django-postman / docs / moderation.rst

Moderation

When created, a message is in a pending state. It is not delivered to the recipient immediately. By default, some person must review its contents and must either accept or reject the message.

Moderation is done through the Admin site. To ease the action, a special message type is available: PendingMessage. It's nothing else but the classic Message type, but:

  • It is intended to collect only messages in the pending state
  • A dedicated simplified change view is available, with two main buttons: Accept and Reject

The moderator can give a reason in case of rejection of the message. If provided, this piece of information will be reported in the notification to the sender.

Auto moderators

You may automate the moderation by giving zero, one, or many auto-moderator functions to the views. The value of the parameter can be one single function or a sequence of functions as a tuple or a list.

Views supporting an auto-moderators parameter are: write, reply.

Example:

def mod1(message):
    # ...
    return None

def mod2(message):
    # ...
    return None
mod2.default_reason = 'mod2 default reason'

urlpatterns = patterns('postman.views',
    # ...
    url(r'^write/(?:(?P<recipients>[\w.@+-:]+)/)?$', 'write',
        {'auto_moderators': (mod1, mod2)}, name='postman_write'),
    url(r'^reply/(?P<message_id>[\d]+)/$', 'reply',
        {'auto_moderators': mod1}, name='postman_reply'),
    # ...
)

Each auto-moderator function will be called for the message to moderate, in the same order as the one set in the parameter.

Input:

  • message: a Message instance

Output:

The structure of the output is either a rating or a tuple (rating, reason).

rating may take the following values:

  • None
  • 0 or False
  • 100 or True
  • an integer between 1 and 99

reason is a string, giving a specific reason for a rejection. If not provided, a default reason will be taken from the default_reason attribute of the function, if any. Otherwise, there will be no reason.

The processing of the chain of auto-moderators is managed by these rules:

  1. If return is None or outside the range 0..100, the auto-moderator is neutral
  2. If return is 0, no other function is processed, the message is rejected
  3. If return is 100, no other function is processed, the message is accepted
  4. Otherwise, the rating will count for an average among the full set of returned ratings

At the end of the loop, if the decision is not final, the sequence is:

  1. If there was no valid rating at all, then the POSTMAN_AUTO_MODERATE_AS setting applies.
  2. An average rating is computed: if greater or equal to 50, the message is accepted.
  3. The message is rejected. The final reason is a comma separated collection of reasons coming from moderators having returned a rating lesser than 50.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.