User flow

Define transitions between the different Views in your application to control what the user will see after clicking a Button. Guards allow finer control.


Try it out

  • Fill in an email address and comment below and click Submit.
  • Notice the browser URL.
  • Try it again, this time without supplying a comment.

class PageFlowExampleUI(UserInterface):
    def assemble(self):
        comment = Comment()

        home = self.define_view('/', title='Page flow demo')
        home.set_slot('main', CommentForm.factory(comment))

        thanks = self.define_view('/thanks', title='Thank you!')
        thanks_text = 'Thanks for submitting your comment'
        thanks.set_slot('main', P.factory(text=thanks_text))

        none_submitted = self.define_view('/none', title='Nothing to say?')
        none_text = 'Mmm, you submitted an empty comment??'
        none_submitted.set_slot('main', P.factory(text=none_text))

        self.define_transition(, home, thanks, 
        self.define_transition(, home, none_submitted, 

class Comment(object):
    def fields(self, fields):
        fields.email_address = EmailField(label='Email address', required=True)
        fields.text = Field(label='Comment')

    def events(self, events):
        events.submit = Event(label='Submit', action=Action(self.submit))

    def submit(self):
        print('%s submitted a comment:' % self.email_address)

    def contains_text(self):
        return self.text and self.text.strip() != ''

class CommentForm(Form):
    def __init__(self, view, comment):
        super(CommentForm, self).__init__(view, 'myform')

        self.layout.add_input(TextInput(self, comment.fields.email_address))
        self.layout.add_input(TextInput(self, comment.fields.text))