Fixed #8353 -- Corrected the case when adminform is not in the context when rendering {% prepopulated_fields_js %} in the admin. Thanks evan_schulz for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8421 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner 2008-08-17 05:16:16 +00:00
parent 15f8b4cde0
commit 219304019b
1 changed files with 8 additions and 7 deletions

View File

@ -8,13 +8,14 @@ def prepopulated_fields_js(context):
the prepopulated fields for both the admin form and inlines. the prepopulated fields for both the admin form and inlines.
""" """
prepopulated_fields = [] prepopulated_fields = []
if context["add"]: if context['add'] and 'adminform' in context:
prepopulated_fields.extend(context["adminform"].prepopulated_fields) prepopulated_fields.extend(context['adminform'].prepopulated_fields)
for inline_admin_formset in context['inline_admin_formsets']: if 'inline_admin_formsets' in context:
for inline_admin_form in inline_admin_formset: for inline_admin_formset in context['inline_admin_formsets']:
if inline_admin_form.original is None: for inline_admin_form in inline_admin_formset:
prepopulated_fields.extend(inline_admin_form.prepopulated_fields) if inline_admin_form.original is None:
context.update({"prepopulated_fields": prepopulated_fields}) prepopulated_fields.extend(inline_admin_form.prepopulated_fields)
context.update({'prepopulated_fields': prepopulated_fields})
return context return context
prepopulated_fields_js = register.inclusion_tag('admin/prepopulated_fields_js.html', takes_context=True)(prepopulated_fields_js) prepopulated_fields_js = register.inclusion_tag('admin/prepopulated_fields_js.html', takes_context=True)(prepopulated_fields_js)