Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13301 -- Corrected problem with capitalization of changelist r…

…ow headers in admin. Thanks to emyller for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12947 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit faceca7075d72d55f0eebc586049fb634cd46129 1 parent f4c76fb
Russell Keith-Magee authored April 11, 2010
13  django/contrib/admin/helpers.py
@@ -7,6 +7,7 @@
7 7
 from django.db.models.fields import FieldDoesNotExist
8 8
 from django.db.models.fields.related import ManyToManyRel
9 9
 from django.forms.util import flatatt
  10
+from django.template.defaultfilters import capfirst
10 11
 from django.utils.encoding import force_unicode, smart_unicode
11 12
 from django.utils.html import escape, conditional_escape
12 13
 from django.utils.safestring import mark_safe
@@ -132,8 +133,12 @@ def __init__(self, form, field, is_first, model_admin=None):
132 133
         # Make self.field look a little bit like a field. This means that
133 134
         # {{ field.name }} must be a useful class name to identify the field.
134 135
         # For convenience, store other field-related data here too.
  136
+        if callable(field):
  137
+            class_name = field.__name__ != '<lambda>' and field.__name__ or ''
  138
+        else:
  139
+            class_name = field
135 140
         self.field = {
136  
-            'name': force_unicode(label != '--' and label or ''),
  141
+            'name': class_name,
137 142
             'label': label,
138 143
             'field': field,
139 144
         }
@@ -147,8 +152,8 @@ def label_tag(self):
147 152
         attrs = {}
148 153
         if not self.is_first:
149 154
             attrs["class"] = "inline"
150  
-        label = forms.forms.pretty_name(self.field['label'])
151  
-        contents = force_unicode(escape(label)) + u":"
  155
+        label = self.field['label']
  156
+        contents = capfirst(force_unicode(escape(label))) + u":"
152 157
         return mark_safe('<label%(attrs)s>%(contents)s</label>' % {
153 158
             "attrs": flatatt(attrs),
154 159
             "contents": contents,
@@ -213,7 +218,7 @@ def fields(self):
213 218
                 continue
214 219
             if field in self.readonly_fields:
215 220
                 label = label_for_field(field, self.opts.model, self.model_admin)
216  
-                yield (False, forms.forms.pretty_name(label))
  221
+                yield (False, label)
217 222
             else:
218 223
                 field = self.formset.form.base_fields[field]
219 224
                 yield (field.widget.is_hidden, field.label)
1  django/contrib/admin/templatetags/admin_list.py
@@ -88,7 +88,6 @@ def result_headers(cl):
88 88
                     "class_attrib": mark_safe(' class="action-checkbox-column"')
89 89
                 }
90 90
                 continue
91  
-            header = pretty_name(header)
92 91
 
93 92
             # It is a non-field, but perhaps one that is sortable
94 93
             admin_order_field = getattr(attr, "admin_order_field", None)
5  django/contrib/admin/util.py
... ...
@@ -1,5 +1,6 @@
1 1
 from django.core.exceptions import ObjectDoesNotExist
2 2
 from django.db import models
  3
+from django.forms.forms import pretty_name
3 4
 from django.utils import formats
4 5
 from django.utils.html import escape
5 6
 from django.utils.safestring import mark_safe
@@ -303,9 +304,9 @@ def label_for_field(name, model, model_admin=None, return_attr=False):
303 304
                 if attr.__name__ == "<lambda>":
304 305
                     label = "--"
305 306
                 else:
306  
-                    label = attr.__name__
  307
+                    label = pretty_name(attr.__name__)
307 308
             else:
308  
-                label = name
  309
+                label = pretty_name(name)
309 310
     if return_attr:
310 311
         return (label, attr)
311 312
     else:
2  tests/regressiontests/admin_util/models.py
@@ -16,7 +16,7 @@ def test_from_model(self):
16 16
 
17 17
     def test_from_model_with_override(self):
18 18
         return "nothing"
19  
-    test_from_model_with_override.short_description = "not what you expect"
  19
+    test_from_model_with_override.short_description = "not What you Expect"
20 20
 
21 21
 class Count(models.Model):
22 22
     num = models.PositiveSmallIntegerField()
19  tests/regressiontests/admin_util/tests.py
@@ -157,7 +157,7 @@ def test_label_for_field(self):
157 157
             "another name"
158 158
         )
159 159
         self.assertEquals(
160  
-            label_for_field("title2", Article, return_attr=True), 
  160
+            label_for_field("title2", Article, return_attr=True),
161 161
             ("another name", None)
162 162
         )
163 163
 
@@ -179,24 +179,24 @@ def test_callable(obj):
179 179
             return "nothing"
180 180
         self.assertEquals(
181 181
             label_for_field(test_callable, Article),
182  
-            "test_callable"
  182
+            "Test callable"
183 183
         )
184 184
         self.assertEquals(
185 185
             label_for_field(test_callable, Article, return_attr=True),
186  
-            ("test_callable", test_callable)
  186
+            ("Test callable", test_callable)
187 187
         )
188 188
 
189 189
         self.assertEquals(
190 190
             label_for_field("test_from_model", Article),
191  
-            "test_from_model"
  191
+            "Test from model"
192 192
         )
193 193
         self.assertEquals(
194 194
             label_for_field("test_from_model", Article, return_attr=True),
195  
-            ("test_from_model", Article.test_from_model)
  195
+            ("Test from model", Article.test_from_model)
196 196
         )
197 197
         self.assertEquals(
198 198
             label_for_field("test_from_model_with_override", Article),
199  
-            "not what you expect"
  199
+            "not What you Expect"
200 200
         )
201 201
 
202 202
         self.assertEquals(
@@ -207,15 +207,16 @@ def test_callable(obj):
207 207
         class MockModelAdmin(object):
208 208
             def test_from_model(self, obj):
209 209
                 return "nothing"
210  
-            test_from_model.short_description = "not really the model"
  210
+            test_from_model.short_description = "not Really the Model"
  211
+
211 212
         self.assertEquals(
212 213
             label_for_field("test_from_model", Article, model_admin=MockModelAdmin),
213  
-            "not really the model"
  214
+            "not Really the Model"
214 215
         )
215 216
         self.assertEquals(
216 217
             label_for_field("test_from_model", Article,
217 218
                 model_admin = MockModelAdmin,
218 219
                 return_attr = True
219 220
             ),
220  
-            ("not really the model", MockModelAdmin.test_from_model)
  221
+            ("not Really the Model", MockModelAdmin.test_from_model)
221 222
         )
7  tests/regressiontests/admin_views/models.py
@@ -474,7 +474,7 @@ def awesomeness_level(self):
474 474
 
475 475
 class PostAdmin(admin.ModelAdmin):
476 476
     list_display = ['title', 'public']
477  
-    readonly_fields = ('posted', 'awesomeness_level', 'coolness', lambda obj: "foo")
  477
+    readonly_fields = ('posted', 'awesomeness_level', 'coolness', 'value', lambda obj: "foo")
478 478
 
479 479
     inlines = [
480 480
         LinkInline
@@ -486,6 +486,9 @@ def coolness(self, instance):
486 486
         else:
487 487
             return "Unkown coolness."
488 488
 
  489
+    def value(self, instance):
  490
+        return 1000
  491
+    value.short_description = 'Value in $US'
489 492
 
490 493
 class Gadget(models.Model):
491 494
     name = models.CharField(max_length=100)
@@ -567,7 +570,7 @@ def __unicode__(self):
567 570
         return self.name
568 571
 
569 572
 class Topping(models.Model):
570  
-    name = models.CharField(max_length=20) 
  573
+    name = models.CharField(max_length=20)
571 574
 
572 575
 class Pizza(models.Model):
573 576
     name = models.CharField(max_length=20)
1  tests/regressiontests/admin_views/tests.py
@@ -1970,6 +1970,7 @@ def test_readonly_get(self):
1970 1970
         self.assertContains(response, '<div class="form-row coolness">')
1971 1971
         self.assertContains(response, '<div class="form-row awesomeness_level">')
1972 1972
         self.assertContains(response, '<div class="form-row posted">')
  1973
+        self.assertContains(response, '<div class="form-row value">')
1973 1974
         self.assertContains(response, '<div class="form-row ">')
1974 1975
 
1975 1976
         p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")

0 notes on commit faceca7

Please sign in to comment.
Something went wrong with that request. Please try again.