Opened 15 years ago

Closed 14 years ago

Last modified 11 years ago

#7115 closed (fixed)

[Patch] django.contrib.auth Permissions ordering changed due to qsrf

Reported by: Matthew Flanagan <mattimustang@…> Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



With the merge of the QSRF branch to trunk the ordering of the Permissions model results have changed due to the new QSRF changes respecting the Meta: ordering = ... on related fields. The Permissions model has ordering = ('content_type', 'codename') and ContentType in turn has ordering= ('name',). In pre-QSRF the ordering of ContentType was not respected and so the resulting ordering of permissions was actually on the and not

QSRF has fixed this and this is a good thing but I believe the original intent of the ordering of the Permission model was to group permissions belonging to the same app together so when they are displayed in the django admin they are also grouped in the multi-select list box.

The patch below restores the permissions ordering to what it was prior to the QSRF merge.

Index: django/contrib/auth/
--- django/contrib/auth/       (revision 7503)
+++ django/contrib/auth/       (working copy)
@@ -78,7 +78,7 @@
         verbose_name = _('permission')
         verbose_name_plural = _('permissions')
         unique_together = (('content_type', 'codename'),)
-        ordering = ('content_type', 'codename')
+        ordering = ('content_type__app_label', 'codename')

     def __unicode__(self):
         return u"%s | %s | %s" % (self.content_type.app_label, self.content_type,

A little test case below shows the ordering issue. Run it on pre-QSRF rev [7476] and post-QSRF trunk rev [7503]:

from django.contrib.auth.models import Group, Permission
from django.core.serializers import serialize

# cleanup from previous test

g = Group(name='permordering')

perms = [1,2,16]
print 'Assigning permissions to group:'
for p in perms:
    #print the fields in ordering = ('content_type', 'codename')
    perm = Permission.objects.get(pk=p)
    print '\t%d (%d, %s, %s)' % (p,, perm.content_type, perm.codename)
g.permissions = perms

print serialize('json', [g])

Change History (4)

comment:1 Changed 14 years ago by Marc Fargas

Component: Contrib appsAdmin interface

comment:2 Changed 14 years ago by Eric Holscher

milestone: 1.0
Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 14 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [8246]) Fixed #7115: tweaked ordering on Permission to more closely match the pre-QSRF behavior, which was nice. Thanks, Matthew Flanagan.

comment:4 Changed 11 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top