﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7115	[Patch] django.contrib.auth Permissions ordering changed due to qsrf	Matthew Flanagan <mattimustang@…>	nobody	"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])
}}}"		closed	contrib.admin	dev		fixed			Design decision needed	1	0	0	0	0	0
