Ejemplo n.º 1
0
def assign_trial(account, ip, slash16):
    from r2.models import Jury, Subreddit, Trial
    from r2.lib.db import queries

    defendants_voted_upon = []
    defendants_assigned_to = []
    for jury in Jury.by_account(account):
        defendants_assigned_to.append(jury._thing2_id)
        if jury._name != '0':
            defendants_voted_upon.append(jury._thing2_id)

    subscribed_sr_ids = Subreddit.user_subreddits(account,
                                                  ids=True,
                                                  limit=None)

    # Pull defendants, except ones which already have lots of juryvotes
    defs = Trial.all_defendants(quench=True)

    # Filter out defendants outside this user's subscribed SRs
    defs = filter(lambda d: d.sr_id in subscribed_sr_ids, defs)

    # Dictionary of sr_id => SR for all defendants' SRs
    srs = Subreddit._byID(set([d.sr_id for d in defs]))

    # Dictionary of sr_id => eligibility bool
    submit_srs = {}
    for sr_id, sr in srs.iteritems():
        submit_srs[sr_id] = sr.can_submit(account) and not sr._spam

    # Filter out defendants with ineligible SRs
    defs = filter(lambda d: submit_srs.get(d.sr_id), defs)

    likes = queries.get_likes(account, defs)

    if not g.debug:
        # Filter out things that the user has upvoted or downvoted
        defs = filter(lambda d: likes.get((account, d)) is None, defs)

    # Prefer oldest trials
    defs.sort(key=lambda x: x._date)

    for defendant in defs:
        sr = srs[defendant.sr_id]

        if voir_dire(account, ip, slash16, defendants_voted_upon, defendant,
                     sr):
            if defendant._id not in defendants_assigned_to:
                j = Jury._new(account, defendant)

            return defendant

    return None
Ejemplo n.º 2
0
def assign_trial(account, ip, slash16):
    from r2.models import Jury, Subreddit, Trial
    from r2.lib.db import queries

    defendants_voted_upon = []
    defendants_assigned_to = []
    for jury in Jury.by_account(account):
        defendants_assigned_to.append(jury._thing2_id)
        if jury._name != '0':
            defendants_voted_upon.append(jury._thing2_id)

    subscribed_sr_ids = Subreddit.user_subreddits(account, ids=True, limit=None)

    # Pull defendants, except ones which already have lots of juryvotes
    defs = Trial.all_defendants(quench=True)

    # Filter out defendants outside this user's subscribed SRs
    defs = filter (lambda d: d.sr_id in subscribed_sr_ids, defs)

    # Dictionary of sr_id => SR for all defendants' SRs
    srs = Subreddit._byID(set([ d.sr_id for d in defs ]))

    # Dictionary of sr_id => eligibility bool
    submit_srs = {}
    for sr_id, sr in srs.iteritems():
        submit_srs[sr_id] = sr.can_submit(account) and not sr._spam

    # Filter out defendants with ineligible SRs
    defs = filter (lambda d: submit_srs.get(d.sr_id), defs)

    likes = queries.get_likes(account, defs)

    if not g.debug:
        # Filter out things that the user has upvoted or downvoted
        defs = filter (lambda d: likes.get((account, d)) is None, defs)

    # Prefer oldest trials
    defs.sort(key=lambda x: x._date)

    for defendant in defs:
        sr = srs[defendant.sr_id]

        if voir_dire(account, ip, slash16, defendants_voted_upon, defendant, sr):
            if defendant._id not in defendants_assigned_to:
                j = Jury._new(account, defendant)

            return defendant

    return None