On 9/12/06, Jacob Kaplan-Moss <[EMAIL PROTECTED]> wrote: > Out of curiosity, did you consider having a single ``Form`` object > that may be bound or unbound? It seems like most of ``BoundForm`` > simply delegates down to the enclosed ``Form``, so perhaps ``Form.bind > ()`` should store the data internally and just behave differently > once bound?
If we have a single Form object that may be bound or unbound, what is the "more correct" behavior of bind()? Namely, should any data passed to those functions *overwrite* any existing bound data, or should it raise an exception? Solution One: class Form(object): def __init__(self): self._data = None def bind(self, kwargs): self._data = kwargs # Overwrite regardless of whether already bound. Solution Two: class Form(object): def __init__(self): self._data = None def bind(self, kwargs): if self._data is not None: raise Exception('This form is already bound.') self._data = kwargs Solution Three: class Form(object): def __init__(self): self._data = {} def bind(self, kwargs): self._data.update(kwargs) I can see arguments for any of these, although I think my preference is for Solution Two. (Actually I must admit my *true* preference is for separate Form and BoundForm classes, so we avoid this issue entirely.) Similarly, how would is_valid() and errors() work? If is_valid() or errors() get passed kwargs, does the form instance automatically become a BoundForm? What if it's already been bound? Do the kwargs replace any existing bound data? Adrian -- Adrian Holovaty holovaty.com | djangoproject.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---