コード例 #1
0
ファイル: report.py プロジェクト: whatisaphone/lesswrong
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)
コード例 #2
0
ファイル: report.py プロジェクト: cmak/reddit
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)
コード例 #3
0
ファイル: report.py プロジェクト: cmak/reddit
def unreport(things, correct=False, auto = False, banned_by = ''):
    things = tup(things)

    # load authors (to set the spammer flag)
    try:
        aids = set(t.author_id for t in things)
    except AttributeError:
        aids = None

    authors = Account._byID(tuple(aids), data=True) if aids else {}


    # load all reports (to set their amount to be +/-1)
    reports = Report.reported(things=things, amount = 0)

    # mark the reports as finalized:
    for r in reports.values(): Report.accept(r, correct)

    amount = 1 if correct else -1

    spammer = {}
    for t in things:
        # clean up inconsistencies
        if getattr(t, Report._field) != 0:
            setattr(t, Report._field, 0)
            t._commit()
            # flag search indexer that something has changed
            tc.changed(t)
            
        # update the spam flag
        if t._spam != correct and hasattr(t, 'author_id'):
            # tally the spamminess of the author
            spammer[t.author_id] = spammer.get(t.author_id,0) + amount
            #author = authors.get(t.author_id)
            #if author:
            #    karma_whack(author, t.__class__, -amount)

    #will be empty if the items didn't have authors
    for s, v in spammer.iteritems():
        if authors[s].spammer + v >= 0:
            authors[s]._incr('spammer', v)
            
    # mark all as spam
    admintools.spam(things, amount = amount, auto = auto, banned_by = banned_by)
コード例 #4
0
ファイル: report.py プロジェクト: whatisaphone/lesswrong
def unreport(things, correct=False, auto=False, banned_by=''):
    things = tup(things)

    # load authors (to set the spammer flag)
    try:
        aids = set(t.author_id for t in things)
    except AttributeError:
        aids = None

    authors = Account._byID(tuple(aids), data=True) if aids else {}

    # load all reports (to set their amount to be +/-1)
    reports = Report.reported(things=things, amount=0)

    # mark the reports as finalized:
    for r in reports.values():
        Report.accept(r, correct)

    amount = 1 if correct else -1

    spammer = {}
    for t in things:
        # clean up inconsistencies
        if getattr(t, Report._field) != 0:
            setattr(t, Report._field, 0)
            t._commit()
            # flag search indexer that something has changed
            tc.changed(t)

        # update the spam flag
        if t._spam != correct and hasattr(t, 'author_id'):
            # tally the spamminess of the author
            spammer[t.author_id] = spammer.get(t.author_id, 0) + amount
            #author = authors.get(t.author_id)
            #if author:
            #    karma_whack(author, t.__class__, -amount)

    #will be empty if the items didn't have authors
    for s, v in spammer.iteritems():
        if authors[s].spammer + v >= 0:
            authors[s]._incr('spammer', v)

    # mark all as spam
    admintools.spam(things, amount=amount, auto=auto, banned_by=banned_by)