Example #1
0
def _files(files):
    if not files:
        files = []
    hash = md5(str(datetime.now())).hexdigest()
    dest = '%s/%s/%s/%s' % (env.user.login[0], env.user.login,
                            hash[:2], hash[2:4])

    files_del = env.request.args('del-attach', [])
    if not isinstance(files_del, (list, tuple)):
        files_del = [files_del]
    for f in files_del:
        if f not in files:
            continue
        remove_attach(f)
        files.remove(f)

    files_in = env.request.args('attach', [])
    files_p = env.request.files('attach')

    if not isinstance(files_in, (list, tuple)):
        files_in = [files_in]
        files_p = [files_p]

    for i, file in enumerate(files_in[:10]):
        if isinstance(file, str):
            file = file.decode('utf-8')
        file = re.sub(r'[^\w\.]+', '-', unidecode(file))
        d = "%s/%s/" % (dest, randint(1000, 9999))
        make_attach(files_p[i], d, file, remove=True)
        files.append(os.path.join(d, file))

    return files
Example #2
0
def _files(files):
    if not files:
        files = []
    hash = md5(str(datetime.now())).hexdigest()
    dest = '%s/%s/%s/%s' % (env.user.login[0], env.user.login, hash[:2],
                            hash[2:4])

    files_del = env.request.args('del-attach', [])
    if not isinstance(files_del, (list, tuple)):
        files_del = [files_del]
    for f in files_del:
        if f not in files:
            continue
        remove_attach(f)
        files.remove(f)

    files_in = env.request.args('attach', [])
    files_p = env.request.files('attach')

    if not isinstance(files_in, (list, tuple)):
        files_in = [files_in]
        files_p = [files_p]

    for i, file in enumerate(files_in[:10]):
        if isinstance(file, str):
            file = file.decode('utf-8')
        file = re.sub(r'[^\w\.]+', '-', unidecode(file))
        d = "%s/%s/" % (dest, randint(1000, 9999))
        make_attach(files_p[i], d, file, remove=True)
        files.append(os.path.join(d, file))

    return files
Example #3
0
 def delete(self):
     res = db.fetchone("DELETE FROM posts.comments "
                      "WHERE post_id=%s AND comment_id=%s "
                      "RETURNING files;",
                      [unb26(self.post.id), self.id])
     if res and res['files']:
         for f in res['files']:
             remove_attach(f)
         redis = RedisPool(settings.storage_socket)
         redis.decr('cmnt_cnt.%s' % unb26(self.post.id))
Example #4
0
    def delete(self):
        files = []
        for ff in db.fetchall("SELECT files FROM posts.comments "
                              "WHERE post_id=%s;", [unb26(self.id)]):
            if ff and ff['files']:
                files.extend(ff['files'])
        for ff in db.fetchone("DELETE FROM posts.posts WHERE id=%s "
                              "RETURNING files;", [unb26(self.id)]):
            if ff:
                files.extend(ff)

        redis = RedisPool(settings.storage_socket)
        redis.delete('cmnt_cnt.%s' % unb26(self.id))

        for f in files:
            remove_attach(f)
Example #5
0
    def delete(self):
        res = db.fetchone(
            "DELETE FROM posts.comments " "WHERE post_id=%s AND comment_id=%s " "RETURNING files;",
            [unb26(self.post.id), self.id],
        )
        if res and res["files"]:
            for f in res["files"]:
                remove_attach(f)
            redis = RedisPool(settings.storage_socket)
            redis.decr("cmnt_cnt.%s" % unb26(self.post.id))

        try:
            es = elasticsearch.Elasticsearch()
            try:
                es.delete(index="point-comments", doc_type="post", id="%s-%s" % (self.post.id, self.id))
            except elasticsearch.exceptions.NotFoundError:
                pass
        except elasticsearch.ConnectionError, e:
            log.error("Elasticsearch: %s" % e)
Example #6
0
    def delete(self):
        files = []
        for ff in db.fetchall("SELECT files FROM posts.comments " "WHERE post_id=%s;", [unb26(self.id)]):
            if ff and ff["files"]:
                files.extend(ff["files"])
        for ff in db.fetchone("DELETE FROM posts.posts WHERE id=%s " "RETURNING files;", [unb26(self.id)]):
            if ff:
                files.extend(ff)

        redis = RedisPool(settings.storage_socket)
        redis.delete("cmnt_cnt.%s" % unb26(self.id))

        for f in files:
            remove_attach(f)

        es = elasticsearch.Elasticsearch()
        try:
            es.delete(index="point-posts", doc_type="post", id=self.id)
        except elasticsearch.exceptions.NotFoundError:
            pass
Example #7
0
    def delete(self):
        res = db.fetchone("DELETE FROM posts.comments "
                         "WHERE post_id=%s AND comment_id=%s "
                         "RETURNING files;",
                         [unb26(self.post.id), self.id])
        if res and res['files']:
            for f in res['files']:
                remove_attach(f)
            redis = RedisPool(settings.storage_socket)
            redis.decr('cmnt_cnt.%s' % unb26(self.post.id))

        try:
            es = elasticsearch.Elasticsearch()
            try:
                es.delete(index='point-comments', doc_type='post',
                          id='%s-%s' % (self.post.id, self.id))
            except elasticsearch.exceptions.NotFoundError:
                pass
        except elasticsearch.ConnectionError, e:
            log.error('Elasticsearch: %s' % e)
Example #8
0
    def delete(self):
        files = []
        for ff in db.fetchall("SELECT files FROM posts.comments "
                              "WHERE post_id=%s;", [unb26(self.id)]):
            if ff and ff['files']:
                files.extend(ff['files'])
        for ff in db.fetchone("DELETE FROM posts.posts WHERE id=%s "
                              "RETURNING files;", [unb26(self.id)]):
            if ff:
                files.extend(ff)

        redis = RedisPool(settings.storage_socket)
        redis.delete('cmnt_cnt.%s' % unb26(self.id))

        for f in files:
            remove_attach(f)

        es = elasticsearch.Elasticsearch()
        try:
            es.delete(index='point-posts', doc_type='post', id=self.id)
        except elasticsearch.exceptions.NotFoundError:
            pass