Django

Code

Changeset 4204

Show
Ignore:
Timestamp:
12/14/06 23:35:19 (2 years ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/forms.py

    r4199 r4204  
    3333        return type.__new__(cls, name, bases, attrs) 
    3434 
    35 class Form(StrAndUnicode): 
    36     "A collection of Fields, plus their associated data." 
    37     __metaclass__ = DeclarativeFieldsMetaclass 
    38  
     35class BaseForm(StrAndUnicode): 
     36    # This is the main implementation of all the Form logic. Note that this 
     37    # class is different than Form. See the comments by the Form class for more 
     38    # information. Any improvements to the form API should be made to *this* 
     39    # class, not to the Form class. 
    3940    def __init__(self, data=None, auto_id='id_%s', prefix=None): 
    4041        self.ignore_errors = data is None 
     
    169170        return self.clean_data 
    170171 
     172class Form(BaseForm): 
     173    "A collection of Fields, plus their associated data." 
     174    # This is a separate class from BaseForm in order to abstract the way 
     175    # self.fields is specified. This class (Form) is the one that does the 
     176    # fancy metaclass stuff purely for the semantic sugar -- it allows one 
     177    # to define a form using declarative syntax. 
     178    # BaseForm itself has no way of designating self.fields. 
     179    __metaclass__ = DeclarativeFieldsMetaclass 
     180 
    171181class BoundField(StrAndUnicode): 
    172182    "A Field plus data"