def moderate_related(self, obj, user, status): """Moderate related objects""" model = model_from_queue(obj.__class__) if model: for rel_name in model['rel_fields']: rel_obj = getattr(obj, rel_name, None) if rel_obj: moderate_rel_objects(rel_obj, status, user)
def moderate_selected(modeladmin, request, queryset, status): """ Generic action to moderate selected objects plus all related objects. """ opts = modeladmin.model._meta # If moderation is disabled.. if not model_from_queue(modeladmin.model): return 0 # Check that the user has required permission for the actual model. # To reset to pending status, change_perm is enough. For all else, # user need to have moderate_perm. if ( (status == PENDING_STATUS and not modeladmin.has_change_permission(request) ) or (status != PENDING_STATUS and not modeladmin.has_moderate_permission(request) ) ): raise PermissionDenied # Approved objects can not further be moderated. queryset = queryset.exclude_approved() # After moderating objects in queryset, moderate related objects also q_count = queryset.count() # We want to use the status display rather than abbreviations in logs. status_display = STATUS_DICT[status] if q_count: #for obj in queryset: #message = 'Changed status from %s to %s.' % ( # obj.get_status_display(), status_display #) #modeladmin.log_moderation(request, obj, message) #me = MonitorEntry.objects.get_for_instance(obj) moderate_rel_objects(queryset, status, request.user) return q_count
def moderate_selected(modeladmin, request, queryset, status): """ Generic action to moderate selected objects plus all related objects. """ # If moderation is disabled.. if not model_from_queue(modeladmin.model): return 0 # Check that the user has required permission for the actual model. # To reset to pending status, change_perm is enough. For all else, # user need to have moderate_perm. if ((status == PENDING_STATUS and not modeladmin.has_change_permission(request)) or (status != PENDING_STATUS and not modeladmin.has_moderate_permission(request))): raise PermissionDenied # Approved objects can not further be moderated. queryset = queryset.exclude_approved() # After moderating objects in queryset, moderate related objects also q_count = queryset.count() # We want to use the status display rather than abbreviations in logs. status_display = STATUS_DICT[status] if q_count: #for obj in queryset: #message = 'Changed status from %s to %s.' % ( # obj.get_status_display(), status_display #) #modeladmin.log_moderation(request, obj, message) #me = MonitorEntry.objects.get_for_instance(obj) moderate_rel_objects(queryset, status, request.user) return q_count