Exemple #1
0
def populate_spotlight():
    raise Exception("this function is broken (re: ip_and_slash16) and pending demolition")

    from r2.models import Jury
    from r2.lib.db.thing import NotFound

    if not (c.user_is_loggedin and c.user.jury_betatester()):
        g.log.debug("not eligible")
        return None

    try:
        juries_already_on = Jury.by_account(c.user)
    except NotFound:
        # This can happen if Jury.delete_old() just so happens to be cleaning
        # up this user's old Jury rels while they're visiting the front page.
        # In this unlucky case, just skip the 20% nagging below.
        juries_already_on = []

    # If they're already on a jury, and haven't yet voted, re-show
    # it every five or so times.
    if rand.random() < 0.2:
        unvoted = filter(lambda j: j._name == '0', juries_already_on)
        defs = [u._thing2 for u in unvoted]
        active_trials = trial_info(defs)
        for d in defs:
            if active_trials.get(d._fullname, False):
                return d

    if not g.cache.add("global-jury-key", True, 5):
        g.log.debug("not yet time to add another juror")
        return None

    ip, slash16 = ip_and_slash16(request)

    jcd = jury_cache_dict(c.user, ip, slash16)

    if jcd is None:
        g.cache.delete("global-jury-key")
        return None

    if g.cache.get_multi(jcd.keys()) and not g.debug:
        g.log.debug("recent juror")
        g.cache.delete("global-jury-key")
        return None

    trial = assign_trial(c.user, juries_already_on, ip, slash16)

    if trial is None:
        g.log.debug("nothing available")
        g.cache.delete("global-jury-key")
        return None

    for k, v in jcd.iteritems():
        g.cache.set(k, True, v)

    log_text("juryassignment",
             "%s was just assigned to the jury for %s" % (c.user.name, trial._id36),
             level="info")

    return trial
Exemple #2
0
def populate_spotlight():
    if not (c.user_is_loggedin and c.user.jury_betatester()):
        g.log.debug("not eligible")
        return None

    if not g.cache.add("global-jury-key", True, 5):
        g.log.debug("not yet time to add another juror")
        return None

    ip, slash16 = ip_and_slash16(request)

    jcd = jury_cache_dict(c.user, ip, slash16)

    if jcd is None:
        g.cache.delete("global-jury-key")
        return None

    if g.cache.get_multi(jcd.keys()) and not g.debug:
        g.log.debug("recent juror")
        g.cache.delete("global-jury-key")
        return None

    trial = assign_trial(c.user, ip, slash16)

    if trial is None:
        g.log.debug("nothing available")
        g.cache.delete("global-jury-key")
        return None

    for k, v in jcd.iteritems():
        g.cache.set(k, True, v)

    log_text("juryassignment",
             "%s was just assigned to the jury for %s" %
             (c.user.name, trial._id36),
             level="info")

    return trial
Exemple #3
0
def populate_spotlight():
    if not (c.user_is_loggedin and c.user.jury_betatester()):
        g.log.debug("not eligible")
        return None

    if not g.cache.add("global-jury-key", True, 5):
        g.log.debug("not yet time to add another juror")
        return None

    ip, slash16 = ip_and_slash16(request)

    jcd = jury_cache_dict(c.user, ip, slash16)

    if jcd is None:
        g.cache.delete("global-jury-key")
        return None

    if g.cache.get_multi(jcd.keys()) and not g.debug:
        g.log.debug("recent juror")
        g.cache.delete("global-jury-key")
        return None

    trial = assign_trial(c.user, ip, slash16)

    if trial is None:
        g.log.debug("nothing available")
        g.cache.delete("global-jury-key")
        return None

    for k, v in jcd.iteritems():
        g.cache.set(k, True, v)

    log_text("juryassignment",
             "%s was just assigned to the jury for %s" % (c.user.name, trial._id36),
             level="info")

    return trial