def _cache_prefix(cls, rel, t_class, amount = None): # encode the amount keyword on the prefix prefix = thing_prefix(rel.__name__) + '_' + \ thing_prefix(t_class.__name__) if amount is not None: prefix += ("_amount_%d" % amount) return prefix
def _cache_prefix(cls, rel, t_class, amount=None): # encode the amount keyword on the prefix prefix = thing_prefix(rel.__name__) + '_' + \ thing_prefix(t_class.__name__) if amount is not None: prefix += ("_amount_%d" % amount) return prefix
def unreport_account(user, correct=True, types=(Link, Comment, Message), auto=False, banned_by=''): for typ in types: thing_dict = tdb.types_id[typ._type_id] dtable, table = thing_dict.data_table by_user_query = sa.and_( table.c.thing_id == dtable.c.thing_id, dtable.c.key == 'author_id', sa.func.substring(dtable.c.value, 1, 1000) == str(user._id)) s = sa.select(["count(*)"], sa.and_(by_user_query, table.c.spam == (not correct))) # update the author's spamminess count = s.execute().fetchone()[0] * (1 if correct else -1) if user.spammer + count >= 0: user._incr('spammer', count) #for i in xrange(count if count > 0 else -count): # karma_whack(user, typ, -count) things = list( typ._query(typ.c.author_id == user._id, typ.c._spam == (not correct), data=False, limit=300)) admintools.spam(things, amount=1 if correct else -1, mark_as_spam=False, auto=auto, banned_by=banned_by) u = """UPDATE %(table)s SET spam='%(spam)s' FROM %(dtable)s WHERE %(table)s.thing_id = %(dtable)s.thing_id AND %(dtable)s.key = 'author_id' AND substring(%(dtable)s.value, 1, 1000) = '%(author_id)s'""" u = u % dict(spam='t' if correct else 'f', table=table.name, dtable=dtable.name, author_id=user._id) table.engine.execute(u) # grab a list of all the things we just blew away and update the cache s = sa.select([table.c.thing_id], by_user_query) tids = [t[0] for t in s.execute().fetchall()] keys = [thing_prefix(typ.__name__, i) for i in tids] cache.delete_multi(keys) # mark the reports as finalized: reports = Report._by_author(user, amount=0) for r in reports: Report.accept(r, correct)
def unreport_account(user, correct = True, types = (Link, Comment, Message), auto = False, banned_by = ''): for typ in types: thing_dict = tdb.types_id[typ._type_id] dtable, table = thing_dict.data_table by_user_query = sa.and_(table.c.thing_id == dtable.c.thing_id, dtable.c.key == 'author_id', sa.func.substring(dtable.c.value, 1, 1000) == user._id) s = sa.select(["count(*)"], sa.and_(by_user_query, table.c.spam == (not correct))) # update the author's spamminess count = s.execute().fetchone()[0] * (1 if correct else -1) if user.spammer + count >= 0: user._incr('spammer', count) #for i in xrange(count if count > 0 else -count): # karma_whack(user, typ, -count) things= list(typ._query(typ.c.author_id == user._id, typ.c._spam == (not correct), data = False, limit=300)) admintools.spam(things, amount = 1 if correct else -1, mark_as_spam = False, auto = auto, banned_by = banned_by) u = """UPDATE %(table)s SET spam='%(spam)s' FROM %(dtable)s WHERE %(table)s.thing_id = %(dtable)s.thing_id AND %(dtable)s.key = 'author_id' AND substring(%(dtable)s.value, 1, 1000) = %(author_id)s""" u = u % dict(spam = 't' if correct else 'f', table = table.name, dtable = dtable.name, author_id = user._id) table.engine.execute(u) # grab a list of all the things we just blew away and update the cache s = sa.select([table.c.thing_id], by_user_query) tids = [t[0] for t in s.execute().fetchall()] keys = [thing_prefix(typ.__name__, i) for i in tids] cache.delete_multi(keys) # mark the reports as finalized: reports = Report._by_author(user, amount = 0) for r in reports: Report.accept(r, correct)