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


Python models.Inbox类代码示例

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


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

示例1: recompute_unread

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,代码行数:30,代码来源:migrate.py

示例2: monitor_mentions

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,代码行数:57,代码来源:butler.py

示例3: notify_mention

def notify_mention(user, thing):
    try:
        inbox_rel = Inbox._add(user, thing, "mention")
    except CreationError:
        # this mention was already inserted, ignore it
        g.log.error("duplicate mention for (%s, %s)", user, thing)
        return

    with query_cache.CachedQueryMutator() as m:
        m.insert(queries.get_inbox_comment_mentions(user), [inbox_rel])
        queries.set_unread(thing, user, unread=True, mutator=m)
开发者ID:AHAMED750,项目名称:reddit,代码行数:11,代码来源:butler.py

示例4: set_unread

def set_unread(message, to, unread):
    if isinstance(to, Subreddit):
        for i in ModeratorInbox.set_unread(message, unread):
            kw = dict(insert_items=i) if unread else dict(delete_items=i)
            add_queries([get_unread_subreddit_messages(i._thing1)], **kw)
    else:
        for i in Inbox.set_unread(message, unread, to=to):
            kw = dict(insert_items=i) if unread else dict(delete_items=i)
            if i._name == "selfreply":
                add_queries([get_unread_selfreply(i._thing1)], **kw)
            elif isinstance(message, Comment):
                add_queries([get_unread_comments(i._thing1)], **kw)
            else:
                add_queries([get_unread_messages(i._thing1)], **kw)
开发者ID:denrobapps,项目名称:Reddit-VM,代码行数:14,代码来源:queries.py

示例5: set_unread

def set_unread(messages, to, unread):
    # Maintain backwards compatability
    messages = tup(messages)

    if isinstance(to, Subreddit):
        for i in ModeratorInbox.set_unread(messages, unread):
            kw = dict(insert_items = i) if unread else dict(delete_items = i)
            add_queries([get_unread_subreddit_messages(i._thing1)], **kw)
    else:
        # All messages should be of the same type
        for i in Inbox.set_unread(messages, unread, to=to):
            kw = dict(insert_items = i) if unread else dict(delete_items = i)
            if isinstance(messages[0], Comment) and not unread:
                add_queries([get_unread_comments(i._thing1)], **kw)
                add_queries([get_unread_selfreply(i._thing1)], **kw)
            elif i._name == 'selfreply':
                add_queries([get_unread_selfreply(i._thing1)], **kw)
            elif isinstance(messages[0], Comment):
                add_queries([get_unread_comments(i._thing1)], **kw)
            else:
                add_queries([get_unread_messages(i._thing1)], **kw)
开发者ID:rram,项目名称:reddit,代码行数:21,代码来源:queries.py

示例6: set_unread

def set_unread(messages, to, unread, mutator=None):
    # Maintain backwards compatability
    messages = tup(messages)

    if not mutator:
        m = CachedQueryMutator()
    else:
        m = mutator

    if isinstance(to, Subreddit):
        for i in ModeratorInbox.set_unread(messages, unread):
            q = get_unread_subreddit_messages(i._thing1_id)
            if unread:
                m.insert(q, [i])
            else:
                m.delete(q, [i])
    else:
        # All messages should be of the same type
        # (asserted by Inbox.set_unread)
        for i in Inbox.set_unread(messages, unread, to=to):
            query = None
            if isinstance(messages[0], Comment):
                if i._name == "inbox":
                    query = get_unread_comments(i._thing1_id)
                elif i._name == "selfreply":
                    query = get_unread_selfreply(i._thing1_id)
            elif isinstance(messages[0], Message):
                query = get_unread_messages(i._thing1_id)
            assert query is not None

            if unread:
                m.insert(query, [i])
            else:
                m.delete(query, [i])

    if not mutator:
        m.send()
开发者ID:WyriHaximus,项目名称:reddit,代码行数:37,代码来源:queries.py

示例7: rel_query

    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,代码行数:31,代码来源:queries.py

示例8: notify_mention

def notify_mention(user, thing):
    inbox_rel = Inbox._add(user, thing, "mention")
    with query_cache.CachedQueryMutator() as m:
        m.insert(queries.get_inbox_comment_mentions(user), [inbox_rel])
        queries.set_unread(thing, user, unread=True, mutator=m)
开发者ID:Robert77168,项目名称:reddit,代码行数:5,代码来源:butler.py

示例9: get_unread_and_unemailed

def get_unread_and_unemailed(user):
    inbox_items = Inbox.get_unread_and_unemailed(user._id)
    return sorted(inbox_items, key=lambda x: x[1]._date)
开发者ID:zeantsoi,项目名称:reddit,代码行数:3,代码来源:emailer.py


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