Beispiel #1
0
Datei: site.py Projekt: CMGS/ymir
def delete_block(site, id):
    block = Block.get(Block.id == id, Block.sid == site.id)
    rds.delete(config.BLOCK_PREFIX.format(sid=site.id, ip=block.ip))
    site.blocks = Site.blocks - 1
    site.save()
    del local_cache[site.token]
    return block.delete_instance()
Beispiel #2
0
    def test_check_block(self):
        site = get_site_by_token(self.token)
        ip = '192.168.1.11'
        block(site, ip)

        self.assertTrue(check_block(site.id, ip))
        rds.delete(config.BLOCK_PREFIX.format(sid = site.id, ip = ip))
        self.assertTrue(check_block(site.id, ip))
        self.assertFalse(check_block(site.id, '192.168.1.12'))
Beispiel #3
0
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
Beispiel #4
0
Datei: test.py Projekt: CMGS/ymir
def cleanup():
    from models.site import Site, Block
    Site.drop_table(fail_silently=True)
    Block.drop_table(fail_silently=True)
    from utils.cache import local_cache
    for k, v in local_cache.iteritems():
        if not v:
            continue
        v.drop_table(fail_silently=True)
    from utils.cache import rds
    keys = rds.keys('c:*')
    if keys:
        rds.delete(*keys)
Beispiel #5
0
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