23
23
class BaseFormView(XHTMLView):
24
24
"""A base form view."""
26
def filter(self, stream, ctx):
27
return stream | HTMLFormFiller(data=ctx['data'])
28
"""The FormEncode validator to use."""
29
raise NotImplementedError()
29
31
def populate_state(self, state):
32
"""Populate the state given to the FormEncode validator.
34
Subclasses can override this and set additional attributes.
32
38
def get_return_url(self, obj):
39
"""Return the URL to which the completed form should redirect.
41
By default this will redirect to the saved object.
33
43
return self.req.publisher.generate(obj)
35
45
def get_default_data(self, req):
46
"""Return a dict mapping field names to default form values.
48
For an edit form, this should return the object's existing data.
49
For a creation form, this should probably return an empty dict.
51
This must be overridden by subclasses.
36
53
raise NotImplementedError()
38
55
def save_object(self, req, data):
39
raise NotImplementedError()
43
raise NotImplementedError()
56
"""Take the validated form data and turn it into an object.
58
The object must then be returned.
60
For an edit form, this should just overwrite data on an existing
62
For a creation form, this should create a new object with the given
63
data and add it to the request's store.
65
raise NotImplementedError()
67
def filter(self, stream, ctx):
68
return stream | HTMLFormFiller(data=ctx['data'])
45
70
def populate(self, req, ctx):
46
71
if req.method == 'POST':