@@ -57,7 +57,7 @@ def __init__(self, *args, **kwargs):
5757 self .blank = not self .required
5858
5959 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 ("_" , " " )
6161
6262 def _set_verbose_name (self , val ):
6363 self ._verbose_name = val
@@ -70,23 +70,23 @@ def formfield(self, form_class=None, choices_form_class=None, **kwargs):
7070 """
7171
7272 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 ,
7676 }
7777 if self .default :
7878 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
8181 else :
82- defaults [' initial' ] = self .default
82+ defaults [" initial" ] = self .default
8383 if self .choices :
8484 # 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
8888 if self .null :
89- defaults [' empty_value' ] = None
89+ defaults [" empty_value" ] = None
9090 if choices_form_class is not None :
9191 form_class = choices_form_class
9292 else :
@@ -96,16 +96,16 @@ def formfield(self, form_class=None, choices_form_class=None, **kwargs):
9696 # the values that TypedChoiceField will understand.
9797 for k in list (kwargs ):
9898 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" ,
109109 ):
110110 del kwargs [k ]
111111 defaults .update (kwargs )
@@ -150,13 +150,13 @@ def formfield(self, form_class=forms.CharField, choices_form_class=None, **kwarg
150150 defaults = {}
151151
152152 if self .max_length and not self .choices :
153- defaults [' max_length' ] = self .max_length
153+ defaults [" max_length" ] = self .max_length
154154
155155 if self .max_length is None and not self .choices :
156- defaults [' widget' ] = forms .Textarea
156+ defaults [" widget" ] = forms .Textarea
157157
158158 if self .regex :
159- defaults [' regex' ] = self .regex
159+ defaults [" regex" ] = self .regex
160160
161161 defaults .update (kwargs )
162162 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
165165class EmailField (StringField ):
166166 def __init__ (self , * args , ** kwargs ):
167167 # 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 )
169169 super ().__init__ (* args , ** kwargs )
170170
171171 def formfield (self , ** kwargs ):
172172 defaults = {
173- ' form_class' : forms .EmailField ,
173+ " form_class" : forms .EmailField ,
174174 }
175175 defaults .update (kwargs )
176176 return super ().formfield (** defaults )
@@ -179,7 +179,7 @@ def formfield(self, **kwargs):
179179class URLField (StringField ):
180180 def formfield (self , ** kwargs ):
181181 defaults = {
182- ' form_class' : forms .URLField ,
182+ " form_class" : forms .URLField ,
183183 }
184184 defaults .update (kwargs )
185185 return super ().formfield (** defaults )
@@ -188,8 +188,8 @@ def formfield(self, **kwargs):
188188class MinMaxMixin :
189189 def formfield (self , ** kwargs ):
190190 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 ,
193193 }
194194 defaults .update (kwargs )
195195 return super ().formfield (** defaults )
@@ -198,7 +198,7 @@ def formfield(self, **kwargs):
198198class IntField (MinMaxMixin , DjangoField ):
199199 def formfield (self , ** kwargs ):
200200 defaults = {
201- ' form_class' : forms .IntegerField ,
201+ " form_class" : forms .IntegerField ,
202202 }
203203 defaults .update (kwargs )
204204 return super ().formfield (** defaults )
@@ -207,7 +207,7 @@ def formfield(self, **kwargs):
207207class FloatField (MinMaxMixin , DjangoField ):
208208 def formfield (self , ** kwargs ):
209209 defaults = {
210- ' form_class' : forms .FloatField ,
210+ " form_class" : forms .FloatField ,
211211 }
212212 defaults .update (kwargs )
213213 return super ().formfield (** defaults )
@@ -216,9 +216,9 @@ def formfield(self, **kwargs):
216216class DecimalField (MinMaxMixin , DjangoField ):
217217 def formfield (self , ** kwargs ):
218218 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 ,
222222 }
223223 defaults .update (kwargs )
224224 return super ().formfield (** defaults )
@@ -229,34 +229,34 @@ def formfield(self, **kwargs):
229229
230230class BooleanField (DjangoField ):
231231 def __init__ (self , * args , ** kwargs ):
232- kwargs [' blank' ] = True
232+ kwargs [" blank" ] = True
233233
234234 super ().__init__ (* args , ** kwargs )
235235
236236 def formfield (self , ** kwargs ):
237237 # Unlike most fields, BooleanField figures out include_blank from
238238 # self.null instead of self.blank.
239239 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 )}
242242 else :
243- defaults = {' form_class' : forms .BooleanField }
243+ defaults = {" form_class" : forms .BooleanField }
244244 defaults .update (kwargs )
245245 return super ().formfield (** defaults )
246246
247247
248248class DateTimeField (DjangoField ):
249249 def formfield (self , ** kwargs ):
250- defaults = {' form_class' : forms .DateTimeField }
250+ defaults = {" form_class" : forms .DateTimeField }
251251 defaults .update (kwargs )
252252 return super ().formfield (** defaults )
253253
254254
255255class ReferenceField (DjangoField ):
256256 def formfield (self , ** kwargs ):
257257 defaults = {
258- ' form_class' : formfields .ReferenceField ,
259- ' queryset' : self .document_type .objects ,
258+ " form_class" : formfields .ReferenceField ,
259+ " queryset" : self .document_type .objects ,
260260 }
261261 defaults .update (kwargs )
262262 return super ().formfield (** defaults )
@@ -267,14 +267,14 @@ class ListField(DjangoField):
267267 def formfield (self , ** kwargs ):
268268 if self .field .choices :
269269 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 ,
273273 }
274274 elif isinstance (self .field , fields .ReferenceField ):
275275 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
278278 }
279279 else :
280280 defaults = {}
@@ -285,25 +285,25 @@ def formfield(self, **kwargs):
285285
286286class FileField (DjangoField ):
287287 def __init__ (self , * args , ** kwargs ):
288- kwargs [' max_length' ] = kwargs .get (' max_length' , 100 )
288+ kwargs [" max_length" ] = kwargs .get (" max_length" , 100 )
289289 super ().__init__ (* args , ** kwargs )
290290
291291 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 }
293293 # If a file has been provided previously, then the form doesn't require
294294 # that a new file is provided this time.
295295 # The code to mark the form field as not required is used by
296296 # form_for_instance, but can probably be removed once form_for_instance
297297 # 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
300300 defaults .update (kwargs )
301301 return super ().formfield (** defaults )
302302
303303
304304class ImageField (FileField ):
305305 def formfield (self , ** kwargs ):
306- defaults = {' form_class' : forms .ImageField }
306+ defaults = {" form_class" : forms .ImageField }
307307 defaults .update (kwargs )
308308 return super ().formfield (** defaults )
309309
@@ -313,14 +313,14 @@ def formfield(self, **kwargs):
313313 # remove Mongo reserved words
314314 validators = [
315315 RegexValidator (
316- regex = ' ^[^$_]' ,
316+ regex = " ^[^$_]" ,
317317 message = 'Ensure the keys do not begin with : ["$","_"].' ,
318- code = ' invalid_start' ,
318+ code = " invalid_start" ,
319319 )
320320 ]
321321 defaults = {
322- ' validators' : validators ,
323- ' form_class' : formfields .DictField ,
322+ " validators" : validators ,
323+ " form_class" : formfields .DictField ,
324324 }
325325 return super ().formfield (** defaults )
326326
@@ -330,8 +330,8 @@ def formfield(self, **kwargs):
330330 from django_mongoengine .forms .documents import documentform_factory
331331
332332 defaults = {
333- ' label' : self .label ,
334- ' help_text' : self .help_text ,
333+ " label" : self .label ,
334+ " help_text" : self .help_text ,
335335 }
336336 form_class = EmbeddedDocumentField
337337 defaults .update (kwargs )
0 commit comments