Ticket #9969: 9969-backport-to-1.0.x.diff
File 9969-backport-to-1.0.x.diff, 5.6 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/filterspecs.py
diff -r 1e19a4bc3612 django/contrib/admin/filterspecs.py
a b 90 90 yield {'selected': self.lookup_val is None, 91 91 'query_string': cl.get_query_string({}, [self.lookup_kwarg]), 92 92 'display': _('All')} 93 for k, v in self.field. choices:93 for k, v in self.field.flatchoices: 94 94 yield {'selected': smart_unicode(k) == self.lookup_val, 95 95 'query_string': cl.get_query_string({self.lookup_kwarg: k}), 96 96 'display': v} -
django/contrib/admin/templatetags/admin_list.py
diff -r 1e19a4bc3612 django/contrib/admin/templatetags/admin_list.py
a b 205 205 result_repr = EMPTY_CHANGELIST_VALUE 206 206 # Fields with choices are special: Use the representation 207 207 # of the choice. 208 elif f. choices:209 result_repr = dict(f. choices).get(field_val, EMPTY_CHANGELIST_VALUE)208 elif f.flatchoices: 209 result_repr = dict(f.flatchoices).get(field_val, EMPTY_CHANGELIST_VALUE) 210 210 else: 211 211 result_repr = escape(field_val) 212 212 if force_unicode(result_repr) == '': -
new file tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml
diff -r 1e19a4bc3612 tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml
- + 1 <?xml version="1.0" encoding="utf-8"?> 2 <django-objects version="1.0"> 3 <object pk="1" model="admin_views.fabric"> 4 <field type="CharField" name="surface">x</field> 5 </object> 6 <object pk="2" model="admin_views.fabric"> 7 <field type="CharField" name="surface">y</field> 8 </object> 9 <object pk="3" model="admin_views.fabric"> 10 <field type="CharField" name="surface">plain</field> 11 </object> 12 </django-objects> -
tests/regressiontests/admin_views/models.py
diff -r 1e19a4bc3612 tests/regressiontests/admin_views/models.py
a b 134 134 class ThingAdmin(admin.ModelAdmin): 135 135 list_filter = ('color',) 136 136 137 class Fabric(models.Model): 138 NG_CHOICES = ( 139 ('Textured', ( 140 ('x', 'Horizontal'), 141 ('y', 'Vertical'), 142 ) 143 ), 144 ('plain', 'Smooth'), 145 ) 146 surface = models.CharField(max_length=20, choices=NG_CHOICES) 147 148 class FabricAdmin(admin.ModelAdmin): 149 list_display = ('surface',) 150 list_filter = ('surface',) 151 137 152 class Persona(models.Model): 138 153 """ 139 154 A simple persona associated with accounts, to test inlining of related … … 208 223 admin.site.register(Persona, PersonaAdmin) 209 224 admin.site.register(Parent, ParentAdmin) 210 225 admin.site.register(EmptyModel, EmptyModelAdmin) 226 admin.site.register(Fabric, FabricAdmin) 211 227 212 228 # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. 213 229 # That way we cover all four cases: -
tests/regressiontests/admin_views/tests.py
diff -r 1e19a4bc3612 tests/regressiontests/admin_views/tests.py
a b 19 19 from sets import Set as set 20 20 21 21 class AdminViewBasicTest(TestCase): 22 fixtures = ['admin-views-users.xml', 'admin-views-colors.xml' ]22 fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml'] 23 23 24 24 def setUp(self): 25 25 self.client.login(username='super', password='secret') … … 174 174 self.assertRedirects(response, '/test_admin/admin/admin_views/thing/?e=1') 175 175 response = self.client.get('/test_admin/admin/admin_views/thing/', {'color__id__exact': 'StringNotInteger!'}) 176 176 self.assertRedirects(response, '/test_admin/admin/admin_views/thing/?e=1') 177 178 def testNamedGroupFieldChoicesChangeList(self): 179 """ 180 Ensures the admin changelist shows correct values in the relevant column 181 for rows corresponding to instances of a model in which a named group 182 has been used in the choices option of a field. 183 """ 184 response = self.client.get('/test_admin/admin/admin_views/fabric/') 185 self.failUnlessEqual(response.status_code, 200) 186 self.failUnless( 187 '<a href="1/">Horizontal</a>' in response.content and 188 '<a href="2/">Vertical</a>' in response.content, 189 "Changelist table isn't showing the right human-readable values set by a model field 'choices' option named group." 190 ) 191 192 def testNamedGroupFieldChoicesFilter(self): 193 """ 194 Ensures the filter UI shows correctly when at least one named group has 195 been used in the choices option of a model field. 196 """ 197 response = self.client.get('/test_admin/admin/admin_views/fabric/') 198 self.failUnlessEqual(response.status_code, 200) 199 self.failUnless( 200 '<div id="changelist-filter">' in response.content, 201 "Expected filter not found in changelist view." 202 ) 203 self.failUnless( 204 '<a href="?surface__exact=x">Horizontal</a>' in response.content and 205 '<a href="?surface__exact=y">Vertical</a>' in response.content, 206 "Changelist filter isn't showing options contained inside a model field 'choices' option named group." 207 ) 177 208 178 209 def get_perm(Model, perm): 179 210 """Return the permission object, for the Model"""