Ticket #494: 494.r12661.diff

File 494.r12661.diff, 6.1 KB (added by schinckel, 6 years ago)

I've updated the patch so that it doesn't use an empty list as the default argument for classes: this doesn't necessarily do what you expect it to. A second or tertiary call to the same function will use the same list, even if you have added things to it in the meantime, meaning that classes may get added to other objects that were not supposed to. At this stage, that is unlikely anyway, but it is bad form to create a function definition with an empty list as the default argument to anything. This patch works with r12661.

  • django/forms/formsets.py

     
    321321        return mark_safe(u'\n'.join([unicode(self.management_form), forms]))
    322322
    323323def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
    324                     can_delete=False, max_num=0):
     324                    can_delete=False, max_num=0, classes=None):
    325325    """Return a FormSet for the given form class."""
    326326    attrs = {'form': form, 'extra': extra,
    327327             'can_order': can_order, 'can_delete': can_delete,
    328              'max_num': max_num}
     328             'max_num': max_num, 'classes':classes or []}
    329329    return type(form.__name__ + 'FormSet', (formset,), attrs)
    330330
    331331def all_valid(formsets):
  • django/forms/models.py

     
    643643        super(BaseModelFormSet, self).add_fields(form, index)
    644644
    645645def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
    646                          formset=BaseModelFormSet,
     646                         formset=BaseModelFormSet, classes=None,
    647647                         extra=1, can_delete=False, can_order=False,
    648648                         max_num=0, fields=None, exclude=None):
    649649    """
     
    652652    form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
    653653                             formfield_callback=formfield_callback)
    654654    FormSet = formset_factory(form, formset, extra=extra, max_num=max_num,
    655                               can_order=can_order, can_delete=can_delete)
     655                              can_order=can_order, can_delete=can_delete,
     656                              classes=classes or [])
    656657    FormSet.model = model
    657658    return FormSet
    658659
     
    794795
    795796def inlineformset_factory(parent_model, model, form=ModelForm,
    796797                          formset=BaseInlineFormSet, fk_name=None,
    797                           fields=None, exclude=None,
     798                          fields=None, exclude=None, classes=None,
    798799                          extra=3, can_order=False, can_delete=True, max_num=0,
    799800                          formfield_callback=lambda f: f.formfield()):
    800801    """
     
    817818        'fields': fields,
    818819        'exclude': exclude,
    819820        'max_num': max_num,
     821        'classes': classes or [],
    820822    }
    821823    FormSet = modelformset_factory(model, **kwargs)
    822824    FormSet.fk = fk
  • django/contrib/admin/options.py

     
    11881188    verbose_name = None
    11891189    verbose_name_plural = None
    11901190    can_delete = True
     1191    classes = []
    11911192
    11921193    def __init__(self, parent_model, admin_site):
    11931194        self.admin_site = admin_site
     
    12041205        js = ['js/jquery.min.js', 'js/inlines.min.js']
    12051206        if self.prepopulated_fields:
    12061207            js.append('js/urlify.js')
     1208        if 'collapse' in self.classes:
     1209            js.append('js/collapse.min.js')
    12071210        if self.filter_vertical or self.filter_horizontal:
    12081211            js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
    12091212        return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
     
    12341237            "extra": self.extra,
    12351238            "max_num": self.max_num,
    12361239            "can_delete": self.can_delete,
     1240            "classes": self.classes,
    12371241        }
    12381242        defaults.update(kwargs)
    12391243        return inlineformset_factory(self.parent_model, self.model, **defaults)
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

     
    22<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
    33  <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
    44{{ inline_admin_formset.formset.management_form }}
    5 <fieldset class="module">
     5<fieldset class="module {% for class in inline_admin_formset.formset.classes %} {{class}}{% endfor %}">
    66   <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
    77   {{ inline_admin_formset.formset.non_form_errors }}
    88   <table>
  • django/contrib/contenttypes/generic.py

     
    335335def generic_inlineformset_factory(model, form=ModelForm,
    336336                                  formset=BaseGenericInlineFormSet,
    337337                                  ct_field="content_type", fk_field="object_id",
    338                                   fields=None, exclude=None,
     338                                  fields=None, exclude=None, classes=None,
    339339                                  extra=3, can_order=False, can_delete=True,
    340340                                  max_num=0,
    341341                                  formfield_callback=lambda f: f.formfield()):
     
    360360        exclude = [ct_field.name, fk_field.name]
    361361    FormSet = modelformset_factory(model, form=form,
    362362                                   formfield_callback=formfield_callback,
    363                                    formset=formset,
     363                                   formset=formset, classes=classes or [],
    364364                                   extra=extra, can_delete=can_delete, can_order=can_order,
    365365                                   fields=fields, exclude=exclude, max_num=max_num)
    366366    FormSet.ct_field = ct_field
     
    394394            "can_order": False,
    395395            "fields": fields,
    396396            "max_num": self.max_num,
    397             "exclude": exclude
     397            "exclude": exclude,
     398            "classes": classes,
    398399        }
    399400        return generic_inlineformset_factory(self.model, **defaults)
    400401
Back to Top