~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/base/forms.py

  • Committer: William Grant
  • Date: 2010-02-12 03:27:30 UTC
  • Revision ID: grantw@unimelb.edu.au-20100212032730-6bs564337ob5d16m
Document BaseFormView.

Show diffs side-by-side

added added

removed removed

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