mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
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
This commit is contained in:
parent
74a74f3766
commit
0a7d8b18ff
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user