当前位置: 首页>>代码示例>>Python>>正文


Python Trial.all_defendants方法代码示例

本文整理汇总了Python中r2.models.Trial.all_defendants方法的典型用法代码示例。如果您正苦于以下问题:Python Trial.all_defendants方法的具体用法?Python Trial.all_defendants怎么用?Python Trial.all_defendants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在r2.models.Trial的用法示例。


在下文中一共展示了Trial.all_defendants方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: indict

# 需要导入模块: from r2.models import Trial [as 别名]
# 或者: from r2.models.Trial import all_defendants [as 别名]
def indict(defendant):
    from r2.models import Trial

    tk = trial_key(defendant)

    rv = False
    if defendant._deleted:
        result = "already deleted"
    elif getattr(defendant, "promoted", None) is not None:
        result = "it's promoted"
    elif hasattr(defendant, "verdict") and defendant.verdict is not None:
        result = "it already has a verdict"
    elif g.hardcache.get(tk):
        result = "it's already on trial"
    else:
        # The spams/koshers dict is just a infrequently-updated cache; the
        # official source of the data is the Jury relation.
        g.hardcache.set(tk, dict(spams=0, koshers=0), TRIAL_TIME)
        Trial.all_defendants(_update=True)
        result = "it's now indicted: %s" % tk
        rv = True

    log_text("indict_result", "%s: %s" % (defendant._id36, result), level="info")

    return rv
开发者ID:bqevin,项目名称:reddit,代码行数:27,代码来源:trial_utils.py

示例2: end_trial

# 需要导入模块: from r2.models import Trial [as 别名]
# 或者: from r2.models.Trial import all_defendants [as 别名]
def end_trial(thing, verdict=None):
    from r2.models import Trial
    if trial_info(thing):
        g.hardcache.delete(trial_key(thing))
        Trial.all_defendants(_update=True)

    if verdict is not None:
        thing.verdict = verdict
        thing._commit()
开发者ID:git001,项目名称:reddit,代码行数:11,代码来源:trial_utils.py

示例3: look_for_verdicts

# 需要导入模块: from r2.models import Trial [as 别名]
# 或者: from r2.models.Trial import all_defendants [as 别名]
def look_for_verdicts():
    from r2.models import Trial

    print "checking all trials for verdicts..."
    for defendant in Trial.all_defendants():
        print "Looking at reddit.com/comments/%s/x" % defendant._id36
        v = Trial(defendant).check_verdict()
        print "Verdict: %r" % v
开发者ID:XieConnect,项目名称:reddit,代码行数:10,代码来源:trial_utils.py

示例4: look_for_verdicts

# 需要导入模块: from r2.models import Trial [as 别名]
# 或者: from r2.models.Trial import all_defendants [as 别名]
def look_for_verdicts():
    from r2.models import Trial, Jury

    print "checking all trials for verdicts..."
    for defendant in Trial.all_defendants():
        print "Looking at populr.de/comments/%s/x" % defendant._id36
        v = Trial(defendant).check_verdict()
        print "Verdict: %r" % v

    Jury.delete_old(verbose=True, limit=1000)
开发者ID:git001,项目名称:reddit,代码行数:12,代码来源:trial_utils.py

示例5: assign_trial

# 需要导入模块: from r2.models import Trial [as 别名]
# 或者: from r2.models.Trial import all_defendants [as 别名]
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
开发者ID:XieConnect,项目名称:reddit,代码行数:51,代码来源:trial_utils.py


注:本文中的r2.models.Trial.all_defendants方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。