From f0c2228709b0481eac09c860d7a4a30d3987cc19 Mon Sep 17 00:00:00 2001 From: Julien Phalip Date: Sun, 19 Feb 2012 16:42:12 +0000 Subject: [PATCH] Fixed #13068 (again) -- Corrected the admin stacked inline template to allow prepopulated fields to work (Thanks Stanislas Guerra for the report). Also fixed a regression introduced in [16953] where prepopulated fields wouldn't be recognized any more due to the additional "field-" CSS class name prefix. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17562 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../templates/admin/edit_inline/stacked.html | 10 +- .../templates/admin/edit_inline/tabular.html | 4 +- .../templates/admin/includes/fieldset.html | 2 +- .../admin/prepopulated_fields_js.html | 9 +- django/contrib/admin/tests.py | 15 ++- tests/regressiontests/admin_views/admin.py | 35 +++++- tests/regressiontests/admin_views/models.py | 22 ++++ tests/regressiontests/admin_views/tests.py | 109 +++++++++++++++++- 8 files changed, 191 insertions(+), 15 deletions(-) diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html index 3ef5976f93..08e8ca306d 100644 --- a/django/contrib/admin/templates/admin/edit_inline/stacked.html +++ b/django/contrib/admin/templates/admin/edit_inline/stacked.html @@ -27,14 +27,14 @@ var count = i + 1; $(this).html($(this).html().replace(/(#\d+)/g, "#" + count)); }); - } + }; var reinitDateTimeShortCuts = function() { // Reinitialize the calendar and clock widgets by force, yuck. if (typeof DateTimeShortcuts != "undefined") { $(".datetimeshortcuts").remove(); DateTimeShortcuts.init(); } - } + }; var updateSelectFilter = function() { // If any SelectFilter widgets were added, instantiate a new instance. if (typeof SelectFilter != "undefined"){ @@ -47,7 +47,7 @@ SelectFilter.init(value.id, namearr[namearr.length-1], true, "{% static "admin/" %}"); }); } - } + }; var initPrepopulatedFields = function(row) { row.find('.prepopulated_field').each(function() { var field = $(this); @@ -55,13 +55,13 @@ var dependency_list = input.data('dependency_list') || []; var dependencies = []; $.each(dependency_list, function(i, field_name) { - dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id')); + dependencies.push('#' + row.find('.form-row .field-' + field_name).find('input, select, textarea').attr('id')); }); if (dependencies.length) { input.prepopulate(dependencies, input.attr('maxlength')); } }); - } + }; $(rows).formset({ prefix: "{{ inline_admin_formset.formset.prefix }}", addText: "{% blocktrans with verbose_name=inline_admin_formset.opts.verbose_name|title %}Add another {{ verbose_name }}{% endblocktrans %}", diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html index 8a6578f4d3..9e215afd92 100644 --- a/django/contrib/admin/templates/admin/edit_inline/tabular.html +++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html @@ -22,7 +22,7 @@ {% if inline_admin_form.form.non_field_errors %} {{ inline_admin_form.form.non_field_errors }} {% endif %} - {% if inline_admin_form.original or inline_admin_form.show_url %}

@@ -103,7 +103,7 @@ var dependency_list = input.data('dependency_list') || []; var dependencies = []; $.each(dependency_list, function(i, field_name) { - dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id')); + dependencies.push('#' + row.find('.field-' + field_name).find('input, select, textarea').attr('id')); }); if (dependencies.length) { input.prepopulate(dependencies, input.attr('maxlength')); diff --git a/django/contrib/admin/templates/admin/includes/fieldset.html b/django/contrib/admin/templates/admin/includes/fieldset.html index 0b71d501f9..c8d08c880f 100644 --- a/django/contrib/admin/templates/admin/includes/fieldset.html +++ b/django/contrib/admin/templates/admin/includes/fieldset.html @@ -7,7 +7,7 @@

{% if line.fields|length_is:'1' %}{{ line.errors }}{% endif %} {% for field in line %} - + {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %} {% if field.is_checkbox %} {{ field.field }}{{ field.label_tag }} diff --git a/django/contrib/admin/templates/admin/prepopulated_fields_js.html b/django/contrib/admin/templates/admin/prepopulated_fields_js.html index 7300bea3d9..0ff4d27acd 100644 --- a/django/contrib/admin/templates/admin/prepopulated_fields_js.html +++ b/django/contrib/admin/templates/admin/prepopulated_fields_js.html @@ -1,7 +1,7 @@ {% load l10n %}