Code

Ticket #503: required.diff

File required.diff, 6.6 KB (added by craig@…, 9 years ago)

makes CharField's maxlength and FloatField's max_digits and decimal_places positional non-defaulted arguments for the constructors

Line 
1Index: django/models/core.py
2===================================================================
3--- django/models/core.py       (revision 640)
4+++ django/models/core.py       (working copy)
5@@ -1,8 +1,8 @@
6 from django.core import meta, validators
7 
8 class Site(meta.Model):
9-    domain = meta.CharField('domain name', maxlength=100)
10-    name = meta.CharField('display name', maxlength=50)
11+    domain = meta.CharField(100, 'domain name')
12+    name = meta.CharField(50, 'display name')
13     class META:
14         db_table = 'sites'
15         ordering = ('domain',)
16@@ -16,8 +16,8 @@
17         return get_object(pk=SITE_ID)
18 
19 class Package(meta.Model):
20-    label = meta.CharField(maxlength=20, primary_key=True)
21-    name = meta.CharField(maxlength=30, unique=True)
22+    label = meta.CharField(20, primary_key=True)
23+    name = meta.CharField(30, unique=True)
24     class META:
25         db_table = 'packages'
26         ordering = ('name',)
27@@ -26,9 +26,9 @@
28         return self.name
29 
30 class ContentType(meta.Model):
31-    name = meta.CharField(maxlength=100)
32+    name = meta.CharField(100)
33     package = meta.ForeignKey(Package, db_column='package')
34-    python_module_name = meta.CharField(maxlength=50)
35+    python_module_name = meta.CharField(50)
36     class META:
37         db_table = 'content_types'
38         ordering = ('package', 'name')
39@@ -52,9 +52,9 @@
40 
41 class Redirect(meta.Model):
42     site = meta.ForeignKey(Site, radio_admin=meta.VERTICAL)
43-    old_path = meta.CharField('redirect from', maxlength=200, db_index=True,
44+    old_path = meta.CharField(200, 'redirect from', db_index=True,
45         help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'.")
46-    new_path = meta.CharField('redirect to', maxlength=200, blank=True,
47+    new_path = meta.CharField(200, 'redirect to', blank=True,
48         help_text="This can be either an absolute path (as above) or a full URL starting with 'http://'.")
49     class META:
50         db_table = 'redirects'
51@@ -69,12 +69,12 @@
52         return "%s ---> %s" % (self.old_path, self.new_path)
53 
54 class FlatFile(meta.Model):
55-    url = meta.CharField('URL', maxlength=100, validator_list=[validators.isAlphaNumericURL],
56+    url = meta.CharField(100, 'URL', validator_list=[validators.isAlphaNumericURL],
57         help_text="Example: '/about/contact/'. Make sure to have leading and trailing slashes.")
58-    title = meta.CharField(maxlength=200)
59+    title = meta.CharField(200)
60     content = meta.TextField()
61     enable_comments = meta.BooleanField()
62-    template_name = meta.CharField(maxlength=70, blank=True,
63+    template_name = meta.CharField(70, blank=True,
64         help_text="Example: 'flatfiles/contact_page'. If this isn't provided, the system will use 'flatfiles/default'.")
65     registration_required = meta.BooleanField(help_text="If this is checked, only logged-in users will be able to view the page.")
66     sites = meta.ManyToManyField(Site)
67@@ -101,7 +101,7 @@
68 import cPickle as pickle
69 
70 class Session(meta.Model):
71-    session_key = meta.CharField(maxlength=40, primary_key=True)
72+    session_key = meta.CharField(40, primary_key=True)
73     session_data = meta.TextField()
74     expire_date = meta.DateTimeField()
75     class META:
76Index: django/models/auth.py
77===================================================================
78--- django/models/auth.py       (revision 640)
79+++ django/models/auth.py       (working copy)
80@@ -2,9 +2,9 @@
81 from django.models import core
82 
83 class Permission(meta.Model):
84-    name = meta.CharField(maxlength=50)
85+    name = meta.CharField(50)
86     package = meta.ForeignKey(core.Package, db_column='package')
87-    codename = meta.CharField(maxlength=100)
88+    codename = meta.CharField(100)
89     class META:
90         unique_together = (('package', 'codename'),)
91         ordering = ('package', 'codename')
92@@ -13,7 +13,7 @@
93         return "%s | %s" % (self.package, self.name)
94 
95 class Group(meta.Model):
96-    name = meta.CharField(maxlength=80, unique=True)
97+    name = meta.CharField(80, unique=True)
98     permissions = meta.ManyToManyField(Permission, blank=True, filter_interface=meta.HORIZONTAL)
99     class META:
100         ordering = ('name',)
101@@ -25,11 +25,11 @@
102         return self.name
103 
104 class User(meta.Model):
105-    username = meta.CharField(maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric])
106-    first_name = meta.CharField(maxlength=30, blank=True)
107-    last_name = meta.CharField(maxlength=30, blank=True)
108+    username = meta.CharField(30, unique=True, validator_list=[validators.isAlphaNumeric])
109+    first_name = meta.CharField(30, blank=True)
110+    last_name = meta.CharField(30, blank=True)
111     email = meta.EmailField('e-mail address', blank=True)
112-    password_md5 = meta.CharField('password', maxlength=32, help_text="Use an MD5 hash -- not the raw password.")
113+    password_md5 = meta.CharField(32, 'password', help_text="Use an MD5 hash -- not the raw password.")
114     is_staff = meta.BooleanField('staff status', help_text="Designates whether the user can log into this admin site.")
115     is_active = meta.BooleanField('active', default=True)
116     is_superuser = meta.BooleanField('superuser status')
117@@ -182,7 +182,7 @@
118     user = meta.ForeignKey(User)
119     content_type = meta.ForeignKey(core.ContentType, blank=True, null=True) # TODO: content_type_id name?
120     object_id = meta.TextField(blank=True, null=True)
121-    object_repr = meta.CharField(maxlength=200)
122+    object_repr = meta.CharField(200)
123     action_flag = meta.PositiveSmallIntegerField()
124     change_message = meta.TextField(blank=True)
125     class META:
126Index: django/core/meta/fields.py
127===================================================================
128--- django/core/meta/fields.py  (revision 640)
129+++ django/core/meta/fields.py  (working copy)
130@@ -287,6 +287,10 @@
131         return [formfields.CheckboxField]
132 
133 class CharField(Field):
134+    def __init__(self, maxlength, *args, **kwargs):
135+        kwargs['maxlength'] = maxlength
136+        Field.__init__(self, *args, **kwargs)
137+       
138     def get_manipulator_field_objs(self):
139         return [formfields.TextField]
140 
141@@ -422,9 +426,10 @@
142 
143 class FloatField(Field):
144     empty_strings_allowed = False
145-    def __init__(self, verbose_name=None, name=None, max_digits=None, decimal_places=None, **kwargs):
146-        self.max_digits, self.decimal_places = max_digits, decimal_places
147-        Field.__init__(self, verbose_name, name, **kwargs)
148+    def __init__(self, max_digits, decimal_places, *args, **kwargs):
149+        self.max_digits = max_digits
150+        self.decimal_places = decimal_places
151+        Field.__init__(self, *args, **kwargs)
152 
153     def get_manipulator_field_objs(self):
154         return [curry(formfields.FloatField, max_digits=self.max_digits, decimal_places=self.decimal_places)]