Permalink
Browse files

Adding back get_formsets to call the newly renamed get_formsets_with_…

…inlines. Ticket 20702.
  • Loading branch information...
1 parent ea7c7dc commit bb00388b8a7feb14a6d51d4d8837405b8d031346 @tim-schilling committed Aug 16, 2013
Showing with 21 additions and 8 deletions.
  1. +18 −5 django/contrib/admin/options.py
  2. +3 −3 tests/regressiontests/generic_inline_admin/tests.py
@@ -502,10 +502,23 @@ def get_changelist_formset(self, request, **kwargs):
self.get_changelist_form(request), extra=0,
fields=self.list_editable, **defaults)
- def get_formsets(self, request, obj=None):
+ def get_formsets_with_inlines(self, request, obj=None):
+ """
+ Fetches the formsets for each of the inline instances.
+ :return: Tuple (formset, inline)
+ """
for inline in self.get_inline_instances(request):
yield inline.get_formset(request, obj), inline
+ def get_formsets(self, request, obj=None):
+ """
+ Fetches the formsets for each of the inline instances.
+
+ Exists for backwards compatibility.
+ """
+ for formset, inline in self.get_formsets_with_inlines(request, obj):
+ yield formset
+
def get_paginator(self, request, queryset, per_page, orphans=0, allow_empty_first_page=True):
return self.paginator(queryset, per_page, orphans, allow_empty_first_page)
@@ -941,7 +954,7 @@ def add_view(self, request, form_url='', extra_context=None):
form_validated = False
new_object = self.model()
prefixes = {}
- for FormSet, inline in self.get_formsets(request):
+ for FormSet, inline in self.get_formsets_with_inlines(request):
prefix = FormSet.get_default_prefix()
prefixes[prefix] = prefixes.get(prefix, 0) + 1
if prefixes[prefix] != 1 or not prefix:
@@ -969,7 +982,7 @@ def add_view(self, request, form_url='', extra_context=None):
initial[k] = initial[k].split(",")
form = ModelForm(initial=initial)
prefixes = {}
- for FormSet, inline in self.get_formsets(request):
+ for FormSet, inline in self.get_formsets_with_inlines(request):
prefix = FormSet.get_default_prefix()
prefixes[prefix] = prefixes.get(prefix, 0) + 1
if prefixes[prefix] != 1 or not prefix:
@@ -1039,7 +1052,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
form_validated = False
new_object = obj
prefixes = {}
- for FormSet, inline in self.get_formsets(request, new_object):
+ for FormSet, inline in self.get_formsets_with_inlines(request, new_object):
prefix = FormSet.get_default_prefix()
prefixes[prefix] = prefixes.get(prefix, 0) + 1
if prefixes[prefix] != 1 or not prefix:
@@ -1061,7 +1074,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
else:
form = ModelForm(instance=obj)
prefixes = {}
- for FormSet, inline in self.get_formsets(request, obj):
+ for FormSet, inline in self.get_formsets_with_inlines(request, obj):
prefix = FormSet.get_default_prefix()
prefixes[prefix] = prefixes.get(prefix, 0) + 1
if prefixes[prefix] != 1 or not prefix:
@@ -274,7 +274,7 @@ class EpisodeAdmin(admin.ModelAdmin):
ma = EpisodeAdmin(Episode, self.site)
self.assertEqual(
- list(ma.get_formsets(request))[0][0]().forms[0].fields.keys(),
+ list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
['keywords', 'id', 'DELETE'])
def test_custom_form_meta_exclude(self):
@@ -304,7 +304,7 @@ class EpisodeAdmin(admin.ModelAdmin):
ma = EpisodeAdmin(Episode, self.site)
self.assertEqual(
- list(ma.get_formsets(request))[0][0]().forms[0].fields.keys(),
+ list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
['url', 'keywords', 'id', 'DELETE'])
# Then, only with `ModelForm` -----------------
@@ -320,5 +320,5 @@ class EpisodeAdmin(admin.ModelAdmin):
ma = EpisodeAdmin(Episode, self.site)
self.assertEqual(
- list(ma.get_formsets(request))[0][0]().forms[0].fields.keys(),
+ list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
['description', 'keywords', 'id', 'DELETE'])

0 comments on commit bb00388

Please sign in to comment.