Simplifed formset iteration using enumerate().
This commit is contained in:
parent
2b56c56653
commit
b2717c7532
|
@ -223,8 +223,7 @@ class BaseFormSet:
|
||||||
# that have had their deletion widget set to True
|
# that have had their deletion widget set to True
|
||||||
if not hasattr(self, '_deleted_form_indexes'):
|
if not hasattr(self, '_deleted_form_indexes'):
|
||||||
self._deleted_form_indexes = []
|
self._deleted_form_indexes = []
|
||||||
for i in range(0, self.total_form_count()):
|
for i, form in enumerate(self.forms):
|
||||||
form = self.forms[i]
|
|
||||||
# if this is an extra form and hasn't changed, don't consider it
|
# if this is an extra form and hasn't changed, don't consider it
|
||||||
if i >= self.initial_form_count() and not form.has_changed():
|
if i >= self.initial_form_count() and not form.has_changed():
|
||||||
continue
|
continue
|
||||||
|
@ -246,8 +245,7 @@ class BaseFormSet:
|
||||||
# by the form data.
|
# by the form data.
|
||||||
if not hasattr(self, '_ordering'):
|
if not hasattr(self, '_ordering'):
|
||||||
self._ordering = []
|
self._ordering = []
|
||||||
for i in range(0, self.total_form_count()):
|
for i, form in enumerate(self.forms):
|
||||||
form = self.forms[i]
|
|
||||||
# if this is an extra form and hasn't changed, don't consider it
|
# if this is an extra form and hasn't changed, don't consider it
|
||||||
if i >= self.initial_form_count() and not form.has_changed():
|
if i >= self.initial_form_count() and not form.has_changed():
|
||||||
continue
|
continue
|
||||||
|
@ -313,8 +311,7 @@ class BaseFormSet:
|
||||||
forms_valid = True
|
forms_valid = True
|
||||||
# This triggers a full clean.
|
# This triggers a full clean.
|
||||||
self.errors
|
self.errors
|
||||||
for i in range(0, self.total_form_count()):
|
for form in self.forms:
|
||||||
form = self.forms[i]
|
|
||||||
if self.can_delete and self._should_delete_form(form):
|
if self.can_delete and self._should_delete_form(form):
|
||||||
# This form is going to be deleted so any of its errors
|
# This form is going to be deleted so any of its errors
|
||||||
# shouldn't cause the entire formset to be invalid.
|
# shouldn't cause the entire formset to be invalid.
|
||||||
|
@ -333,8 +330,7 @@ class BaseFormSet:
|
||||||
|
|
||||||
if not self.is_bound: # Stop further processing.
|
if not self.is_bound: # Stop further processing.
|
||||||
return
|
return
|
||||||
for i in range(0, self.total_form_count()):
|
for i, form in enumerate(self.forms):
|
||||||
form = self.forms[i]
|
|
||||||
# Empty forms are unchanged forms beyond those with initial data.
|
# Empty forms are unchanged forms beyond those with initial data.
|
||||||
if not form.has_changed() and i >= self.initial_form_count():
|
if not form.has_changed() and i >= self.initial_form_count():
|
||||||
empty_forms_count += 1
|
empty_forms_count += 1
|
||||||
|
|
|
@ -237,8 +237,7 @@ class BaseTestFormSet(BaseFormSet):
|
||||||
return
|
return
|
||||||
|
|
||||||
emails = []
|
emails = []
|
||||||
for i in range(0, self.total_form_count()):
|
for form in self.forms:
|
||||||
form = self.forms[i]
|
|
||||||
email = form.cleaned_data['email']
|
email = form.cleaned_data['email']
|
||||||
if email in emails:
|
if email in emails:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
|
|
Loading…
Reference in New Issue