summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-12-15 05:35:19 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-12-15 05:35:19 +0000
commit0a7d8b18ff844edad75ac3b21fb89e479db4705a (patch)
treef8882f4cb6d051c65958481bac224c36d3b36296
parent74a74f3766f4209cf07bea52877d5465490cf816 (diff)
newforms: Split the Form class into BaseForm and Form. The former has all the Form logic; the latter just implements the metaclass that allows for declarative form definition. This change makes it easier to allow other (i.e., non-declarative) designation of a form's fields in creating a form class
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4204 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/newforms/forms.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index d492ebeb0f..96948264e4 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -32,10 +32,11 @@ class DeclarativeFieldsMetaclass(type):
attrs['fields'] = SortedDictFromList(fields)
return type.__new__(cls, name, bases, attrs)
-class Form(StrAndUnicode):
- "A collection of Fields, plus their associated data."
- __metaclass__ = DeclarativeFieldsMetaclass
-
+class BaseForm(StrAndUnicode):
+ # This is the main implementation of all the Form logic. Note that this
+ # class is different than Form. See the comments by the Form class for more
+ # information. Any improvements to the form API should be made to *this*
+ # class, not to the Form class.
def __init__(self, data=None, auto_id='id_%s', prefix=None):
self.ignore_errors = data is None
self.data = data or {}
@@ -168,6 +169,15 @@ class Form(StrAndUnicode):
"""
return self.clean_data
+class Form(BaseForm):
+ "A collection of Fields, plus their associated data."
+ # This is a separate class from BaseForm in order to abstract the way
+ # self.fields is specified. This class (Form) is the one that does the
+ # fancy metaclass stuff purely for the semantic sugar -- it allows one
+ # to define a form using declarative syntax.
+ # BaseForm itself has no way of designating self.fields.
+ __metaclass__ = DeclarativeFieldsMetaclass
+
class BoundField(StrAndUnicode):
"A Field plus data"
def __init__(self, form, field, name):