Example #1
0
File: comment.py Project: CMGS/ymir
def get_comments_by_fid(site, count, page, num, fid):
    comment_table = get_table(site.id, site.token, site.node)
    return comment_table \
            .select() \
            .where(comment_table.fid == fid) \
            .order_by(comment_table.id.desc()) \
            .paginate(page, num)
Example #2
0
File: comment.py Project: CMGS/ymir
def delete_comments_by_tid(site, tid):
    comment_table = get_table(site.id, site.token, site.node)
    result = comment_table.delete().where(comment_table.tid == tid).execute()
    site.comments = Site.comments - result
    site.save()
    rds.decr(config.COMMENT_COUNT_PREFIX.format(sid = site.id, tid = tid), result)
    return result
Example #3
0
File: comment.py Project: CMGS/ymir
def get_comments_by_ip(site, ip, tid = -1):
    comment_table = get_table(site.id, site.token, site.node)
    if tid == -1:
        comments = comment_table.select().where(comment_table.ip == ip)
    else:
        comments = comment_table.select().where(comment_table.tid == tid, comment_table.ip == ip)
    return comments
Example #4
0
File: comment.py Project: CMGS/ymir
def create(site, tid, fid, uid, ip, content):
    comment_table = get_table(site.id, site.token, site.node)
    site.comments = Site.comments + 1
    site.save()
    comment = comment_table.create(tid=tid, fid=fid, uid=uid, ip=ip, content=content)
    if fid:
        f_comment = get_comment(site, fid)
        f_comment.count = comment_table.count + 1
        f_comment.save()
        rds.delete(config.COMMENT_CACHE_PREFIX.format(sid = site.id, id = fid))
    rds.incr(config.COMMENT_COUNT_PREFIX.format(sid = site.id, tid = tid))
    return comment
Example #5
0
File: comment.py Project: CMGS/ymir
def get_comments(site, count, page, num, tid, expand):
    comment_table = get_table(site.id, site.token, site.node)
    comments = comment_table \
                .select() \
                .where(comment_table.tid == tid, comment_table.fid == 0) \
                .order_by(comment_table.id.desc()) \
                .paginate(page, num)
    for comment in comments:
        yield comment
        if not expand:
            continue
        for reply in get_comments_by_fid(site, comment.count, page, num, fid = comment.id):
            yield reply
Example #6
0
File: comment.py Project: CMGS/ymir
def delete_comment(site, comment):
    comment_table = get_table(site.id, site.token, site.node)
    comment.delete_instance()
    result = comment_table.delete().where(comment_table.fid == comment.id).execute()
    need_delete_keys = [config.COMMENT_CACHE_PREFIX.format(sid = site.id, id = comment.id)]
    if comment.fid:
        f_comment = get_comment(site, comment.fid)
        f_comment.count = comment_table.count - 1
        f_comment.save()
        need_delete_keys.append(config.COMMENT_CACHE_PREFIX.format(sid = site.id, id = comment.fid))
    result += 1
    site.comments = Site.comments - result
    site.save()
    rds.delete(*need_delete_keys)
    rds.decr(config.COMMENT_COUNT_PREFIX.format(sid = site.id, tid = comment.tid), result)
    return result
Example #7
0
File: comment.py Project: CMGS/ymir
def get_comment(site, id):
    comment_table = get_table(site.id, site.token, site.node)
    return comment_table.get(comment_table.id == id)
Example #8
0
File: comment.py Project: CMGS/ymir
def get_comment_cached(site, id):
    comment_table = get_table(site.id, site.token, site.node)
    comment = comment_table.select().where(comment_table.id == id).first()
    return comment
Example #9
0
 def test_get_table(self):
     from utils import comment
     self.patch(comment, 'local_cache', {})
     comment_table = comment.get_table(1, self.token, 0)
     self.assertEqual(comment.local_cache.get(config.COMMENT_TABLE_PREFIX.format(token = self.token)), comment_table)