From edf396da59d44efebe6d5d7242bda30de4b1afeb Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Tue, 10 Jun 2008 19:58:25 +0000 Subject: [PATCH] newforms-admin: Removed the leading underscore from _formset_factory. It was missed in [7605]. git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7612 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/formsets.py | 4 ++-- django/newforms/models.py | 4 ++-- tests/regressiontests/forms/formsets.py | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/django/newforms/formsets.py b/django/newforms/formsets.py index 8a76a54042..2edc673a32 100644 --- a/django/newforms/formsets.py +++ b/django/newforms/formsets.py @@ -265,8 +265,8 @@ class BaseFormSet(StrAndUnicode): forms = u' '.join([form.as_table() for form in self.forms]) return mark_safe(u'\n'.join([unicode(self.management_form), forms])) -# XXX: This API *will* change. Use at your own risk. -def _formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, can_delete=False): +def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, + can_delete=False): """Return a FormSet for the given form class.""" attrs = {'form': form, 'extra': extra, 'can_order': can_order, 'can_delete': can_delete} return type(form.__name__ + 'FormSet', (formset,), attrs) diff --git a/django/newforms/models.py b/django/newforms/models.py index 9e350d2a8b..b9baced609 100644 --- a/django/newforms/models.py +++ b/django/newforms/models.py @@ -15,7 +15,7 @@ from forms import BaseForm, get_declared_fields from fields import Field, ChoiceField, IntegerField, EMPTY_VALUES from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput from widgets import media_property -from formsets import BaseFormSet, _formset_factory, DELETION_FIELD_NAME +from formsets import BaseFormSet, formset_factory, DELETION_FIELD_NAME __all__ = ( 'ModelForm', 'BaseModelForm', 'model_to_dict', 'fields_for_model', @@ -377,7 +377,7 @@ def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.f """ form = modelform_factory(model, form=form, fields=fields, exclude=exclude, formfield_callback=formfield_callback) - FormSet = _formset_factory(form, formset, extra=extra, can_order=can_order, can_delete=can_delete) + FormSet = formset_factory(form, formset, extra=extra, can_order=can_order, can_delete=can_delete) FormSet.model = model return FormSet diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py index a0e0215660..4cccb10d09 100644 --- a/tests/regressiontests/forms/formsets.py +++ b/tests/regressiontests/forms/formsets.py @@ -3,16 +3,16 @@ tests = """ # Basic FormSet creation and usage ############################################ FormSet allows us to use multiple instance of the same form on 1 page. For now, -the best way to create a FormSet is by using the _formset_factory function. +the best way to create a FormSet is by using the formset_factory function. >>> from django.newforms import Form, CharField, IntegerField, ValidationError ->>> from django.newforms.formsets import _formset_factory, BaseFormSet +>>> from django.newforms.formsets import formset_factory, BaseFormSet >>> class Choice(Form): ... choice = CharField() ... votes = IntegerField() ->>> ChoiceFormSet = _formset_factory(Choice) +>>> ChoiceFormSet = formset_factory(Choice) A FormSet constructor takes the same arguments as Form. Let's create a FormSet for adding data. By default, it displays 1 blank form. It can display more, @@ -146,9 +146,9 @@ False # Displaying more than 1 blank form ########################################### We can also display more than 1 empty form at a time. To do so, pass a -extra argument to _formset_factory. +extra argument to formset_factory. ->>> ChoiceFormSet = _formset_factory(Choice, extra=3) +>>> ChoiceFormSet = formset_factory(Choice, extra=3) >>> formset = ChoiceFormSet(auto_id=False, prefix='choices') >>> for form in formset.forms: @@ -242,10 +242,10 @@ data. # FormSets with deletion ###################################################### We can easily add deletion ability to a FormSet with an agrument to -_formset_factory. This will add a boolean field to each form instance. When +formset_factory. This will add a boolean field to each form instance. When that boolean field is True, the form will be in formset.deleted_forms ->>> ChoiceFormSet = _formset_factory(Choice, can_delete=True) +>>> ChoiceFormSet = formset_factory(Choice, can_delete=True) >>> initial = [{'choice': u'Calexico', 'votes': 100}, {'choice': u'Fergie', 'votes': 900}] >>> formset = ChoiceFormSet(initial=initial, auto_id=False, prefix='choices') @@ -290,14 +290,14 @@ True # FormSets with ordering ###################################################### We can also add ordering ability to a FormSet with an agrument to -_formset_factory. This will add a integer field to each form instance. When +formset_factory. This will add a integer field to each form instance. When form validation succeeds, [form.cleaned_data for form in formset.forms] will have the data in the correct order specified by the ordering fields. If a number is duplicated in the set of ordering fields, for instance form 0 and form 3 are both marked as 1, then the form index used as a secondary ordering criteria. In order to put something at the front of the list, you'd need to set it's order to 0. ->>> ChoiceFormSet = _formset_factory(Choice, can_order=True) +>>> ChoiceFormSet = formset_factory(Choice, can_order=True) >>> initial = [{'choice': u'Calexico', 'votes': 100}, {'choice': u'Fergie', 'votes': 900}] >>> formset = ChoiceFormSet(initial=initial, auto_id=False, prefix='choices') @@ -371,7 +371,7 @@ True Let's try throwing ordering and deletion into the same form. ->>> ChoiceFormSet = _formset_factory(Choice, can_order=True, can_delete=True) +>>> ChoiceFormSet = formset_factory(Choice, can_order=True, can_delete=True) >>> initial = [ ... {'choice': u'Calexico', 'votes': 100},