Ticket #494: 494.r12351.diff

File 494.r12351.diff, 7.0 KB (added by ramusus, 5 years ago)

works with 12351 rev in development trunk (updated)

  • django/django/forms/formsets.py

     
    318318        return mark_safe(u'\n'.join([unicode(self.management_form), forms]))
    319319
    320320def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
    321                     can_delete=False, max_num=0):
     321                    can_delete=False, max_num=0, classes=[]):
    322322    """Return a FormSet for the given form class."""
    323     attrs = {'form': form, 'extra': extra,
     323    attrs = {'form': form, 'extra': extra, 'classes': classes,
    324324             'can_order': can_order, 'can_delete': can_delete,
    325325             'max_num': max_num}
    326326    return type(form.__name__ + 'FormSet', (formset,), attrs)
  • django/django/forms/models.py

     
    635635        super(BaseModelFormSet, self).add_fields(form, index)
    636636
    637637def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
    638                          formset=BaseModelFormSet,
     638                         formset=BaseModelFormSet, classes=[],
    639639                         extra=1, can_delete=False, can_order=False,
    640640                         max_num=0, fields=None, exclude=None):
    641641    """
     
    644644    form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
    645645                             formfield_callback=formfield_callback)
    646646    FormSet = formset_factory(form, formset, extra=extra, max_num=max_num,
    647                               can_order=can_order, can_delete=can_delete)
     647                              can_order=can_order, can_delete=can_delete,
     648                              classes=classes)
    648649    FormSet.model = model
    649650    return FormSet
    650651
     
    776777
    777778def inlineformset_factory(parent_model, model, form=ModelForm,
    778779                          formset=BaseInlineFormSet, fk_name=None,
    779                           fields=None, exclude=None,
     780                          fields=None, exclude=None, classes=[],
    780781                          extra=3, can_order=False, can_delete=True, max_num=0,
    781782                          formfield_callback=lambda f: f.formfield()):
    782783    """
     
    799800        'fields': fields,
    800801        'exclude': exclude,
    801802        'max_num': max_num,
     803        'classes': classes,
    802804    }
    803805    FormSet = modelformset_factory(model, **kwargs)
    804806    FormSet.fk = fk
  • django/django/contrib/admin/options.py

     
    11801180    template = None
    11811181    verbose_name = None
    11821182    verbose_name_plural = None
     1183    classes = []
    11831184
    11841185    def __init__(self, parent_model, admin_site):
    11851186        self.admin_site = admin_site
     
    11961197        js = ['js/jquery.min.js', 'js/inlines.min.js']
    11971198        if self.prepopulated_fields:
    11981199            js.append('js/urlify.js')
     1200        if 'collapse' in self.classes:
     1201            js.append('js/collapse.min.js')
    11991202        if self.filter_vertical or self.filter_horizontal:
    12001203            js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
    12011204        return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
     
    12251228            "formfield_callback": curry(self.formfield_for_dbfield, request=request),
    12261229            "extra": self.extra,
    12271230            "max_num": self.max_num,
     1231            "classes": self.classes,
    12281232        }
    12291233        defaults.update(kwargs)
    12301234        return inlineformset_factory(self.parent_model, self.model, **defaults)
  • django/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/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

     
    10771077An override to the ``verbose_name_plural`` found in the model's inner ``Meta``
    10781078class.
    10791079
     1080``classes``
     1081~~~~~~~~~~~
     1082
     1083.. versionadded:: development
     1084
     1085A list containing extra CSS classes to apply to the inline.
     1086
     1087Example::
     1088
     1089    class BookInline(admin.TabularInline):
     1090        classes = ['collapse', 'extrapretty']
     1091
     1092A useful class is ``collapse``, which will cause the inline to be initially
     1093collapsed.
     1094
    10801095Working with a model with two or more foreign keys to the same parent model
    10811096---------------------------------------------------------------------------
    10821097
Back to Top