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


Python Inbox.rel方法代码示例

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


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

示例1: recompute_unread

# 需要导入模块: from r2.models import Inbox [as 别名]
# 或者: from r2.models.Inbox import rel [as 别名]
def recompute_unread(min_date = None):
    from r2.models import Inbox, Account, Comment, Message
    from r2.lib.db import queries

    def load_accounts(inbox_rel):
        accounts = set()
        q = inbox_rel._query(eager_load = False, data = False,
                             sort = desc("_date"))
        if min_date:
            q._filter(inbox_rel.c._date > min_date)

        for i in fetch_things2(q):
            accounts.add(i._thing1_id)

        return accounts

    accounts_m = load_accounts(Inbox.rel(Account, Message))
    for i, a in enumerate(accounts_m):
        a = Account._byID(a)
        print "%s / %s : %s" % (i, len(accounts_m), a)
        queries.get_unread_messages(a).update()
        queries.get_unread_comments(a).update()
        queries.get_unread_selfreply(a).update()

    accounts = load_accounts(Inbox.rel(Account, Comment)) - accounts_m
    for i, a in enumerate(accounts):
        a = Account._byID(a)
        print "%s / %s : %s" % (i, len(accounts), a)
        queries.get_unread_comments(a).update()
        queries.get_unread_selfreply(a).update()
开发者ID:MatsT,项目名称:reddit,代码行数:32,代码来源:migrate.py

示例2: monitor_mentions

# 需要导入模块: from r2.models import Inbox [as 别名]
# 或者: from r2.models.Inbox import rel [as 别名]
def monitor_mentions(comment):
    if not isinstance(comment, Comment):
        return

    if comment._spam or comment._deleted:
        return

    sender = comment.author_slow
    if getattr(sender, "butler_ignore", False):
        # this is an account that generates false notifications, e.g.
        # LinkFixer
        return

    subreddit = comment.subreddit_slow
    usernames = list(extract_user_mentions(comment.body, num=g.butler_max_mentions + 1))
    inbox_class = Inbox.rel(Account, Comment)

    # If more than our allowed number of mentions were passed, don't highlight
    # any of them.
    if len(usernames) > g.butler_max_mentions:
        return

    # Subreddit.can_view stupidly requires this.
    c.user_is_loggedin = True

    for username in usernames:
        try:
            account = Account._by_name(username)
        except NotFound:
            continue

        # most people are aware of when they mention themselves.
        if account == sender:
            continue

        # bail out if that user has the feature turned off
        if not account.pref_monitor_mentions:
            continue

        # don't notify users of things they can't see
        if not subreddit.can_view(account):
            continue

        # don't notify users when a person they've blocked mentions them
        if account.is_enemy(sender):
            continue

        # ensure this comment isn't already in the user's inbox already
        rels = inbox_class._fast_query(
            account,
            comment,
            ("inbox", "selfreply", "mention"),
        )
        if filter(None, rels.values()):
            continue

        notify_mention(account, comment)
开发者ID:Robert77168,项目名称:reddit,代码行数:59,代码来源:butler.py

示例3: rel_query

# 需要导入模块: from r2.models import Inbox [as 别名]
# 或者: from r2.models.Inbox import rel [as 别名]
    return rel_query(SaveHide, user, 'hide')

@cached_userrel_query
def get_saved(user):
    return rel_query(SaveHide, user, 'save')

@migrating_cached_srrel_query
def get_subreddit_messages(sr):
    return rel_query(ModeratorInbox, sr, 'inbox')

@migrating_cached_srrel_query
def get_unread_subreddit_messages(sr):
    return rel_query(ModeratorInbox, sr, 'inbox',
                          filters = [ModeratorInbox.c.new == True])

inbox_message_rel = Inbox.rel(Account, Message)
@migrating_cached_userrel_query
def get_inbox_messages(user):
    return rel_query(inbox_message_rel, user, 'inbox')

@migrating_cached_userrel_query
def get_unread_messages(user):
    return rel_query(inbox_message_rel, user, 'inbox',
                          filters = [inbox_message_rel.c.new == True])

inbox_comment_rel = Inbox.rel(Account, Comment)
@migrating_cached_userrel_query
def get_inbox_comments(user):
    return rel_query(inbox_comment_rel, user, 'inbox')

@migrating_cached_userrel_query
开发者ID:rram,项目名称:reddit,代码行数:33,代码来源:queries.py


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