Ticket #494: 494.5.patch

File 494.5.patch, 7.3 KB (added by jgelens, 6 years ago)

The patch didn't apply correctly anymore to trunk. Updated with the right offsets.

  • 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

     
    443443        super(BaseModelFormSet, self).add_fields(form, index)
    444444
    445445def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
    446                          formset=BaseModelFormSet,
     446                         formset=BaseModelFormSet, classes=[],
    447447                         extra=1, can_delete=False, can_order=False,
    448448                         max_num=0, fields=None, exclude=None):
    449449    """
     
    452452    form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
    453453                             formfield_callback=formfield_callback)
    454454    FormSet = formset_factory(form, formset, extra=extra, max_num=max_num,
    455                               can_order=can_order, can_delete=can_delete)
     455                              can_order=can_order, can_delete=can_delete,
     456                              classes=classes)
    456457    FormSet.model = model
    457458    return FormSet
    458459
     
    543544
    544545def inlineformset_factory(parent_model, model, form=ModelForm,
    545546                          formset=BaseInlineFormSet, fk_name=None,
    546                           fields=None, exclude=None,
     547                          fields=None, exclude=None, classes=[],
    547548                          extra=3, can_order=False, can_delete=True, max_num=0,
    548549                          formfield_callback=lambda f: f.formfield()):
    549550    """
     
    573574        'fields': fields,
    574575        'exclude': exclude,
    575576        'max_num': max_num,
     577        'classes': classes,
    576578    }
    577579    FormSet = modelformset_factory(model, **kwargs)
    578580    FormSet.fk = fk
  • django/contrib/admin/options.py

     
    816816    template = None
    817817    verbose_name = None
    818818    verbose_name_plural = None
     819    classes = []
    819820   
    820821    def __init__(self, parent_model, admin_site):
    821822        self.admin_site = admin_site
     
    832833        js = []
    833834        if self.prepopulated_fields:
    834835            js.append('js/urlify.js')
     836        if 'collapse' in self.classes:
     837            js.append('js/admin/CollapsedFieldsets.js')
    835838        if self.filter_vertical or self.filter_horizontal:
    836839            js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
    837840        return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
     
    856859            "formfield_callback": curry(self.formfield_for_dbfield, request=request),
    857860            "extra": self.extra,
    858861            "max_num": self.max_num,
     862            "classes": self.classes,
    859863        }
    860864        defaults.update(kwargs)
    861865        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 }}
     
    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/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/contrib/contenttypes/generic.py

     
    326326def generic_inlineformset_factory(model, form=ModelForm,
    327327                                  formset=BaseGenericInlineFormSet,
    328328                                  ct_field="content_type", fk_field="object_id",
    329                                   fields=None, exclude=None,
     329                                  fields=None, exclude=None, classes=[],
    330330                                  extra=3, can_order=False, can_delete=True,
    331331                                  max_num=0,
    332332                                  formfield_callback=lambda f: f.formfield()):
     
    350350        exclude = [ct_field.name, fk_field.name]
    351351    FormSet = modelformset_factory(model, form=form,
    352352                                   formfield_callback=formfield_callback,
    353                                    formset=formset,
     353                                   formset=formset, classes=classes,
    354354                                   extra=extra, can_delete=can_delete, can_order=can_order,
    355355                                   fields=fields, exclude=exclude, max_num=max_num)
    356356    FormSet.ct_field = ct_field
  • docs/ref/contrib/admin.txt

     
    877877An override to the ``verbose_name_plural`` found in the model's inner ``Meta``
    878878class.
    879879
     880``classes``
     881~~~~~~~~~~~
     882
     883.. versionadded:: development
     884
     885A list containing extra CSS classes to apply to the inline.
     886
     887Example::
     888
     889    class BookInline(admin.TabularInline):
     890        classes = ['collapse', 'extrapretty']
     891
     892A useful class is ``collapse``, which will cause the inline to be initially
     893collapsed.
     894
    880895Working with a model with two or more foreign keys to the same parent model
    881896---------------------------------------------------------------------------
    882897
Back to Top