Hi Terrence,
Firstly - it sounds like you use the word "pure" here to mean that you
do not want any code on the domain objects that refer to user interface
stuff. Is that right?
Nothing stops you from doing something similar with Reahl. For example:
Let's say you have a Person without our fields/events. Then you could
create a PersonEditor like this:
class PersonEditor(object):
def __init__(self, person):
self.person = person
@property
def fields(self):
delegated_fields = FieldIndex(self.person)
delegated_fields.name = Field(label='Name', required=True)
delegated_fields.age = IntegerField(label='Age', min_value=0,
required=True)
return delegated_fields
I like the idea of putting .fields() on the actual domain objects
though, because you could re-use the single definition of, say what
Person.fields.age is from different Facade objects (like the
PersonEditor example) without repeating yourself. Remember .fields() and
.events() do not provide a user interface. They're just hooks you can
build a user interface on top of.
Anyways, there are many possibilities. Another possibility is to put
.fields() on a Widget itself. Something like:
class PersonEditForm(Form):
def __init__(self, view, person):
super(PersonEditForm, self).__init__(view, 'edit_person')
self.person = person
self.name =
person.name
self.age = person.age
self.add_child(LabelledBlockInput(TextInput(view,
self.name)))
self.add_child(LabelledBlockInput(TextInput(view, self.age)))
def save(self):
self.person.name =
self.name
self.person.age = self.age
@exposed
def fields(self, fields):
fields.name = Field(label='Name', required=True)
fields.age = IntegerField(label='Age', min_value=0, required=True)
@exposed
def events(self, events):
events.save = Event(label='Save', action=Action(self.save))
(You can also pull the delegated_fields trick here if you want to.)
There are so many possibilities. Exactly what you do is best decided on
the merits of your specific situation.
Regards
-Iwan
--
Reahl, the Python only web framework:
http://www.reahl.org