Skip to content

Commit cc6e9b2

Browse files
committed
Fixed #12434: Made pretty_name handle empty string and None as input. Thanks ales_zoulek and gabrielhurley.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12794 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 3c59067 commit cc6e9b2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

django/forms/forms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
NON_FIELD_ERRORS = '__all__'
1919

2020
def pretty_name(name):
21-
"Converts 'first_name' to 'First name'"
22-
name = name[0].upper() + name[1:]
23-
return name.replace('_', ' ')
21+
"""Converts 'first_name' to 'First name'"""
22+
if not name:
23+
return u''
24+
return name.replace('_', ' ').capitalize()
2425

2526
def get_declared_fields(bases, attrs, with_base_fields=True):
2627
"""

tests/regressiontests/admin_views/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __unicode__(self):
3535
def model_year(self):
3636
return self.date.year
3737
model_year.admin_order_field = 'date'
38+
model_year.short_description = ''
3839

3940
class Book(models.Model):
4041
"""
@@ -103,6 +104,7 @@ def changelist_view(self, request):
103104
def modeladmin_year(self, obj):
104105
return obj.date.year
105106
modeladmin_year.admin_order_field = 'date'
107+
modeladmin_year.short_description = None
106108

107109
class CustomArticle(models.Model):
108110
content = models.TextField()

0 commit comments

Comments
 (0)