Ticket #494: 494.r12835.diff

File 494.r12835.diff, 10.8 KB (added by Matthew Schinckel, 15 years ago)

A version that actually adds the classes properly. Works with r12835, and StackedInlines.

  • django/forms/formsets.py

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

     
    647647        super(BaseModelFormSet, self).add_fields(form, index)
    648648
    649649def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
    650                          formset=BaseModelFormSet,
     650                         formset=BaseModelFormSet, classes=None,
    651651                         extra=1, can_delete=False, can_order=False,
    652652                         max_num=0, fields=None, exclude=None):
    653653    """
     
    656656    form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
    657657                             formfield_callback=formfield_callback)
    658658    FormSet = formset_factory(form, formset, extra=extra, max_num=max_num,
    659                               can_order=can_order, can_delete=can_delete)
     659                              can_order=can_order, can_delete=can_delete,
     660                              classes=classes or [])
    660661    FormSet.model = model
    661662    return FormSet
    662663
     
    798799
    799800def inlineformset_factory(parent_model, model, form=ModelForm,
    800801                          formset=BaseInlineFormSet, fk_name=None,
    801                           fields=None, exclude=None,
     802                          fields=None, exclude=None, classes=None,
    802803                          extra=3, can_order=False, can_delete=True, max_num=0,
    803804                          formfield_callback=lambda f: f.formfield()):
    804805    """
     
    821822        'fields': fields,
    822823        'exclude': exclude,
    823824        'max_num': max_num,
     825        'classes': classes or [],
    824826    }
    825827    FormSet = modelformset_factory(model, **kwargs)
    826828    FormSet.fk = fk
  • django/contrib/admin/media/css/forms.css

     
    125125
    126126/* COLLAPSED FIELDSETS */
    127127
    128 fieldset.collapsed * {
     128fieldset.collapsed *, div.collapsed * {
    129129    display: none;
    130130}
    131131
    132 fieldset.collapsed h2, fieldset.collapsed {
     132fieldset.collapsed h2, fieldset.collapsed, div.collapsed h2, div.collapsed {
    133133    display: block !important;
    134134}
    135135
    136 fieldset.collapsed h2 {
     136fieldset.collapsed h2, div.collapsed h2 {
    137137    background-image: url(../img/admin/nav-bg.gif);
    138138    background-position: bottom left;
    139139    color: #999;
    140140}
    141141
    142 fieldset.collapsed .collapse-toggle {
     142.collapse-toggle {
    143143    background: transparent;
    144144    display: inline !important;
    145145}
  • django/contrib/admin/media/js/collapse.min.js

     
    1 (function(a){a(document).ready(function(){a("fieldset.collapse").each(function(c,b){if(a(b).find("div.errors").length==0){a(b).addClass("collapsed");a(b).find("h2").first().append(' (<a id="fieldsetcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")}});a("fieldset.collapse a.collapse-toggle").toggle(function(){a(this).text(gettext("Hide"));a(this).closest("fieldset").removeClass("collapsed");return false},function(){a(this).text(gettext("Show"));a(this).closest("fieldset").addClass("collapsed");
    2 return false})})})(jQuery);
     1(function(a){a(document).ready(function(){a("div.collapse").each(function(c,b){if(a(b).find("div.errors").length==0){a(b).addClass("collapsed");a(b).find("h2").first().append(' (<a id="divcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")}});a("fieldset.collapse").each(function(c,b){if(a(b).find("div.errors").length==0){a(b).addClass("collapsed");a(b).find("h2").first().append(' (<a id="fieldsetcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")}});
     2a("fieldset.collapse a.collapse-toggle").toggle(function(){a(this).text(gettext("Hide"));a(this).closest("fieldset").removeClass("collapsed");return false},function(){a(this).text(gettext("Show"));a(this).closest("fieldset").addClass("collapsed");return false});a("div.collapse a.collapse-toggle").toggle(function(){a(this).text(gettext("Hide"));a(this).closest("div").removeClass("collapsed");return false},function(){a(this).text(gettext("Show"));a(this).closest("div").addClass("collapsed");return false})})})(jQuery);
  • django/contrib/admin/media/js/collapse.js

     
    11(function($) {
    22        $(document).ready(function() {
     3            $("div.collapse").each(function(i, elem) {
     4                        // Don't hide if fields in this fieldset have errors
     5            if ( $(elem).find("div.errors").length == 0 ) {
     6                                $(elem).addClass("collapsed");
     7                                $(elem).find("h2").first().append(' (<a id="divcollapser' +
     8                                        i +'" class="collapse-toggle" href="#">' + gettext("Show") +
     9                                        '</a>)');
     10            }
     11                });
    312                // Add anchor tag for Show/Hide link
    413                $("fieldset.collapse").each(function(i, elem) {
    514                        // Don't hide if fields in this fieldset have errors
     
    1019                                        '</a>)');
    1120                        }
    1221                });
     22
     23               
    1324                // Add toggle to anchor tag
    1425                $("fieldset.collapse a.collapse-toggle").toggle(
    1526                        function() { // Show
     
    2334                                return false;
    2435                        }
    2536                );
     37                $("div.collapse a.collapse-toggle").toggle(
     38                        function() { // Show
     39                                $(this).text(gettext("Hide"));
     40                                $(this).closest("div").removeClass("collapsed");
     41                                return false;
     42                        },
     43                        function() { // Hide
     44                                $(this).text(gettext("Show"));
     45                                $(this).closest("div").addClass("collapsed");
     46                                return false;
     47                        }
     48                );
    2649        });
    2750})(jQuery);
  • django/contrib/admin/options.py

     
    11841184    verbose_name = None
    11851185    verbose_name_plural = None
    11861186    can_delete = True
     1187    classes = []
    11871188
    11881189    def __init__(self, parent_model, admin_site):
    11891190        self.admin_site = admin_site
     
    12001201        js = ['js/jquery.min.js', 'js/inlines.min.js']
    12011202        if self.prepopulated_fields:
    12021203            js.append('js/urlify.js')
     1204        if 'collapse' in self.classes:
     1205            js.append('js/collapse.min.js')
    12031206        if self.filter_vertical or self.filter_horizontal:
    12041207            js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
    12051208        return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
     
    12301233            "extra": self.extra,
    12311234            "max_num": self.max_num,
    12321235            "can_delete": self.can_delete,
     1236            "classes": self.classes,
    12331237        }
    12341238        defaults.update(kwargs)
    12351239        return inlineformset_factory(self.parent_model, self.model, **defaults)
  • django/contrib/admin/templates/admin/edit_inline/stacked.html

     
    11{% load i18n adminmedia %}
    2 <div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
     2<div class="inline-group {% for class in inline_admin_formset.formset.classes %} {{class}}{% endfor %}" id="{{ inline_admin_formset.formset.prefix }}-group">
    33  <h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2>
    44{{ inline_admin_formset.formset.management_form }}
    55{{ inline_admin_formset.formset.non_form_errors }}
  • 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