示例#1
0
def create_message(sender, recipient, subject, body='', skip_notification=False, auto_archive=False, auto_delete=False, auto_moderators=None, sent_at=None):
    if not user_is_valid(sender):
        raise InvalidSenderException()
    if not user_is_valid(recipient):
        raise InvalidRecipientException()
    if subject is None or subject == '':
        raise NoMessageSubjectException('this message has an empty subject line. Messages without subject cannot be sent')
    if body is None or body == '':
        raise NoMessageBodyException('this message has an empty message body. Empty message cannot be sent')
    message = Message(subject=subject, body=body, sender=sender, recipient=recipient)
    if not sent_at is None:
        message.sent_at = sent_at
    initial_status = message.moderation_status
    if auto_moderators:
        message.auto_moderate(auto_moderators)
    else:
        message.moderation_status = STATUS_ACCEPTED
    message.clean_moderation(initial_status)
    if auto_archive:
        message.sender_archived = True
    if auto_delete:
        message.sender_deleted_at = now()
    message.save()
    if not skip_notification:
        message.notify_users(initial_status, _get_site())
    return message
示例#2
0
def pm_write(sender, recipient, subject, body='', skip_notification=False,
        auto_archive=False, auto_delete=False, auto_moderators=None):
    """
    Write a message to a User.
    Contrary to pm_broadcast(), the message is archived and/or deleted on
    the sender side only if requested.
    The message may come from an untrusted application, a gateway for example,
    so it may be useful to involve some auto moderators in the processing.

    Optional arguments:
        ``skip_notification``: if the normal notification event is not wished
        ``auto_archive``: to mark the message as archived on the sender side
        ``auto_delete``: to mark the message as deleted on the sender side
        ``auto_moderators``: a list of auto-moderation functions
    """
    message = Message(subject=subject, body=body, sender=sender, recipient=recipient)
    initial_status = message.moderation_status
    if auto_moderators:
        message.auto_moderate(auto_moderators)
    else:
        message.moderation_status = STATUS_ACCEPTED
    message.clean_moderation(initial_status)
    if auto_archive:
        message.sender_archived = True
    if auto_delete:
        message.sender_deleted_at = now()
    message.save()
    if not skip_notification:
        message.notify_users(initial_status, _get_site())
示例#3
0
文件: api.py 项目: hannanxp/uface
def pm_write(sender,
             recipient,
             subject,
             body='',
             skip_notification=False,
             auto_archive=False,
             auto_delete=False):
    """
    Write a message to a User.
    Contrary to pm_broadcast(), the message is archived and/or deleted on the sender side only if requested.

    Optional arguments:
        ``skip_notification``: if the normal notification event is not wished
        ``auto_archive``: to mark the message as archived on the sender side
        ``auto_delete``: to mark the message as deleted on the sender side
    """
    message = Message(subject=subject,
                      body=body,
                      sender=sender,
                      recipient=recipient,
                      moderation_status=STATUS_ACCEPTED,
                      moderation_date=now())
    if auto_archive:
        message.sender_archived = True
    if auto_delete:
        message.sender_deleted_at = now()
    message.save()
    if not skip_notification:
        message.notify_users(STATUS_PENDING)