Ticket #494: 494.3.patch

File 494.3.patch, 4.7 KB (added by Antonis Christofides, 16 years ago)

Quick and dirty solution for brainstorming

  • django/forms/formsets.py

     
    273273        return mark_safe(u'\n'.join([unicode(self.management_form), forms]))
    274274
    275275def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
    276                     can_delete=False, max_num=0):
     276                    can_delete=False, max_num=0, classes=[]):
    277277    """Return a FormSet for the given form class."""
    278     attrs = {'form': form, 'extra': extra,
     278    attrs = {'form': form, 'extra': extra, 'classes': classes,
    279279             'can_order': can_order, 'can_delete': can_delete,
    280280             'max_num': max_num}
    281281    return type(form.__name__ + 'FormSet', (formset,), attrs)
  • django/forms/models.py

     
    418418        super(BaseModelFormSet, self).add_fields(form, index)
    419419
    420420def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
    421                          formset=BaseModelFormSet,
     421                         formset=BaseModelFormSet, classes=[],
    422422                         extra=1, can_delete=False, can_order=False,
    423423                         max_num=0, fields=None, exclude=None):
    424424    """
     
    427427    form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
    428428                             formfield_callback=formfield_callback)
    429429    FormSet = formset_factory(form, formset, extra=extra, max_num=max_num,
    430                               can_order=can_order, can_delete=can_delete)
     430                              can_order=can_order, can_delete=can_delete,
     431                              classes=classes)
    431432    FormSet.model = model
    432433    return FormSet
    433434
     
    514515
    515516def inlineformset_factory(parent_model, model, form=ModelForm,
    516517                          formset=BaseInlineFormSet, fk_name=None,
    517                           fields=None, exclude=None,
     518                          fields=None, exclude=None, classes=[],
    518519                          extra=3, can_order=False, can_delete=True, max_num=0,
    519520                          formfield_callback=lambda f: f.formfield()):
    520521    """
     
    541542        'fields': fields,
    542543        'exclude': exclude,
    543544        'max_num': max_num,
     545        'classes': classes,
    544546    }
    545547    FormSet = modelformset_factory(model, **kwargs)
    546548    FormSet.fk = fk
  • django/contrib/admin/options.py

     
    750750    template = None
    751751    verbose_name = None
    752752    verbose_name_plural = None
     753    classes = []
    753754
    754755    def __init__(self, parent_model, admin_site):
    755756        self.admin_site = admin_site
     
    790791            "formfield_callback": self.formfield_for_dbfield,
    791792            "extra": self.extra,
    792793            "max_num": self.max_num,
     794            "classes": self.classes,
    793795        }
    794796        defaults.update(kwargs)
    795797        return inlineformset_factory(self.parent_model, self.model, **defaults)
  • django/contrib/admin/templates/admin/edit_inline/stacked.html

     
    11{% load i18n %}
    22<div class="inline-group">
     3<fieldset class="module {% for class in inline_admin_formset.formset.classes %}{{class}}{% endfor %}">
    34  <h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2>
    45{{ inline_admin_formset.formset.management_form }}
    56{{ inline_admin_formset.formset.non_form_errors }}
     
    2425{#   <li><a class="add" href="">Add another {{ inline_admin_formset.opts.verbose_name|title }}</a></li> #}
    2526{# </ul> #}
    2627</div>
     28</div>
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

     
    22<div class="inline-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>
Back to Top