Django-monitor / monitor /

__author__ = "Rajeesh Nair"
__version__ = "0.1.0a"
__copyright__ = "Copyright (c) 2011 Rajeesh"
__license__ = "BSD"

from django.dispatch import Signal
from django.db.models import signals

from monitor.util import create_moderate_perms, add_fields, save_handler

_queue = {}

def model_from_queue(model):
    """ Returns the model dict if model is enqueued, else None."""
    return _queue.get(model, None)

def queued_models():
    """ Return the models enqueued for moderation"""
    return _queue.keys()

def get_monitor_entry(obj):
    """ Returns the monitor_entry for the given object."""
    model_dict = model_from_queue(obj.__class__)
    return getattr(obj, model_dict['monitor_name']) if model_dict else None

def nq(
    model, rel_fields = [], manager_name = 'objects',
    status_name = 'status', monitor_name = 'monitor_entry', base_manager = None
    """ Register(enqueue) the model for moderation."""
    if not model_from_queue(model):
        signals.post_save.connect(save_handler, sender = model)
        add_fields(model, manager_name, status_name, monitor_name, base_manager)
        _queue[model] = {
            'rel_fields': rel_fields,
            'manager_name': manager_name,
            'status_name': status_name,
            'monitor_name': monitor_name

post_moderation = Signal(providing_args = ["instance"])

    dispatch_uid = "django-monitor.create_moderate_perms"
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
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.