=== modified file 'django/forms/fields.py'
|
|
|
59 | 59 | creation_counter = 0 |
60 | 60 | |
61 | 61 | def __init__(self, required=True, widget=None, label=None, initial=None, |
62 | | help_text=None, error_messages=None, show_hidden_initial=False): |
| 62 | help_text=None, error_messages=None, show_hidden_initial=False, |
| 63 | attrs=None, template=None): |
63 | 64 | # required -- Boolean that specifies whether the field is required. |
64 | 65 | # True by default. |
65 | 66 | # widget -- A Widget class, or instance of a Widget class, that should |
… |
… |
|
93 | 94 | widget.attrs.update(extra_attrs) |
94 | 95 | |
95 | 96 | self.widget = widget |
| 97 | |
| 98 | self.attrs = attrs |
| 99 | self.template = template |
96 | 100 | |
97 | 101 | # Increase the creation counter, and save our local copy. |
98 | 102 | self.creation_counter = Field.creation_counter |
=== modified file 'django/forms/forms.py'
|
|
|
114 | 114 | # class, not to the Form class. |
115 | 115 | def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, |
116 | 116 | initial=None, error_class=ErrorList, label_suffix=':', |
117 | | empty_permitted=False): |
| 117 | empty_permitted=False, attrs=None, template=None): |
118 | 118 | self.is_bound = data is not None or files is not None |
119 | 119 | self.data = data or {} |
120 | 120 | self.files = files or {} |
… |
… |
|
127 | 127 | self._is_valid = None # Stores validation state after full_clean() has been called. |
128 | 128 | self._changed_data = None |
129 | 129 | |
| 130 | self.attrs = attrs |
| 131 | self.template = template |
| 132 | |
130 | 133 | # The base_fields class attribute is the *class-wide* definition of |
131 | 134 | # fields. Because a particular *instance* of the class might want to |
132 | 135 | # alter self.fields, we create self.fields here by copying base_fields. |
… |
… |
|
417 | 420 | else: |
418 | 421 | self.label = self.field.label |
419 | 422 | self.help_text = field.help_text or '' |
| 423 | self.attrs = field.attrs |
| 424 | self.template = field.template |
420 | 425 | |
421 | 426 | def __unicode__(self): |
422 | 427 | """Renders this field as an HTML widget.""" |
=== modified file 'django/forms/formsets.py'
|
|
|
30 | 30 | A collection of instances of the same Form class. |
31 | 31 | """ |
32 | 32 | def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, |
33 | | initial=None, error_class=ErrorList): |
| 33 | initial=None, error_class=ErrorList, attrs=None, template=None, legend=None): |
34 | 34 | self.is_bound = data is not None or files is not None |
35 | 35 | self.prefix = prefix or 'form' |
36 | 36 | self.auto_id = auto_id |
… |
… |
|
62 | 62 | INITIAL_FORM_COUNT: self._initial_form_count} |
63 | 63 | self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix) |
64 | 64 | |
| 65 | self.attrs = attrs |
| 66 | self.template = template |
| 67 | self.legend = legend |
| 68 | |
65 | 69 | # construct the forms in the formset |
66 | 70 | self._construct_forms() |
67 | 71 | |
=== modified file 'django/forms/models.py'
|
|
|
223 | 223 | class BaseModelForm(BaseForm): |
224 | 224 | def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, |
225 | 225 | initial=None, error_class=ErrorList, label_suffix=':', |
226 | | empty_permitted=False, instance=None): |
| 226 | empty_permitted=False, instance=None, attrs=None, template=None): |
227 | 227 | if instance is None: |
228 | 228 | # if we didn't get an instance, instantiate a new one |
229 | 229 | self.instance = self._meta.model() |
… |
… |
|
235 | 235 | if initial is not None: |
236 | 236 | object_data.update(initial) |
237 | 237 | super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, |
238 | | error_class, label_suffix, empty_permitted) |
| 238 | error_class, label_suffix, empty_permitted, |
| 239 | attrs, template) |
239 | 240 | def clean(self): |
240 | 241 | self.validate_unique() |
241 | 242 | return self.cleaned_data |
… |
… |
|
498 | 499 | self.save_as_new = save_as_new |
499 | 500 | # is there a better way to get the object descriptor? |
500 | 501 | self.rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name() |
501 | | super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix or self.rel_name) |
| 502 | kwargs = {} |
| 503 | for name in ('attrs', 'template', 'legend'): |
| 504 | kwargs[name] = getattr(self.__class__, name, None) |
| 505 | super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix or self.rel_name, **kwargs) |
502 | 506 | |
503 | 507 | def _construct_forms(self): |
504 | 508 | if self.save_as_new: |
… |
… |
|
571 | 575 | formset=BaseInlineFormSet, fk_name=None, |
572 | 576 | fields=None, exclude=None, fieldsets=None, inlines=None, formfield_kwargs=None, |
573 | 577 | extra=3, can_order=False, can_delete=True, max_num=0, |
574 | | formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)): |
| 578 | formfield_callback=lambda f, **kwargs: f.formfield(**kwargs), |
| 579 | attrs=None, template=None, legend=None): |
575 | 580 | """ |
576 | 581 | Returns an ``InlineFormSet`` for the given kwargs. |
577 | 582 | |
… |
… |
|
603 | 608 | } |
604 | 609 | FormSet = modelformset_factory(model, **kwargs) |
605 | 610 | FormSet.fk = fk |
| 611 | FormSet.attrs = attrs |
| 612 | FormSet.template = template |
| 613 | FormSet.legend = legend |
606 | 614 | return FormSet |
607 | 615 | |
608 | 616 | |