mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #12385: Made built-in field type descriptions in admindocs translatable again. Many thanks to Ramiro for the problem report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11878 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -1,36 +1,30 @@
|
||||
import unittest
|
||||
from django.contrib.admindocs import views
|
||||
import fields
|
||||
|
||||
from django.contrib.admindocs import views
|
||||
from django.db.models import fields as builtin_fields
|
||||
|
||||
|
||||
class TestFieldType(unittest.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_field_name(self):
|
||||
self.assertRaises(AttributeError,
|
||||
views.get_readable_field_data_type, "NotAField"
|
||||
)
|
||||
|
||||
|
||||
def test_builtin_fields(self):
|
||||
self.assertEqual(
|
||||
views.get_readable_field_data_type(builtin_fields.BooleanField()),
|
||||
u'Boolean (Either True or False)'
|
||||
)
|
||||
|
||||
|
||||
def test_custom_fields(self):
|
||||
self.assertEqual(
|
||||
views.get_readable_field_data_type(fields.CustomField()),
|
||||
u'A custom field type'
|
||||
)
|
||||
self.assertEqual(
|
||||
views.get_readable_field_data_type(fields.DocstringLackingField()),
|
||||
u'Field of type: DocstringLackingField'
|
||||
)
|
||||
|
||||
def test_multiline_custom_field_truncation(self):
|
||||
self.assertEqual(
|
||||
views.get_readable_field_data_type(fields.ManyLineDocstringField()),
|
||||
u'Many-line custom field'
|
||||
views.get_readable_field_data_type(fields.DescriptionLackingField()),
|
||||
u'Field of type: DescriptionLackingField'
|
||||
)
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
from django.db import models
|
||||
|
||||
class CustomField(models.Field):
|
||||
"""A custom field type"""
|
||||
|
||||
class ManyLineDocstringField(models.Field):
|
||||
"""Many-line custom field
|
||||
|
||||
This docstring has many lines. Lorum ipsem etc. etc. Four score
|
||||
and seven years ago, and so on and so forth."""
|
||||
description = "A custom field type"
|
||||
|
||||
class DocstringLackingField(models.Field):
|
||||
class DescriptionLackingField(models.Field):
|
||||
pass
|
||||
|
||||
@@ -327,19 +327,11 @@ def get_return_data_type(func_name):
|
||||
return ''
|
||||
|
||||
def get_readable_field_data_type(field):
|
||||
"""Returns the first line of a doc string for a given field type, if it
|
||||
exists. Fields' docstrings can contain format strings, which will be
|
||||
interpolated against the values of Field.__dict__ before being output.
|
||||
If no docstring is given, a sensible value will be auto-generated from
|
||||
the field's class name."""
|
||||
"""Returns the description for a given field type, if it exists,
|
||||
Fields' descriptions can contain format strings, which will be interpolated
|
||||
against the values of field.__dict__ before being output."""
|
||||
|
||||
if field.__doc__:
|
||||
doc = field.__doc__.split('\n')[0]
|
||||
return _(doc) % field.__dict__
|
||||
else:
|
||||
return _(u'Field of type: %(field_type)s') % {
|
||||
'field_type': field.__class__.__name__
|
||||
}
|
||||
return field.description % field.__dict__
|
||||
|
||||
def extract_views_from_urlpatterns(urlpatterns, base=''):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user