summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2010-03-16 16:10:27 +0000
committerKaren Tracey <kmtracey@gmail.com>2010-03-16 16:10:27 +0000
commitcc6e9b22864a0dd72bcc778ab3f673853ee4987d (patch)
treeb9a1a8544a57109a5b988d9a0c74a58139988905
parent3c59067a4f2f7f9281bc425378555262a03c0077 (diff)
downloaddjango-cc6e9b22864a0dd72bcc778ab3f673853ee4987d.tar.gz
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
-rw-r--r--django/forms/forms.py7
-rw-r--r--tests/regressiontests/admin_views/models.py2
2 files changed, 6 insertions, 3 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 45bbbb41b6..b3718efa9a 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -18,9 +18,10 @@ __all__ = ('BaseForm', 'Form')
NON_FIELD_ERRORS = '__all__'
def pretty_name(name):
- "Converts 'first_name' to 'First name'"
- name = name[0].upper() + name[1:]
- return name.replace('_', ' ')
+ """Converts 'first_name' to 'First name'"""
+ if not name:
+ return u''
+ return name.replace('_', ' ').capitalize()
def get_declared_fields(bases, attrs, with_base_fields=True):
"""
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index b8b4e50ba2..80f137ae86 100644
--- a/tests/regressiontests/admin_views/models.py
+++ b/tests/regressiontests/admin_views/models.py
@@ -35,6 +35,7 @@ class Article(models.Model):
def model_year(self):
return self.date.year
model_year.admin_order_field = 'date'
+ model_year.short_description = ''
class Book(models.Model):
"""
@@ -103,6 +104,7 @@ class ArticleAdmin(admin.ModelAdmin):
def modeladmin_year(self, obj):
return obj.date.year
modeladmin_year.admin_order_field = 'date'
+ modeladmin_year.short_description = None
class CustomArticle(models.Model):
content = models.TextField()