Commit f4282336 authored by Karen Tracey's avatar Karen Tracey
Browse files

[1.1.X] Fixed #12385: Made built-in field type descriptions in admindocs...

[1.1.X] Fixed #12385: Made built-in field type descriptions in admindocs translatable again. Many thanks to Ramiro for the problem report and patch. 

r11878 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11879 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 45bc45ea
Loading
Loading
Loading
Loading
+7 −13
Original line number Diff line number Diff line
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
@@ -25,12 +25,6 @@ class TestFieldType(unittest.TestCase):
            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'
        )
+2 −8
Original line number Diff line number Diff line
from django.db import models

class CustomField(models.Field):
    """A custom field type"""
    description = "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."""

class DocstringLackingField(models.Field):
class DescriptionLackingField(models.Field):
    pass
+5 −13
Original line number Diff line number Diff line
@@ -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."""

    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__
        } 
    """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."""

    return field.description % field.__dict__

def extract_views_from_urlpatterns(urlpatterns, base=''):
    """
+11 −8
Original line number Diff line number Diff line
from django.utils.translation import ugettext_lazy as _
from django.contrib.gis import forms
# Getting the SpatialBackend container and the geographic quoting method.
from django.contrib.gis.db.backend import SpatialBackend, gqn
@@ -30,7 +31,7 @@ def get_srid_info(srid):
    return _srid_cache[srid]

class GeometryField(SpatialBackend.Field):
    """The base GIS field -- maps to the OpenGIS Specification Geometry type."""
    "The base GIS field -- maps to the OpenGIS Specification Geometry type."

    # The OpenGIS Geometry name.
    geom_type = 'GEOMETRY'
@@ -38,6 +39,8 @@ class GeometryField(SpatialBackend.Field):
    # Geodetic units.
    geodetic_units = ('Decimal Degree', 'degree')

    description = _("The base GIS field -- maps to the OpenGIS Specification Geometry type.")

    def __init__(self, verbose_name=None, srid=4326, spatial_index=True, dim=2, **kwargs):
        """
        The initialization function for geometry fields.  Takes the following
@@ -257,29 +260,29 @@ class GeometryField(SpatialBackend.Field):

# The OpenGIS Geometry Type Fields
class PointField(GeometryField):
    """Point"""
    geom_type = 'POINT'
    description = _("Point")

class LineStringField(GeometryField):
    """Line string"""
    geom_type = 'LINESTRING'
    description = _("Line string")

class PolygonField(GeometryField):
    """Polygon"""
    geom_type = 'POLYGON'
    description = _("Polygon")

class MultiPointField(GeometryField):
    """Multi-point"""
    geom_type = 'MULTIPOINT'
    description = _("Multi-point")

class MultiLineStringField(GeometryField):
    """Multi-line string"""
    geom_type = 'MULTILINESTRING'
    description = _("Multi-line string")

class MultiPolygonField(GeometryField):
    """Multi polygon"""
    geom_type = 'MULTIPOLYGON'
    description = _("Multi polygon")

class GeometryCollectionField(GeometryField):
    """Geometry collection"""
    geom_type = 'GEOMETRYCOLLECTION'
    description = _("Geometry collection")
+9 −4
Original line number Diff line number Diff line
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.db.models.fields import Field, CharField
from django.contrib.localflavor.us.us_states import STATE_CHOICES

class USStateField(CharField):
    """U.S. state (two uppercase letters)"""

    description = _("U.S. state (two uppercase letters)")

    def __init__(self, *args, **kwargs):
        kwargs['choices'] = STATE_CHOICES
        kwargs['max_length'] = 2
        super(USStateField, self).__init__(*args, **kwargs)

class PhoneNumberField(Field):
    """Phone number"""

    description = _("Phone number")

    def get_internal_type(self):
        return "PhoneNumberField"

Loading