Django Comments Require Remove Action for Non-Superusers

I recently upgraded a large Django installation from 1.1 to 1.3. In the Comments application, they added a disclaimer, so only superusers receive the "Delete" action.

Moderators who have permission to delete do not see these actions as a result. This is really inconvenient for them.

This code is in the contrib.comments.admin file, starting at line 28:

def get_actions(self, request):
    actions = super(CommentsAdmin, self).get_actions(request)
    # Only superusers should be able to delete the comments from the DB.
    if not request.user.is_superuser and 'delete_selected' in actions:
        actions.pop('delete_selected')

Instead, ask if request.user has permission to delete.

How can I override this without hacking with the actual Django installation?

(And if anyone knows why this was changed, I would be interested to know.)

+3
source share
2 answers

" ". , "" , - comment.is_removed = True.

comments.can_moderate . , , :

  • CommentsAdmin admin.py
  • get_actions
  • CommentsAdmin ModelAdmin, .

, .

# myapp.admin.py
# The app should come after `django.contrib.comments` 
# in your INSTALLED_APPS tuple

from django.contrib.comments.admin import CommentsAdmin

class MyCommentsAdmin(CommentsAdmin):
    def get_actions(self, request):
        actions = super(MyCommentsAdmin, self).get_actions(request)
        if not request.user.has_perm('comments.can_moderate'):
            if 'approve_comments' in actions:
                actions.pop('approve_comments')
            if 'remove_comments' in actions:
                actions.pop('remove_comments')
        return actions


admin.site.unregister(CommentsAdmin)
admin.site.register(MyCommentsAdmin)
+2
def has_add_permission(self, request):
    return False

def has_delete_permission(self, request, obj=None):
    return False

def get_actions(self, request):
    actions = []
    return actions

. .

0

All Articles