[Patch] django.contrib.auth Permissions ordering changed due to qsrf
|Reported by:||Matthew Flanagan <mattimustang@…>||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||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 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)
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 Changed 8 years ago by telenieko
- Component changed from Contrib apps to Admin interface
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 8 years ago by ericholscher
- milestone set to 1.0
- Triage Stage changed from Unreviewed to Design decision needed