Fixed #13301 -- Corrected problem with capitalization of changelist row 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
This commit is contained in:
Russell Keith-Magee 2010-04-11 08:35:04 +00:00
parent f4c76fb604
commit faceca7075
7 changed files with 29 additions and 19 deletions

View File

@ -7,6 +7,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.db.models.fields import FieldDoesNotExist from django.db.models.fields import FieldDoesNotExist
from django.db.models.fields.related import ManyToManyRel from django.db.models.fields.related import ManyToManyRel
from django.forms.util import flatatt from django.forms.util import flatatt
from django.template.defaultfilters import capfirst
from django.utils.encoding import force_unicode, smart_unicode from django.utils.encoding import force_unicode, smart_unicode
from django.utils.html import escape, conditional_escape from django.utils.html import escape, conditional_escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
@ -132,8 +133,12 @@ class AdminReadonlyField(object):
# Make self.field look a little bit like a field. This means that # Make self.field look a little bit like a field. This means that
# {{ field.name }} must be a useful class name to identify the field. # {{ field.name }} must be a useful class name to identify the field.
# For convenience, store other field-related data here too. # For convenience, store other field-related data here too.
if callable(field):
class_name = field.__name__ != '<lambda>' and field.__name__ or ''
else:
class_name = field
self.field = { self.field = {
'name': force_unicode(label != '--' and label or ''), 'name': class_name,
'label': label, 'label': label,
'field': field, 'field': field,
} }
@ -147,8 +152,8 @@ class AdminReadonlyField(object):
attrs = {} attrs = {}
if not self.is_first: if not self.is_first:
attrs["class"] = "inline" attrs["class"] = "inline"
label = forms.forms.pretty_name(self.field['label']) label = self.field['label']
contents = force_unicode(escape(label)) + u":" contents = capfirst(force_unicode(escape(label))) + u":"
return mark_safe('<label%(attrs)s>%(contents)s</label>' % { return mark_safe('<label%(attrs)s>%(contents)s</label>' % {
"attrs": flatatt(attrs), "attrs": flatatt(attrs),
"contents": contents, "contents": contents,
@ -213,7 +218,7 @@ class InlineAdminFormSet(object):
continue continue
if field in self.readonly_fields: if field in self.readonly_fields:
label = label_for_field(field, self.opts.model, self.model_admin) label = label_for_field(field, self.opts.model, self.model_admin)
yield (False, forms.forms.pretty_name(label)) yield (False, label)
else: else:
field = self.formset.form.base_fields[field] field = self.formset.form.base_fields[field]
yield (field.widget.is_hidden, field.label) yield (field.widget.is_hidden, field.label)

View File

@ -88,7 +88,6 @@ def result_headers(cl):
"class_attrib": mark_safe(' class="action-checkbox-column"') "class_attrib": mark_safe(' class="action-checkbox-column"')
} }
continue continue
header = pretty_name(header)
# It is a non-field, but perhaps one that is sortable # It is a non-field, but perhaps one that is sortable
admin_order_field = getattr(attr, "admin_order_field", None) admin_order_field = getattr(attr, "admin_order_field", None)

View File

@ -1,5 +1,6 @@
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.db import models from django.db import models
from django.forms.forms import pretty_name
from django.utils import formats from django.utils import formats
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
@ -303,9 +304,9 @@ def label_for_field(name, model, model_admin=None, return_attr=False):
if attr.__name__ == "<lambda>": if attr.__name__ == "<lambda>":
label = "--" label = "--"
else: else:
label = attr.__name__ label = pretty_name(attr.__name__)
else: else:
label = name label = pretty_name(name)
if return_attr: if return_attr:
return (label, attr) return (label, attr)
else: else:

View File

@ -16,7 +16,7 @@ class Article(models.Model):
def test_from_model_with_override(self): def test_from_model_with_override(self):
return "nothing" return "nothing"
test_from_model_with_override.short_description = "not what you expect" test_from_model_with_override.short_description = "not What you Expect"
class Count(models.Model): class Count(models.Model):
num = models.PositiveSmallIntegerField() num = models.PositiveSmallIntegerField()

View File

@ -179,24 +179,24 @@ class UtilTests(unittest.TestCase):
return "nothing" return "nothing"
self.assertEquals( self.assertEquals(
label_for_field(test_callable, Article), label_for_field(test_callable, Article),
"test_callable" "Test callable"
) )
self.assertEquals( self.assertEquals(
label_for_field(test_callable, Article, return_attr=True), label_for_field(test_callable, Article, return_attr=True),
("test_callable", test_callable) ("Test callable", test_callable)
) )
self.assertEquals( self.assertEquals(
label_for_field("test_from_model", Article), label_for_field("test_from_model", Article),
"test_from_model" "Test from model"
) )
self.assertEquals( self.assertEquals(
label_for_field("test_from_model", Article, return_attr=True), label_for_field("test_from_model", Article, return_attr=True),
("test_from_model", Article.test_from_model) ("Test from model", Article.test_from_model)
) )
self.assertEquals( self.assertEquals(
label_for_field("test_from_model_with_override", Article), label_for_field("test_from_model_with_override", Article),
"not what you expect" "not What you Expect"
) )
self.assertEquals( self.assertEquals(
@ -207,15 +207,16 @@ class UtilTests(unittest.TestCase):
class MockModelAdmin(object): class MockModelAdmin(object):
def test_from_model(self, obj): def test_from_model(self, obj):
return "nothing" return "nothing"
test_from_model.short_description = "not really the model" test_from_model.short_description = "not Really the Model"
self.assertEquals( self.assertEquals(
label_for_field("test_from_model", Article, model_admin=MockModelAdmin), label_for_field("test_from_model", Article, model_admin=MockModelAdmin),
"not really the model" "not Really the Model"
) )
self.assertEquals( self.assertEquals(
label_for_field("test_from_model", Article, label_for_field("test_from_model", Article,
model_admin = MockModelAdmin, model_admin = MockModelAdmin,
return_attr = True return_attr = True
), ),
("not really the model", MockModelAdmin.test_from_model) ("not Really the Model", MockModelAdmin.test_from_model)
) )

View File

@ -474,7 +474,7 @@ class Post(models.Model):
class PostAdmin(admin.ModelAdmin): class PostAdmin(admin.ModelAdmin):
list_display = ['title', 'public'] list_display = ['title', 'public']
readonly_fields = ('posted', 'awesomeness_level', 'coolness', lambda obj: "foo") readonly_fields = ('posted', 'awesomeness_level', 'coolness', 'value', lambda obj: "foo")
inlines = [ inlines = [
LinkInline LinkInline
@ -486,6 +486,9 @@ class PostAdmin(admin.ModelAdmin):
else: else:
return "Unkown coolness." return "Unkown coolness."
def value(self, instance):
return 1000
value.short_description = 'Value in $US'
class Gadget(models.Model): class Gadget(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)

View File

@ -1970,6 +1970,7 @@ class ReadonlyTest(TestCase):
self.assertContains(response, '<div class="form-row coolness">') self.assertContains(response, '<div class="form-row coolness">')
self.assertContains(response, '<div class="form-row awesomeness_level">') self.assertContains(response, '<div class="form-row awesomeness_level">')
self.assertContains(response, '<div class="form-row posted">') self.assertContains(response, '<div class="form-row posted">')
self.assertContains(response, '<div class="form-row value">')
self.assertContains(response, '<div class="form-row ">') self.assertContains(response, '<div class="form-row ">')
p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff") p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")