#7115 closed (fixed)
[Patch] django.contrib.auth Permissions ordering changed due to qsrf
Reported by: | 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 |
Description
Hi,
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 content_type.id and not content_type.name.
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/models.py =================================================================== --- django/contrib/auth/models.py (revision 7503) +++ django/contrib/auth/models.py (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, self.name)
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 Group.objects.filter(name='permordering').delete() g = Group(name='permordering') g.save() 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.id, perm.content_type, perm.codename) g.permissions = perms g.save() print serialize('json', [g])
Change History (4)
comment:1 by , 17 years ago
Component: | Contrib apps → Admin interface |
---|
comment:2 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:3 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [8246]) Fixed #7115: tweaked ordering on Permission to more closely match the pre-QSRF behavior, which was nice. Thanks, Matthew Flanagan.