Code

Ticket #8210: 8210-1.diff

File 8210-1.diff, 6.0 KB (added by mattmcc, 6 years ago)
Line 
1Index: django/db/models/fields/__init__.py
2===================================================================
3--- django/db/models/fields/__init__.py (revision 8685)
4+++ django/db/models/fields/__init__.py (working copy)
5@@ -842,16 +842,6 @@
6         defaults.update(kwargs)
7         return super(URLField, self).formfield(**defaults)
8 
9-class USStateField(Field):
10-    def get_internal_type(self):
11-        return "USStateField"
12-
13-    def formfield(self, **kwargs):
14-        from django.contrib.localflavor.us.forms import USStateSelect
15-        defaults = {'widget': USStateSelect}
16-        defaults.update(kwargs)
17-        return super(USStateField, self).formfield(**defaults)
18-
19 class XMLField(TextField):
20     def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
21         self.schema_path = schema_path
22Index: django/contrib/gis/utils/layermapping.py
23===================================================================
24--- django/contrib/gis/utils/layermapping.py    (revision 8685)
25+++ django/contrib/gis/utils/layermapping.py    (working copy)
26@@ -118,6 +118,7 @@
27     OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime
28 from django.contrib.gis.models import GeometryColumns, SpatialRefSys
29 from django.db import models, transaction
30+from django.contrib.localflavor.us.models import USStateField
31 
32 # LayerMapping exceptions.
33 class LayerMapError(Exception): pass
34@@ -150,7 +151,7 @@
35         models.SlugField : OFTString,
36         models.TextField : OFTString,
37         models.URLField : OFTString,
38-        models.USStateField : OFTString,
39+        USStateField : OFTString,
40         models.XMLField : OFTString,
41         models.SmallIntegerField : (OFTInteger, OFTReal, OFTString),
42         models.PositiveSmallIntegerField : (OFTInteger, OFTReal, OFTString),
43Index: django/contrib/gis/tests/relatedapp/models.py
44===================================================================
45--- django/contrib/gis/tests/relatedapp/models.py       (revision 8685)
46+++ django/contrib/gis/tests/relatedapp/models.py       (working copy)
47@@ -1,4 +1,5 @@
48 from django.contrib.gis.db import models
49+from django.contrib.localflavor.us.models import USStateField
50 
51 class Location(models.Model):
52     name = models.CharField(max_length=50)
53@@ -7,6 +8,6 @@
54 
55 class City(models.Model):
56     name = models.CharField(max_length=50)
57-    state = models.USStateField()
58+    state = USStateField()
59     location = models.ForeignKey(Location)
60     objects = models.GeoManager()
61Index: django/contrib/localflavor/us/models.py
62===================================================================
63--- django/contrib/localflavor/us/models.py     (revision 0)
64+++ django/contrib/localflavor/us/models.py     (revision 0)
65@@ -0,0 +1,11 @@
66+from django.db.models.fields import Field
67+
68+class USStateField(Field):
69+    def get_internal_type(self):
70+        return "USStateField"
71+
72+    def formfield(self, **kwargs):
73+        from django.contrib.localflavor.us.forms import USStateSelect
74+        defaults = {'widget': USStateSelect}
75+        defaults.update(kwargs)
76+        return super(USStateField, self).formfield(**defaults)
77Index: tests/regressiontests/serializers_regress/models.py
78===================================================================
79--- tests/regressiontests/serializers_regress/models.py (revision 8685)
80+++ tests/regressiontests/serializers_regress/models.py (working copy)
81@@ -8,6 +8,7 @@
82 from django.db import models
83 from django.contrib.contenttypes import generic
84 from django.contrib.contenttypes.models import ContentType
85+from django.contrib.localflavor.us.models import USStateField
86 
87 # The following classes are for testing basic data
88 # marshalling, including NULL values.
89@@ -73,7 +74,7 @@
90     data = models.TimeField(null=True)
91 
92 class USStateData(models.Model):
93-    data = models.USStateField(null=True)
94+    data = USStateField(null=True)
95 
96 class XMLData(models.Model):
97     data = models.XMLField(null=True)
98@@ -209,7 +210,7 @@
99 #    data = models.TimeField(primary_key=True)
100 
101 class USStatePKData(models.Model):
102-    data = models.USStateField(primary_key=True)
103+    data = USStateField(primary_key=True)
104 
105 # class XMLPKData(models.Model):
106 #     data = models.XMLField(primary_key=True)
107Index: docs/topics/forms/modelforms.txt
108===================================================================
109--- docs/topics/forms/modelforms.txt    (revision 8685)
110+++ docs/topics/forms/modelforms.txt    (working copy)
111@@ -73,10 +73,6 @@
112     ``TimeField``                    ``TimeField``
113     ``URLField``                     ``URLField`` with ``verify_exists`` set
114                                      to the model field's ``verify_exists``
115-    ``USStateField``                 ``CharField`` with
116-                                     ``widget=USStateSelect``
117-                                     (``USStateSelect`` is from
118-                                     ``django.contrib.localflavor.us``)
119     ``XMLField``                     ``CharField`` with ``widget=Textarea``
120     ===============================  ========================================
121 
122Index: docs/ref/contrib/localflavor.txt
123===================================================================
124--- docs/ref/contrib/localflavor.txt    (revision 8685)
125+++ docs/ref/contrib/localflavor.txt    (working copy)
126@@ -649,3 +649,8 @@
127 
128     A form ``Select`` widget that uses a list of U.S. states/territories as its
129     choices.
130+
131+.. class:: us.models.USStateField
132+
133+    A model field that forms represent as a ``forms.USStateField`` field and
134+    stores the two-letter U.S. state abbreviation in the database.
135Index: docs/ref/models/fields.txt
136===================================================================
137--- docs/ref/models/fields.txt  (revision 8685)
138+++ docs/ref/models/fields.txt  (working copy)
139@@ -705,14 +705,6 @@
140 :attr:`~CharField.max_length`argument. If you don't specify
141 :attr:`~CharField.max_length`, a default of 200 is used.
142 
143-``USStateField``
144-----------------
145-
146-.. class:: USStateField([**options])
147-
148-A two-letter U.S. state abbreviation. The admin represents this as an ``<input
149-type="text">`` (a single-line input).
150-
151 ``XMLField``
152 ------------
153