Package: django-gatekeeper
Django application for moderation of model instances.Provides convenience methods and an admin interface for moderating instances of registered Django models.django-gatekeeper is a project of Sunlight Labs (c) 2008.
Writen by Jeremy Carbaugh <jcarbaugh@sunlightfoundation.com>All code is under a BSD-style license, see LICENSE for details.Homepage:http://pypi.python.org/pypi/django-gatekeeper/Source:http://github.com/sunlightlabs/django-gatekeeper/Requirementspython >= 2.4django >= 1.0InstallationTo install runpython setup.py installwhich will install the application into python’s site-packages directory.Quick Setupsettings.pyAdd to INSTALLED_APPS:gatekeeperBe sure to place gatekeeper above any application which contains models that will be moderated.Add to MIDDLEWARE_CLASSES:gatekeeper.middleware.GatekeeperMiddlewareAdd to urls.py:url(r’^admin/gatekeeper/’, include(‘gatekeeper.urls’)),Register Models>>> from django.db import models
>>> import gatekeeper
>>> class MyModel(models.Model):
...     pass
>>> gatekeeper.register(MyModel)gatekeeper.registeroptionally takes some extra parameters for advanced configuration, seeadvanced register optionsfor details.Admin Moderation QueueInclude the following in urls.py BEFORE the default admin:url(r'^admin/gatekeeper/',include('gatekeeper.urls')),Accessing Moderated ModelsModels registered withgatekeeper.registerare given a custom manager that adds several extra fields.  (As documented inadvanced register optionsall of these fields can be renamed via special parameters togatekeeper.registerbut for simplicity they will be referred to by their default names throughout this document.)Model Instance Convenience FieldsEvery model instance accessed via the custom manager (‘objects’ by default) has a few extra read-only fields tacked on:moderation_status - current moderation status (APPROVED_STATUS, PENDING_STATUS, or REJECTED_STATUS)flagged - flag status (True or False)In addition,moderation_objectis provided as a shortcut to access the actualModeratedObjectinstance.  The first access of this attribute incurs a database hit but the instance is then cached for the object lifetime.GatekeeperQuerySetThe custom manager returns a special GatekeeperQuerySet with a few extra filters:>>> MyModel.objects.all().approved()     # approved by moderator
>>> MyModel.objects.all().pending()      # pending in moderation queue
>>> MyModel.objects.all().rejected()     # rejected by moderator
>>> MyModel.objects.all().flagged()      # flagged
>>> MyModel.objects.all().not_flagged()  # not flaggedThese are implemented on theGatekeeperQuerySetitself so that they can be chained:>>> MyModel.objects.filter(spam=eggs).rejected().flagged()Deletion of Moderated ObjectsWhen a moderated object instance is deleted, the associated ModeratedObject instance is deleted as well.Advanced UsageAuto-ModerationIt can be hassle to have to manually moderate objects when there is a simple ruleset used to determine how an object will be moderated. In order to use auto-moderation, the following needs to be added to settings.py:GATEKEEPER_ENABLE_AUTOMODERATION = TrueGatekeeper provides two methods of auto-moderation. First, if the user that saves a moderated object has permission to moderate that object, it will be automatically approved. This will always happen if GATEKEEPER_ENABLE_AUTOMODERATION is set to true in settings.py. The second form of auto-moderation allows a moderation method to be written. This method should return True to approve, False to reject, or None to pass on for manual moderation. The auto-moderation function is pass as an argument when registering a Model.>>> class MyModel(models.Model):
...     pass
>>> def myautomod(obj):
...     pass
>>> gatekeeper.register(MyModel, auto_moderator=myautomod)If the auto-moderation function returns None or is not specified for a model, the first form of auto-moderation will be attempted.Long DescriptionWhen registering a model, a long_desc parameter may be specified that is used to render descriptive text about the instance that is being moderated. The long description is used in emails and in the admin interface.>>> class Book(models.Model):
...     title = models.CharField(max_length=128)
...             author = models.CharField(max_length=128)
>>> def booklongdesc(obj):
...     return u"%s written by %s" % (obj.title, obj.author)
>>> gatekeeper.register(MyModel, long_desc=booklongdesc)The long_desc parameter accepts either a method or a string. If a method is passed, it will be invoked with the object as the only parameter. If a string is used, gatekeeper will first look on the object for a method with the same name, then an attribute if no method is found. If neither are found, or no long_desc parameter is specified, the objects __unicode__() method will be called.Default ModerationBy default, moderated model instances will be marked as pending and placed on the moderation queue when created. This behavior can be overridden by specifying GATEKEEPER_DEFAULT_STATUS in settings.py.gatekeeper.PENDING_STATUS- mark objects as pending and place on the moderation queuegatekeeper.APPROVED_STATUS- mark objects as approved and bypass the moderation queuegatekeeper.REJECTED_STATUS- mark objects as rejected and bypass the moderation queueModeration On FlaggingFlagging is provided as a simple mechanism to allow for users to flag content generally for further review.  By default flagging an object does not change it’s moderation status, but GATEKEEPER_STATUS_ON_FLAG is available toalter this behavior.  If GATEKEEPER_STATUS_ON_FLAG is set to one of the status constants (seeDefault Moderation) the given status will be set for an object whenModeratedObject.flagis called.Import Unmoderated ObjectsIf gatekeeper is added to an existing application, objects already in the database will not be registered with gatekeeper. You can register existing objects with gatekeeper by passing true to theimport_unmoderatedparameter of the registration method. The imported objects will be set to the state specified by GATEKEEPER_DEFAULT_STATUS in settings.py or pending if GATEKEEPER_DEFAULT_STATUS is not set.>>> gatekeeper.register(MyModel, import_unmoderated=True)Moderation Queue NotificationsGatekeep will send a notification email to a list of recipients when a new object is placed on the moderation queue. Specify GATEKEEPER_MODERATOR_LIST in settings.py to enable notifications.GATEKEEPER_MODERATOR_LIST =['moderator@mysite.com','admin@yoursite.com']Post-moderation SignalMany applications will want to execute certain tasks once an object is moderated. Gatekeeper provides a signal that is fired when an object is manually or automatically moderated.gatekeeper.post_moderationAdvanced Register Optionsgatekeeper.registertakes a few optional parameters:manager_name:name of manager to add/replace on model (defaults to objects)status_name:name of moderation status field to add to model instances (defaults tomoderation_status)flagged_name:name of flagged field to add to model instances (defaults toflagged)moderation_object_name:name of moderation_object accessor to add to model instances (defaults tomoderation_object)base_manager:Manager for contributed manager placed atmanager_nameto inherit from.  Default behavior is to attempt to inherit from same class as the manager already in place or fall back tomodels.Managerif no manager exists.