Commits

Angel Velasquez  committed 5533cb1

Adding status parameter to the pm_write and pm_broadcast functions, in order to don't accept them automatically

  • Participants
  • Parent commits faa48d5

Comments (0)

Files changed (1)

File postman/api.py

     from datetime import datetime
     now = datetime.now
 
-from postman.models import Message, STATUS_PENDING, STATUS_ACCEPTED
+from postman.models import Message, STATUS_PENDING, STATUS_ACCEPTED, STATUS_REJECTED
 
-def pm_broadcast(sender, recipients, subject, body='', skip_notification=False):
+def pm_broadcast(sender, recipients, subject, body='', skip_notification=False, status=STATUS_ACCEPTED):
     """
     Broadcast a message to multiple Users.
     For an easier cleanup, all these messages are directly marked as archived and deleted on the sender side.
     """
     message = Message(subject=subject, body=body, sender=sender,
         sender_archived=True, sender_deleted_at=now(),
-        moderation_status=STATUS_ACCEPTED, moderation_date=now())
+        moderation_status=status, moderation_date=now())
     if not isinstance(recipients, (tuple, list)):
         recipients = (recipients,)
     for recipient in recipients:
         if not skip_notification:
             message.notify_users(STATUS_PENDING)
 
-def pm_write(sender, recipient, subject, body='', skip_notification=False, auto_archive=False, auto_delete=False):
+def pm_write(sender, recipient, subject, body='', skip_notification=False, auto_archive=False, auto_delete=False, status=STATUS_ACCEPTED):
     """
     Write a message to a User.
     Contrary to pm_broadcast(), the message is archived and/or deleted on the sender side only if requested.
         ``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())
+        moderation_status=status, moderation_date=now())
     if auto_archive:
         message.sender_archived = True
     if auto_delete: