Ticket #494: 494.7.patch

File 494.7.patch, 8.8 KB (added by ramusus, 15 years ago)

2 differences from 494.6.path described below

  • django/django/forms/formsets.py

     
    302302        return mark_safe(u'\n'.join([unicode(self.management_form), forms]))
    303303
    304304def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
    305                     can_delete=False, max_num=0):
     305                    can_delete=False, max_num=0, classes=[]):
    306306    """Return a FormSet for the given form class."""
    307     attrs = {'form': form, 'extra': extra,
     307    attrs = {'form': form, 'extra': extra, 'classes': classes,
    308308             'can_order': can_order, 'can_delete': can_delete,
    309309             'max_num': max_num}
    310310    return type(form.__name__ + 'FormSet', (formset,), attrs)
  • django/django/forms/models.py

     
    675675        super(BaseModelFormSet, self).add_fields(form, index)
    676676
    677677def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
    678                          formset=BaseModelFormSet,
     678                         formset=BaseModelFormSet, classes=[],
    679679                         extra=1, can_delete=False, can_order=False,
    680680                         max_num=0, fields=None, exclude=None):
    681681    """
     
    684684    form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
    685685                             formfield_callback=formfield_callback)
    686686    FormSet = formset_factory(form, formset, extra=extra, max_num=max_num,
    687                               can_order=can_order, can_delete=can_delete)
     687                              can_order=can_order, can_delete=can_delete,
     688                              classes=classes)
    688689    FormSet.model = model
    689690    return FormSet
    690691
     
    811812
    812813def inlineformset_factory(parent_model, model, form=ModelForm,
    813814                          formset=BaseInlineFormSet, fk_name=None,
    814                           fields=None, exclude=None,
     815                          fields=None, exclude=None, classes=[],
    815816                          extra=3, can_order=False, can_delete=True, max_num=0,
    816817                          formfield_callback=lambda f: f.formfield()):
    817818    """
     
    834835        'fields': fields,
    835836        'exclude': exclude,
    836837        'max_num': max_num,
     838        'classes': classes,
    837839    }
    838840    FormSet = modelformset_factory(model, **kwargs)
    839841    FormSet.fk = fk
  • django/django/contrib/admin/media/js/admin/CollapsedFieldsets.js

     
    1111}
    1212
    1313var CollapsedFieldsets = {
    14     collapse_re: /\bcollapse\b/,   // Class of fieldsets that should be dealt with.
    15     collapsed_re: /\bcollapsed\b/, // Class that fieldsets get when they're hidden.
     14    collapse_re: /\bcollapse\b/g,   // Class of fieldsets that should be dealt with.
     15    collapsed_re: /\bcollapsed\b/g, // Class that fieldsets get when they're hidden.
    1616    collapsed_class: 'collapsed',
    1717    init: function() {
    1818        var fieldsets = document.getElementsByTagName('fieldset');
  • django/django/contrib/admin/options.py

     
    11091109    template = None
    11101110    verbose_name = None
    11111111    verbose_name_plural = None
     1112    classes = []
    11121113
    11131114    def __init__(self, parent_model, admin_site):
    11141115        self.admin_site = admin_site
     
    11251126        js = []
    11261127        if self.prepopulated_fields:
    11271128            js.append('js/urlify.js')
     1129        if 'collapse' in self.classes:
     1130            js.append('js/admin/CollapsedFieldsets.js')
    11281131        if self.filter_vertical or self.filter_horizontal:
    11291132            js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
    11301133        return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
     
    11511154            "formfield_callback": curry(self.formfield_for_dbfield, request=request),
    11521155            "extra": self.extra,
    11531156            "max_num": self.max_num,
     1157            "classes": self.classes,
    11541158        }
    11551159        defaults.update(kwargs)
    11561160        return inlineformset_factory(self.parent_model, self.model, **defaults)
  • django/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 }}
     
    2526{# <ul class="tools"> #}
    2627{#   <li><a class="add" href="">Add another {{ inline_admin_formset.opts.verbose_name|title }}</a></li> #}
    2728{# </ul> #}
     29</fieldset>
    2830</div>
  • django/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>
  • django/django/contrib/contenttypes/generic.py

     
    337337def generic_inlineformset_factory(model, form=ModelForm,
    338338                                  formset=BaseGenericInlineFormSet,
    339339                                  ct_field="content_type", fk_field="object_id",
    340                                   fields=None, exclude=None,
     340                                  fields=None, exclude=None, classes=[],
    341341                                  extra=3, can_order=False, can_delete=True,
    342342                                  max_num=0,
    343343                                  formfield_callback=lambda f: f.formfield()):
     
    362362        exclude = [ct_field.name, fk_field.name]
    363363    FormSet = modelformset_factory(model, form=form,
    364364                                   formfield_callback=formfield_callback,
    365                                    formset=formset,
     365                                   formset=formset, classes=classes,
    366366                                   extra=extra, can_delete=can_delete, can_order=can_order,
    367367                                   fields=fields, exclude=exclude, max_num=max_num)
    368368    FormSet.ct_field = ct_field
     
    390390            "can_order": False,
    391391            "fields": fields,
    392392            "max_num": self.max_num,
    393             "exclude": self.exclude
     393            "exclude": self.exclude,
     394            "classes": self.classes,
    394395        }
    395396        return generic_inlineformset_factory(self.model, **defaults)
    396397
  • django/docs/ref/contrib/admin/index.txt

     
    915915An override to the ``verbose_name_plural`` found in the model's inner ``Meta``
    916916class.
    917917
     918``classes``
     919~~~~~~~~~~~
     920
     921.. versionadded:: development
     922
     923A list containing extra CSS classes to apply to the inline.
     924
     925Example::
     926
     927    class BookInline(admin.TabularInline):
     928        classes = ['collapse', 'extrapretty']
     929
     930A useful class is ``collapse``, which will cause the inline to be initially
     931collapsed.
     932
    918933Working with a model with two or more foreign keys to the same parent model
    919934---------------------------------------------------------------------------
Back to Top