示例#1
0
def nq(
    model, rel_fields = [], import_unmoderated=False, can_delete_approved = True, long_desc=None,
    manager_name = 'objects', status_name = 'status',
    monitor_name = 'monitor_entry', base_manager = None, notify_moderators=None
):
    """ Register(enqueue) the model for moderation."""
    if not model_from_queue(model):
        signals.post_save.connect(save_handler, sender = model)
        signals.pre_delete.connect(delete_handler, sender = model)
        registered_model = get_model(
            model._meta.app_label, model._meta.object_name, only_installed=False
        )
        add_fields(
            registered_model, manager_name, status_name,
            monitor_name, base_manager
        )
        _queue[model] = {
            'rel_fields': rel_fields,
            'can_delete_approved': can_delete_approved,
            'manager_name': manager_name,
            'status_name': status_name,
            'monitor_name': monitor_name,
            'long_desc': long_desc or _default_long_desc,
            'notify_moderators': notify_moderators,
        }
        if import_unmoderated:
            try:
                mod_obj_ids = model.objects.all().values_list('pk', flat=True)
                unmod_objs = model._base_manager.exclude(pk__in=mod_obj_ids)
                print 'importing %s unmoderated objects...' % unmod_objs.count()
                for obj in unmod_objs:
                    me = MonitorEntry(
                        status=PENDING_STATUS,
                        content_object=obj,
                        status_date=datetime.datetime.now())
                    me.save()
            except:
                pass
示例#2
0
def nq(
    model, rel_fields = [], can_delete_approved = True,
    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)
        signals.pre_delete.connect(delete_handler, sender = model)
        registered_model = get_model(
            model._meta.app_label, model._meta.object_name, False
        )
        add_fields(
            registered_model, manager_name, status_name,
            monitor_name, base_manager
        )
        _queue[model] = {
            'rel_fields': rel_fields,
            'can_delete_approved': can_delete_approved,
            'manager_name': manager_name,
            'status_name': status_name,
            'monitor_name': monitor_name
        }