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


Python models.Message类代码示例

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


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

示例1: perform_actions

    def perform_actions(self, item, data):
        """Execute all the rule's actions against the item."""
        for key, target in self.targets.iteritems():
            target_item = self.get_target_item(item, data, key)
            target.perform_actions(target_item, data)

        if self.comment:
            comment = self.build_message(self.comment, item, data, disclaimer=True)

            # TODO: shouldn't have to do all this manually
            if isinstance(item, Comment):
                link = data["link"]
                parent_comment = item
            else:
                link = item
                parent_comment = None
            new_comment, inbox_rel = Comment._new(
                ACCOUNT, link, parent_comment, comment, None)
            new_comment.distinguished = "yes"
            new_comment._commit()
            queries.queue_vote(ACCOUNT, new_comment, True, None)
            queries.new_comment(new_comment, inbox_rel)

            g.stats.simple_event("automoderator.comment")

        if self.modmail:
            message = self.build_message(self.modmail, item, data, permalink=True)
            subject = replace_placeholders(
                self.modmail_subject, data, self.matches)
            subject = subject[:100]

            new_message, inbox_rel = Message._new(ACCOUNT, data["subreddit"],
                subject, message, None)
            new_message.distinguished = "yes"
            new_message._commit()
            queries.new_message(new_message, inbox_rel)

            g.stats.simple_event("automoderator.modmail")

        if self.message and not data["author"]._deleted:
            message = self.build_message(self.message, item, data,
                disclaimer=True, permalink=True)
            subject = replace_placeholders(
                self.message_subject, data, self.matches)
            subject = subject[:100]

            new_message, inbox_rel = Message._new(ACCOUNT, data["author"],
                subject, message, None)
            queries.new_message(new_message, inbox_rel)

            g.stats.simple_event("automoderator.message")

        PerformedRulesByThing.mark_performed(item, self)
开发者ID:j4gold,项目名称:reddit,代码行数:53,代码来源:automoderator.py

示例2: notify_user_added

def notify_user_added(rel_type, author, user, target):
    msgs = user_added_messages.get(rel_type)
    if not msgs:
        return

    srname = target.path.rstrip("/")
    d = {
        "url": srname,
        "title": "%s: %s" % (srname, target.title),
        "author": "/u/" + author.name,
        "user": "/u/" + user.name,
    }

    if "pm" in msgs and author != user:
        subject = msgs["pm"]["subject"] % d
        msg = msgs["pm"]["msg"] % d

        if rel_type in ("moderator_invite", "contributor"):
            # send the message from the subreddit
            item, inbox_rel = Message._new(
                author, user, subject, msg, request.ip, sr=target, from_sr=True,
                can_send_email=False, is_auto_modmail=True)
        else:
            item, inbox_rel = Message._new(
                author, user, subject, msg, request.ip, can_send_email=False)

        queries.new_message(item, inbox_rel, update_modmail=False)

    if "modmail" in msgs:
        subject = msgs["modmail"]["subject"] % d
        msg = msgs["modmail"]["msg"] % d

        if rel_type == "moderator_invite":
            # Don't send the separate moderator invite message from the
            # system user to new modmail, since the one sent to the invitee
            # will already show up in there.
            # TODO: when new modmail is fully deployed, the "modmail" dict
            # should be completely removed from the moderator_invite section
            # of user_added_messages, and this check removed.
            if feature.is_enabled('new_modmail', subreddit=target.name):
                return

            modmail_author = Account.system_user()
        else:
            modmail_author = author

        item, inbox_rel = Message._new(modmail_author, target, subject, msg,
                                       request.ip, sr=target,
                                       is_auto_modmail=True)
        queries.new_message(item, inbox_rel)
开发者ID:zeantsoi,项目名称:reddit,代码行数:50,代码来源:system_messages.py

示例3: _conversation

def _conversation(trees, parent):
    from r2.models import Message
    if parent._id in trees:
        convo = trees[parent._id]
        if convo:
            m = Message._byID(convo[0], data=True)
        if not convo or m.first_message == m.parent_id:
            return [(parent._id, convo)]

    # if we get to this point, either we didn't find the conversation,
    # or the first child of the result was not the actual first child.
    # To the database!
    m = Message._query(Message.c.first_message == parent._id, data=True)
    return compute_message_trees([parent] + list(m))
开发者ID:rtnielson,项目名称:reddit,代码行数:14,代码来源:comment_tree.py

示例4: process_message

 def process_message(msg):
     msg_dict = json.loads(msg.body)
     if msg_dict["event"] == "new_message":
         message_id36 = msg_dict["message_id36"]
         message = Message._byID36(message_id36, data=True)
         send_modmail_email(message)
     elif msg_dict["event"] == "blocked_muted":
         subreddit_id36 = msg_dict["subreddit_id36"]
         sr = Subreddit._byID36(subreddit_id36, data=True)
         parent_id36 = msg_dict["parent_id36"]
         parent = Message._byID36(parent_id36, data=True)
         sender_email = msg_dict["sender_email"]
         incoming_email_id = msg_dict["incoming_email_id"]
         send_blocked_muted_email(sr, parent, sender_email, incoming_email_id)
开发者ID:AHAMED750,项目名称:reddit,代码行数:14,代码来源:message_to_email.py

示例5: get_email_ids

def get_email_ids(message):
    parent_email_id = None
    other_email_ids = []
    if message.parent_id:
        parent = Message._byID(message.parent_id, data=True)
        if parent.email_id:
            other_email_ids.append(parent.email_id)
            parent_email_id = parent.email_id

    if message.first_message:
        first_message = Message._byID(message.first_message, data=True)
        if first_message.email_id:
            other_email_ids.append(first_message.email_id)

    return parent_email_id, other_email_ids
开发者ID:AHAMED750,项目名称:reddit,代码行数:15,代码来源:message_to_email.py

示例6: send_ban_message

def send_ban_message(subreddit, mod, user, note=None, days=None, new=True):
    sr_name = "/r/" + subreddit.name
    if days:
        subject = "you've been temporarily banned from %(subreddit)s"
        message = ("you have been temporarily banned from posting to "
            "%(subreddit)s. this ban will last for %(duration)s days.")
    else:
        subject = "you've been banned from %(subreddit)s"
        message = "you have been banned from posting to %(subreddit)s."

    if not new:
        subject = "Your ban from %(subreddit)s has changed"

    subject %= {"subreddit": sr_name}
    message %= {"subreddit": sr_name, "duration": days}

    if note:
        message += "\n\n" + 'note from the moderators:'
        message += "\n\n" + blockquote_text(note)

    message += "\n\n" + ("you can contact the moderators regarding your ban "
        "by replying to this message. **warning**: using other accounts to "
        "circumvent a subreddit ban is considered a violation of reddit's "
        "[site rules](/rules) and can result in being banned from reddit "
        "entirely.")

    item, inbox_rel = Message._new(
        mod, user, subject, message, request.ip, sr=subreddit, from_sr=True,
        can_send_email=False)
    queries.new_message(item, inbox_rel, update_modmail=False)
开发者ID:Cophy08,项目名称:reddit,代码行数:30,代码来源:system_messages.py

示例7: __init__

    def __init__(self, thing, delete = False, report = True):
        was_comment = getattr(thing, 'was_comment', False)
        permalink = thing.permalink
        # don't allow replying to self unless it's modmail
        valid_recipient = (thing.author_id != c.user._id or
                           thing.sr_id)

        can_reply = (c.user_is_loggedin and
                     getattr(thing, "repliable", True) and
                     valid_recipient)
        can_block = True
        can_mute = False
        is_admin_message = False
        del_on_recipient = (isinstance(thing, Message) and
                            thing.del_on_recipient)

        if not was_comment:
            first_message = thing
            if getattr(thing, 'first_message', False):
                first_message = Message._byID(thing.first_message, data=True)

            if thing.sr_id:
                sr = thing.subreddit_slow
                is_admin_message = '/r/%s' % sr.name == g.admin_message_acct

                if (sr.is_muted(first_message.author_slow) or
                        (first_message.to_id and
                            sr.is_muted(first_message.recipient_slow))):
                    can_reply = False

                can_mute = sr.can_mute(c.user, thing.author_slow)

        if not was_comment and thing.display_author:
            can_block = False

        if was_comment:
            link = thing.link_slow
            if link.archived or link.locked:
                can_reply = False

        # Allow comment-reply messages to have links to the full thread.
        if was_comment:
            self.full_comment_path = thing.link_permalink
            self.full_comment_count = thing.full_comment_count

        PrintableButtons.__init__(self, "messagebuttons", thing,
                                  profilepage = c.profilepage,
                                  permalink = permalink,
                                  was_comment = was_comment,
                                  unread = thing.new,
                                  user_is_recipient = thing.user_is_recipient,
                                  can_reply = can_reply,
                                  parent_id = getattr(thing, "parent_id", None),
                                  show_report = True,
                                  show_delete = False,
                                  can_block = can_block,
                                  can_mute = can_mute,
                                  is_admin_message = is_admin_message,
                                  del_on_recipient=del_on_recipient,
                                 )
开发者ID:Arinzeokeke,项目名称:reddit,代码行数:60,代码来源:things.py

示例8: send_system_message

def send_system_message(user, subject, body, system_user=None,
                        distinguished='admin', repliable=False,
                        add_to_sent=True, author=None):
    from r2.lib.db import queries

    if system_user is None:
        system_user = Account.system_user()
    if not system_user:
        g.log.warning("Can't send system message "
                      "- invalid system_user or g.system_user setting")
        return
    if not author:
        author = system_user

    item, inbox_rel = Message._new(author, user, subject, body,
                                   ip='0.0.0.0')
    item.distinguished = distinguished
    item.repliable = repliable
    item.display_author = system_user._id
    item._commit()

    try:
        queries.new_message(item, inbox_rel, add_to_sent=add_to_sent)
    except MemcachedError:
        raise MessageError('reddit_inbox')
开发者ID:CrypticCraig,项目名称:reddit,代码行数:25,代码来源:admintools.py

示例9: compute_message_trees

def compute_message_trees(messages):
    from r2.models import Message
    roots = set()
    threads = {}
    mdict = {}
    messages = sorted(messages, key = lambda m: m._date, reverse = True)

    for m in messages:
        if not m._loaded:
            m._load()
        mdict[m._id] = m
        if m.first_message:
            roots.add(m.first_message)
            threads.setdefault(m.first_message, set()).add(m._id)
        else:
            roots.add(m._id)

    # load any top-level messages which are not in the original list
    missing = [m for m in roots if m not in mdict]
    if missing:
        mdict.update(Message._byID(tup(missing),
                                   return_dict = True, data = True))

    # sort threads in chrono order
    for k in threads:
        threads[k] = list(sorted(threads[k]))

    tree = [(root, threads.get(root, [])) for root in roots]
    tree.sort(key = tree_sort_fn, reverse = True)

    return tree
开发者ID:Omosofe,项目名称:reddit,代码行数:31,代码来源:comment_tree.py

示例10: POST_traffic_viewer

    def POST_traffic_viewer(self, form, jquery, user, thing):
        """
        Adds a user to the list of users allowed to view a promoted
        link's traffic page.
        """
        if not form.has_errors("name",
                               errors.USER_DOESNT_EXIST, errors.NO_USER):
            form.set_inputs(name="")
            form.set_html(".status:first", _("added"))
            if promote.add_traffic_viewer(thing, user):
                user_row = TrafficViewerList(thing).user_row('traffic_viewer', user)
                jquery(".traffic_viewer-table").show(
                    ).find("table").insert_table_rows(user_row)

                # send the user a message
                msg = user_added_messages['traffic']['pm']['msg']
                subj = user_added_messages['traffic']['pm']['subject']
                if msg and subj:
                    d = dict(url=thing.make_permalink_slow(),
                             traffic_url=promote.promo_traffic_url(thing),
                             title=thing.title)
                    msg = msg % d
                    item, inbox_rel = Message._new(c.user, user,
                                                   subj, msg, request.ip)
                    queries.new_message(item, inbox_rel)
开发者ID:Chef1991,项目名称:reddit,代码行数:25,代码来源:promotecontroller.py

示例11: _add_message_nolock

def _add_message_nolock(key, message):
    from r2.models import Account, Message
    trees = g.permacache.get(key)
    if not trees:
        # in case an empty list got written at some point, delete it to
        # force a recompute
        if trees is not None:
            g.permacache.delete(key)
        # no point computing it now.  We'll do it when they go to
        # their message page.
        return

    # if it is a new root message, easy enough
    if message.first_message is None:
        trees.insert(0, (message._id, []))
    else:
        tree_dict = dict(trees)

        # if the tree already has the first message, update the list
        if message.first_message in tree_dict:
            if message._id not in tree_dict[message.first_message]:
                tree_dict[message.first_message].append(message._id)
                tree_dict[message.first_message].sort()
        # we have to regenerate the conversation :/
        else:
            m = Message._query(Message.c.first_message == message.first_message,
                               data = True)
            new_tree = compute_message_trees(m)
            if new_tree:
                trees.append(new_tree[0])
        trees.sort(key = tree_sort_fn, reverse = True)

    # done!
    g.permacache.set(key, trees)
开发者ID:VincentVazzo,项目名称:reddit,代码行数:34,代码来源:comment_tree.py

示例12: get_reply_to_address

def get_reply_to_address(message):
    """Construct a reply-to address that encodes the message id.

    The address is of the form:
        zendeskreply+{message_id36}-{email_mac}

    where the mac is generated from {message_id36} using the
    `modmail_email_secret`

    The reply address should be configured with the inbound email service so
    that replies to our messages are routed back to the app somehow. For mailgun
    this involves adding a Routes filter for messages sent to
    "zendeskreply\+*@". to be forwarded to POST /api/zendeskreply.

    """

    # all email replies are treated as replies to the first message in the
    # conversation. this is to get around some peculiarities of zendesk
    if message.first_message:
        first_message = Message._byID(message.first_message, data=True)
    else:
        first_message = message
    email_id = first_message._id36

    email_mac = hmac.new(
        g.secrets['modmail_email_secret'], email_id, hashlib.sha256).hexdigest()
    reply_id = "zendeskreply+{email_id}-{email_mac}".format(
        email_id=email_id, email_mac=email_mac)

    sr = Subreddit._byID(message.sr_id, data=True)
    return "r/{subreddit} mail <{reply_id}@{domain}>".format(
        subreddit=sr.name, reply_id=reply_id, domain=g.modmail_email_domain)
开发者ID:AHAMED750,项目名称:reddit,代码行数:32,代码来源:message_to_email.py

示例13: send_ban_message

def send_ban_message(subreddit, mod, user, note=None, days=None, new=True):
    sr_name = "/r/" + subreddit.name
    if days:
        subject = "you've been temporarily banned from %(subreddit)s"
        message = ("you have been temporarily banned from posting to "
            "%(subreddit)s. this ban will last for %(duration)s days.")
    else:
        subject = "you've been banned from %(subreddit)s"
        message = "you have been banned from posting to %(subreddit)s."

    if not new:
        subject = "Your ban from %(subreddit)s has changed"

    subject %= {"subreddit": sr_name}
    message %= {"subreddit": sr_name, "duration": days}

    if note:
        message += "\n\n" + 'note from the moderators:'
        message += "\n\n" + blockquote_text(note)

    message += "\n\n" + ("you can contact the moderators regarding your ban "
        "by replying to this message. **warning**: using other accounts to "
        "circumvent a subreddit ban is considered a violation of reddit's "
        "[site rules](/help/contentpolicy#section_prohibited_behavior) "
        "and can result in the "
        "[suspension](https://reddit.zendesk.com/hc/articles/205687686) "
        "of your reddit account.")

    item, inbox_rel = Message._new(mod, user, subject, message, request.ip,
        sr=subreddit, from_sr=True)
    queries.new_message(item, inbox_rel, update_modmail=False)
开发者ID:Umdlye,项目名称:reddit,代码行数:31,代码来源:system_messages.py

示例14: _load_messages

def _load_messages(mlist):
    from r2.models import Message
    m = {}
    ids = [x for x in mlist if not isinstance(x, Message)]
    if ids:
        m = Message._by_fullname(ids, return_dict = True, data = True)
    messages = [m.get(x, x) for x in mlist]
    return messages
开发者ID:Omosofe,项目名称:reddit,代码行数:8,代码来源:comment_tree.py

示例15: notify_user_added

def notify_user_added(rel_type, author, user, target, message=None):
    msgs = user_added_messages.get(rel_type)
    if not msgs:
        return

    srname = target.path.rstrip("/")
    d = {
        "url": srname,
        "title": "%s: %s" % (srname, target.title),
        "author": "/u/" + author.name,
        "user": "/u/" + user.name,
    }

    if "pm" in msgs and author != user:
        subject = msgs["pm"]["subject"] % d
        msg = msgs["pm"]["msg"] % d

        if rel_type == "banned" and not user.has_interacted_with(target):
            return

        if rel_type == "banned" and message:
            msg += "\n\n" + N_("note from the moderators:\n\n\"%(message)s\"")
            msg %= {'message': message}

        if rel_type in ("banned", "moderator_invite"):
            # send the message from the subreddit
            item, inbox_rel = Message._new(author, user, subject, msg, request.ip,
                                           sr=target, from_sr=True)
        else:
            item, inbox_rel = Message._new(author, user, subject, msg, request.ip)

        queries.new_message(item, inbox_rel, update_modmail=False)

    if "modmail" in msgs:
        subject = msgs["modmail"]["subject"] % d
        msg = msgs["modmail"]["msg"] % d

        if rel_type == "moderator_invite":
            modmail_author = Account.system_user()
        else:
            modmail_author = author

        item, inbox_rel = Message._new(modmail_author, target, subject, msg,
                                       request.ip, sr=target)
        queries.new_message(item, inbox_rel, update_modmail=False)
开发者ID:zz198808,项目名称:reddit,代码行数:45,代码来源:system_messages.py


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