@@ -57,7 +57,7 @@ def __init__(self, *args, **kwargs):
57
57
self .blank = not self .required
58
58
59
59
def _get_verbose_name (self ):
60
- return self ._verbose_name or self .db_field .replace ('_' , ' ' )
60
+ return self ._verbose_name or self .db_field .replace ("_" , " " )
61
61
62
62
def _set_verbose_name (self , val ):
63
63
self ._verbose_name = val
@@ -70,23 +70,23 @@ def formfield(self, form_class=None, choices_form_class=None, **kwargs):
70
70
"""
71
71
72
72
defaults = {
73
- ' required' : self .required ,
74
- ' label' : capfirst (self .verbose_name ),
75
- ' help_text' : self .help_text ,
73
+ " required" : self .required ,
74
+ " label" : capfirst (self .verbose_name ),
75
+ " help_text" : self .help_text ,
76
76
}
77
77
if self .default :
78
78
if callable (self .default ):
79
- defaults [' initial' ] = self .default
80
- defaults [' show_hidden_initial' ] = True
79
+ defaults [" initial" ] = self .default
80
+ defaults [" show_hidden_initial" ] = True
81
81
else :
82
- defaults [' initial' ] = self .default
82
+ defaults [" initial" ] = self .default
83
83
if self .choices :
84
84
# Fields with choices get special treatment.
85
- include_blank = self .blank or not (self .default or ' initial' in kwargs )
86
- defaults [' choices' ] = self .get_choices (include_blank = include_blank )
87
- defaults [' coerce' ] = self .to_python
85
+ include_blank = self .blank or not (self .default or " initial" in kwargs )
86
+ defaults [" choices" ] = self .get_choices (include_blank = include_blank )
87
+ defaults [" coerce" ] = self .to_python
88
88
if self .null :
89
- defaults [' empty_value' ] = None
89
+ defaults [" empty_value" ] = None
90
90
if choices_form_class is not None :
91
91
form_class = choices_form_class
92
92
else :
@@ -96,16 +96,16 @@ def formfield(self, form_class=None, choices_form_class=None, **kwargs):
96
96
# the values that TypedChoiceField will understand.
97
97
for k in list (kwargs ):
98
98
if k not in (
99
- ' coerce' ,
100
- ' empty_value' ,
101
- ' choices' ,
102
- ' required' ,
103
- ' widget' ,
104
- ' label' ,
105
- ' initial' ,
106
- ' help_text' ,
107
- ' error_messages' ,
108
- ' show_hidden_initial' ,
99
+ " coerce" ,
100
+ " empty_value" ,
101
+ " choices" ,
102
+ " required" ,
103
+ " widget" ,
104
+ " label" ,
105
+ " initial" ,
106
+ " help_text" ,
107
+ " error_messages" ,
108
+ " show_hidden_initial" ,
109
109
):
110
110
del kwargs [k ]
111
111
defaults .update (kwargs )
@@ -150,13 +150,13 @@ def formfield(self, form_class=forms.CharField, choices_form_class=None, **kwarg
150
150
defaults = {}
151
151
152
152
if self .max_length and not self .choices :
153
- defaults [' max_length' ] = self .max_length
153
+ defaults [" max_length" ] = self .max_length
154
154
155
155
if self .max_length is None and not self .choices :
156
- defaults [' widget' ] = forms .Textarea
156
+ defaults [" widget" ] = forms .Textarea
157
157
158
158
if self .regex :
159
- defaults [' regex' ] = self .regex
159
+ defaults [" regex" ] = self .regex
160
160
161
161
defaults .update (kwargs )
162
162
return super ().formfield (form_class , choices_form_class , ** defaults )
@@ -165,12 +165,12 @@ def formfield(self, form_class=forms.CharField, choices_form_class=None, **kwarg
165
165
class EmailField (StringField ):
166
166
def __init__ (self , * args , ** kwargs ):
167
167
# max_length=254 to be compliant with RFCs 3696 and 5321
168
- kwargs [' max_length' ] = kwargs .get (' max_length' , 254 )
168
+ kwargs [" max_length" ] = kwargs .get (" max_length" , 254 )
169
169
super ().__init__ (* args , ** kwargs )
170
170
171
171
def formfield (self , ** kwargs ):
172
172
defaults = {
173
- ' form_class' : forms .EmailField ,
173
+ " form_class" : forms .EmailField ,
174
174
}
175
175
defaults .update (kwargs )
176
176
return super ().formfield (** defaults )
@@ -179,7 +179,7 @@ def formfield(self, **kwargs):
179
179
class URLField (StringField ):
180
180
def formfield (self , ** kwargs ):
181
181
defaults = {
182
- ' form_class' : forms .URLField ,
182
+ " form_class" : forms .URLField ,
183
183
}
184
184
defaults .update (kwargs )
185
185
return super ().formfield (** defaults )
@@ -188,8 +188,8 @@ def formfield(self, **kwargs):
188
188
class MinMaxMixin :
189
189
def formfield (self , ** kwargs ):
190
190
defaults = {
191
- ' min_value' : self .min_value ,
192
- ' max_value' : self .max_value ,
191
+ " min_value" : self .min_value ,
192
+ " max_value" : self .max_value ,
193
193
}
194
194
defaults .update (kwargs )
195
195
return super ().formfield (** defaults )
@@ -198,7 +198,7 @@ def formfield(self, **kwargs):
198
198
class IntField (MinMaxMixin , DjangoField ):
199
199
def formfield (self , ** kwargs ):
200
200
defaults = {
201
- ' form_class' : forms .IntegerField ,
201
+ " form_class" : forms .IntegerField ,
202
202
}
203
203
defaults .update (kwargs )
204
204
return super ().formfield (** defaults )
@@ -207,7 +207,7 @@ def formfield(self, **kwargs):
207
207
class FloatField (MinMaxMixin , DjangoField ):
208
208
def formfield (self , ** kwargs ):
209
209
defaults = {
210
- ' form_class' : forms .FloatField ,
210
+ " form_class" : forms .FloatField ,
211
211
}
212
212
defaults .update (kwargs )
213
213
return super ().formfield (** defaults )
@@ -216,9 +216,9 @@ def formfield(self, **kwargs):
216
216
class DecimalField (MinMaxMixin , DjangoField ):
217
217
def formfield (self , ** kwargs ):
218
218
defaults = {
219
- ' max_digits' : self .max_digits ,
220
- ' decimal_places' : self .precision ,
221
- ' form_class' : forms .DecimalField ,
219
+ " max_digits" : self .max_digits ,
220
+ " decimal_places" : self .precision ,
221
+ " form_class" : forms .DecimalField ,
222
222
}
223
223
defaults .update (kwargs )
224
224
return super ().formfield (** defaults )
@@ -229,34 +229,34 @@ def formfield(self, **kwargs):
229
229
230
230
class BooleanField (DjangoField ):
231
231
def __init__ (self , * args , ** kwargs ):
232
- kwargs [' blank' ] = True
232
+ kwargs [" blank" ] = True
233
233
234
234
super ().__init__ (* args , ** kwargs )
235
235
236
236
def formfield (self , ** kwargs ):
237
237
# Unlike most fields, BooleanField figures out include_blank from
238
238
# self.null instead of self.blank.
239
239
if self .choices :
240
- include_blank = not (self .default or ' initial' in kwargs )
241
- defaults = {' choices' : self .get_choices (include_blank = include_blank )}
240
+ include_blank = not (self .default or " initial" in kwargs )
241
+ defaults = {" choices" : self .get_choices (include_blank = include_blank )}
242
242
else :
243
- defaults = {' form_class' : forms .BooleanField }
243
+ defaults = {" form_class" : forms .BooleanField }
244
244
defaults .update (kwargs )
245
245
return super ().formfield (** defaults )
246
246
247
247
248
248
class DateTimeField (DjangoField ):
249
249
def formfield (self , ** kwargs ):
250
- defaults = {' form_class' : forms .DateTimeField }
250
+ defaults = {" form_class" : forms .DateTimeField }
251
251
defaults .update (kwargs )
252
252
return super ().formfield (** defaults )
253
253
254
254
255
255
class ReferenceField (DjangoField ):
256
256
def formfield (self , ** kwargs ):
257
257
defaults = {
258
- ' form_class' : formfields .ReferenceField ,
259
- ' queryset' : self .document_type .objects ,
258
+ " form_class" : formfields .ReferenceField ,
259
+ " queryset" : self .document_type .objects ,
260
260
}
261
261
defaults .update (kwargs )
262
262
return super ().formfield (** defaults )
@@ -267,14 +267,14 @@ class ListField(DjangoField):
267
267
def formfield (self , ** kwargs ):
268
268
if self .field .choices :
269
269
defaults = {
270
- ' choices' : self .field .choices ,
271
- ' widget' : forms .CheckboxSelectMultiple ,
272
- ' form_class' : forms .MultipleChoiceField ,
270
+ " choices" : self .field .choices ,
271
+ " widget" : forms .CheckboxSelectMultiple ,
272
+ " form_class" : forms .MultipleChoiceField ,
273
273
}
274
274
elif isinstance (self .field , fields .ReferenceField ):
275
275
defaults = {
276
- ' form_class' : formfields .DocumentMultipleChoiceField ,
277
- ' queryset' : self .field .document_type .objects , # type: ignore
276
+ " form_class" : formfields .DocumentMultipleChoiceField ,
277
+ " queryset" : self .field .document_type .objects , # type: ignore
278
278
}
279
279
else :
280
280
defaults = {}
@@ -285,25 +285,25 @@ def formfield(self, **kwargs):
285
285
286
286
class FileField (DjangoField ):
287
287
def __init__ (self , * args , ** kwargs ):
288
- kwargs [' max_length' ] = kwargs .get (' max_length' , 100 )
288
+ kwargs [" max_length" ] = kwargs .get (" max_length" , 100 )
289
289
super ().__init__ (* args , ** kwargs )
290
290
291
291
def formfield (self , ** kwargs ):
292
- defaults = {' form_class' : forms .FileField , ' max_length' : self .max_length }
292
+ defaults = {" form_class" : forms .FileField , " max_length" : self .max_length }
293
293
# If a file has been provided previously, then the form doesn't require
294
294
# that a new file is provided this time.
295
295
# The code to mark the form field as not required is used by
296
296
# form_for_instance, but can probably be removed once form_for_instance
297
297
# is gone. ModelForm uses a different method to check for an existing file.
298
- if ' initial' in kwargs :
299
- defaults [' required' ] = False
298
+ if " initial" in kwargs :
299
+ defaults [" required" ] = False
300
300
defaults .update (kwargs )
301
301
return super ().formfield (** defaults )
302
302
303
303
304
304
class ImageField (FileField ):
305
305
def formfield (self , ** kwargs ):
306
- defaults = {' form_class' : forms .ImageField }
306
+ defaults = {" form_class" : forms .ImageField }
307
307
defaults .update (kwargs )
308
308
return super ().formfield (** defaults )
309
309
@@ -313,14 +313,14 @@ def formfield(self, **kwargs):
313
313
# remove Mongo reserved words
314
314
validators = [
315
315
RegexValidator (
316
- regex = ' ^[^$_]' ,
316
+ regex = " ^[^$_]" ,
317
317
message = 'Ensure the keys do not begin with : ["$","_"].' ,
318
- code = ' invalid_start' ,
318
+ code = " invalid_start" ,
319
319
)
320
320
]
321
321
defaults = {
322
- ' validators' : validators ,
323
- ' form_class' : formfields .DictField ,
322
+ " validators" : validators ,
323
+ " form_class" : formfields .DictField ,
324
324
}
325
325
return super ().formfield (** defaults )
326
326
@@ -330,8 +330,8 @@ def formfield(self, **kwargs):
330
330
from django_mongoengine .forms .documents import documentform_factory
331
331
332
332
defaults = {
333
- ' label' : self .label ,
334
- ' help_text' : self .help_text ,
333
+ " label" : self .label ,
334
+ " help_text" : self .help_text ,
335
335
}
336
336
form_class = EmbeddedDocumentField
337
337
defaults .update (kwargs )
0 commit comments