Ticket #494: 494.r12835.diff
File 494.r12835.diff, 10.8 KB (added by , 15 years ago) |
---|
-
django/forms/formsets.py
324 324 return mark_safe(u'\n'.join([unicode(self.management_form), forms])) 325 325 326 326 def 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): 328 328 """Return a FormSet for the given form class.""" 329 329 attrs = {'form': form, 'extra': extra, 330 330 'can_order': can_order, 'can_delete': can_delete, 331 'max_num': max_num }331 'max_num': max_num, 'classes':classes or []} 332 332 return type(form.__name__ + 'FormSet', (formset,), attrs) 333 333 334 334 def all_valid(formsets): -
django/forms/models.py
647 647 super(BaseModelFormSet, self).add_fields(form, index) 648 648 649 649 def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(), 650 formset=BaseModelFormSet, 650 formset=BaseModelFormSet, classes=None, 651 651 extra=1, can_delete=False, can_order=False, 652 652 max_num=0, fields=None, exclude=None): 653 653 """ … … 656 656 form = modelform_factory(model, form=form, fields=fields, exclude=exclude, 657 657 formfield_callback=formfield_callback) 658 658 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 []) 660 661 FormSet.model = model 661 662 return FormSet 662 663 … … 798 799 799 800 def inlineformset_factory(parent_model, model, form=ModelForm, 800 801 formset=BaseInlineFormSet, fk_name=None, 801 fields=None, exclude=None, 802 fields=None, exclude=None, classes=None, 802 803 extra=3, can_order=False, can_delete=True, max_num=0, 803 804 formfield_callback=lambda f: f.formfield()): 804 805 """ … … 821 822 'fields': fields, 822 823 'exclude': exclude, 823 824 'max_num': max_num, 825 'classes': classes or [], 824 826 } 825 827 FormSet = modelformset_factory(model, **kwargs) 826 828 FormSet.fk = fk -
django/contrib/admin/media/css/forms.css
125 125 126 126 /* COLLAPSED FIELDSETS */ 127 127 128 fieldset.collapsed * {128 fieldset.collapsed *, div.collapsed * { 129 129 display: none; 130 130 } 131 131 132 fieldset.collapsed h2, fieldset.collapsed {132 fieldset.collapsed h2, fieldset.collapsed, div.collapsed h2, div.collapsed { 133 133 display: block !important; 134 134 } 135 135 136 fieldset.collapsed h2 {136 fieldset.collapsed h2, div.collapsed h2 { 137 137 background-image: url(../img/admin/nav-bg.gif); 138 138 background-position: bottom left; 139 139 color: #999; 140 140 } 141 141 142 fieldset.collapsed.collapse-toggle {142 .collapse-toggle { 143 143 background: transparent; 144 144 display: inline !important; 145 145 } -
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>)")}}); 2 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");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
1 1 (function($) { 2 2 $(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 }); 3 12 // Add anchor tag for Show/Hide link 4 13 $("fieldset.collapse").each(function(i, elem) { 5 14 // Don't hide if fields in this fieldset have errors … … 10 19 '</a>)'); 11 20 } 12 21 }); 22 23 13 24 // Add toggle to anchor tag 14 25 $("fieldset.collapse a.collapse-toggle").toggle( 15 26 function() { // Show … … 23 34 return false; 24 35 } 25 36 ); 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 ); 26 49 }); 27 50 })(jQuery); -
django/contrib/admin/options.py
1184 1184 verbose_name = None 1185 1185 verbose_name_plural = None 1186 1186 can_delete = True 1187 classes = [] 1187 1188 1188 1189 def __init__(self, parent_model, admin_site): 1189 1190 self.admin_site = admin_site … … 1200 1201 js = ['js/jquery.min.js', 'js/inlines.min.js'] 1201 1202 if self.prepopulated_fields: 1202 1203 js.append('js/urlify.js') 1204 if 'collapse' in self.classes: 1205 js.append('js/collapse.min.js') 1203 1206 if self.filter_vertical or self.filter_horizontal: 1204 1207 js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js']) 1205 1208 return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js]) … … 1230 1233 "extra": self.extra, 1231 1234 "max_num": self.max_num, 1232 1235 "can_delete": self.can_delete, 1236 "classes": self.classes, 1233 1237 } 1234 1238 defaults.update(kwargs) 1235 1239 return inlineformset_factory(self.parent_model, self.model, **defaults) -
django/contrib/admin/templates/admin/edit_inline/stacked.html
1 1 {% 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"> 3 3 <h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2> 4 4 {{ inline_admin_formset.formset.management_form }} 5 5 {{ inline_admin_formset.formset.non_form_errors }} -
django/contrib/admin/templates/admin/edit_inline/tabular.html
2 2 <div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group"> 3 3 <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}"> 4 4 {{ inline_admin_formset.formset.management_form }} 5 <fieldset class="module ">5 <fieldset class="module {% for class in inline_admin_formset.formset.classes %} {{class}}{% endfor %}"> 6 6 <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2> 7 7 {{ inline_admin_formset.formset.non_form_errors }} 8 8 <table> -
django/contrib/contenttypes/generic.py
335 335 def generic_inlineformset_factory(model, form=ModelForm, 336 336 formset=BaseGenericInlineFormSet, 337 337 ct_field="content_type", fk_field="object_id", 338 fields=None, exclude=None, 338 fields=None, exclude=None, classes=None, 339 339 extra=3, can_order=False, can_delete=True, 340 340 max_num=0, 341 341 formfield_callback=lambda f: f.formfield()): … … 360 360 exclude = [ct_field.name, fk_field.name] 361 361 FormSet = modelformset_factory(model, form=form, 362 362 formfield_callback=formfield_callback, 363 formset=formset, 363 formset=formset, classes=classes or [], 364 364 extra=extra, can_delete=can_delete, can_order=can_order, 365 365 fields=fields, exclude=exclude, max_num=max_num) 366 366 FormSet.ct_field = ct_field … … 394 394 "can_order": False, 395 395 "fields": fields, 396 396 "max_num": self.max_num, 397 "exclude": exclude 397 "exclude": exclude, 398 "classes": classes, 398 399 } 399 400 return generic_inlineformset_factory(self.model, **defaults) 400 401