def assemble(self): home = self.define_view('/', title='Hello') home.set_page(HTML5Page.factory().use_layout( PageLayout( contents_layout=ColumnLayout('main').with_slots()))) home.set_slot('main', P.factory(text='Hello world')) home.set_slot('footer', P.factory(text='I am the footer'))
def assemble(self): self.define_page(HTML5Page).use_layout( PageLayout(contents_layout=ColumnLayout('main').with_slots())) home = self.define_view('/', title='Hello') home.set_slot('main', P.factory(text='Hello world')) home.set_slot('nonexistantslotname', P.factory(text='I am breaking'))
def assemble(self): self.define_page(MyPage) home = self.define_view('/', title='Home') home.set_slot('slot1', P.factory(text='a')) home.set_slot('slot2', P.factory(text='b')) other = self.define_view('/other', title='Other') other.set_slot('slot1', P.factory(text='other'))
def __init__(self, view): super(MyFancyWidget, self).__init__(view, css_id='sedrick') self.enable_refresh(self.query_fields.refreshing_state) self.add_child( P(self.view, text='My refreshing state is now %s' % self.refreshing_state)) self.add_child( P(self.view, text='My non-refreshing state is now %s' % self.non_refreshing_state)) fixture.widget = self
def readable_and_writable_widget(self): self.input_widget = Widget(self.view, read_check=self.allowed, write_check=self.allowed) self.input_widget.add_child(P(self.view, text='some text in a p')) self.expected_html = '<p>some text in a p</p>'
def __init__(self, view, an_object): super(MyForm, self).__init__(view, 'myform') self.an_object = an_object self.enable_refresh(on_refresh=an_object.events.choice_changed) if self.exception: self.add_child(P(self.view, text=str(self.exception))) self.change_trigger_input = TextInput(self, an_object.fields.choice, refresh_widget=self) self.add_child(Label(view, for_input=self.change_trigger_input)) self.add_child(self.change_trigger_input) self.add_child(P(self.view, text='My choice state is now %s' % an_object.choice)) self.change3_non_trigger_input = TextInput(self, an_object.fields.choice3) self.add_child(Label(view, for_input=self.change3_non_trigger_input)) self.add_child(self.change3_non_trigger_input) self.add_child(P(self.view, text='My calculated state is now %s' % an_object.calculated_state)) self.define_event_handler(an_object.events.submit) self.add_child(ButtonInput(self, an_object.events.submit))
def test_widget_layout(web_fixture): """A Layout is used to add children to the Widget in customised ways, and to customise the Widget itself upon construction.""" class MyLayout(Layout): def customise_widget(self): self.widget.append_class('class-added-by-custom-layout') def add_wrapped(self, child): wrapper = self.widget.add_child(Div(self.view)) wrapper.add_child(child) return child fixture = web_fixture widget_with_layout = Div(fixture.view) assert not widget_with_layout.has_attribute('class') assert not widget_with_layout.children widget_with_layout.use_layout(MyLayout()) assert widget_with_layout.get_attribute( 'class') == 'class-added-by-custom-layout' assert not widget_with_layout.children widget_to_add = P(fixture.view) widget_with_layout.layout.add_wrapped(widget_to_add) [wrapper] = widget_with_layout.children assert wrapper.children == [widget_to_add]
def __init__(self, view, an_object): super(MyForm, self).__init__(view, 'myform') self.use_layout(FormLayout()) self.an_object = an_object self.enable_refresh(on_refresh=an_object.events.choice_changed) if self.exception: self.layout.add_alert_for_domain_exception(self.exception) self.change_trigger_input = TextInput(self, an_object.fields.choice, refresh_widget=self) self.layout.add_input(self.change_trigger_input) self.add_child(P(self.view, text='My choice state is now %s' % an_object.choice)) self.change2_trigger_input = TextInput(self, an_object.fields.choice2, refresh_widget=self) self.layout.add_input(self.change2_trigger_input) self.add_child(P(self.view, text='My choice2 state is now %s' % an_object.choice2)) self.add_child(P(self.view, text='My calculated state is now %s' % an_object.calculated_state)) self.define_event_handler(an_object.events.submit) self.add_child(ButtonInput(self, an_object.events.submit))
def __init__(self, view): super().__init__(view) alert = self.add_child(Alert(view, _('An error occurred:'), 'danger')) alert.add_child(HTMLElement(view, 'hr')) alert.add_child(P(view, text=self.error_message)) a = alert.add_child(A(view, Url(self.error_source_href), description='Ok')) a.use_layout(ButtonLayout(style='primary'))
def not_readable_widget(self): self.input_widget = Widget(self.web_fixture.view, read_check=self.disallowed) self.input_widget.add_child( P(self.web_fixture.view, text='some text in a p')) self.expected_html = ''
def __init__(self, view, an_object): super(MyForm, self).__init__(view, 'myform') self.enable_refresh() self.change_trigger_input = fixture.create_trigger_input(self, an_object) self.add_child(Label(view, for_input=self.change_trigger_input)) self.add_child(self.change_trigger_input) self.add_child(P(self.view, text='My state is now %s' % an_object.choice))
def not_readable_but_writable_widget(self): # Think of password field, where the input's value is not readable by a human self.input_widget = Widget(self.view, read_check=self.disallowed, write_check=self.allowed) self.input_widget.add_child(P(self.view, text='some text in a p')) self.expected_html = ''
def __init__(self, view): super().__init__(view, css_id='sedrick') self.enable_refresh() self.add_child(P(self.view, text='My state is now %s' % self.fancy_state)) if self.fancy_state == 2: form = self.add_child(NestedForm(view, 'nestedform')) form.define_event_handler(self.events.submit) form.add_child(ButtonInput(form.form, self.events.submit)) fixture.widget = self
def __init__(self, view): super(CustomErrorPage, self).__init__(view) error_widget = self.body.insert_child(0, ErrorWidget(view)) error_widget.add_child(H(view, 1, text='My custom error page')) error_widget.add_child(P(view, text=error_widget.error_message)) error_widget.add_child( A(view, Url(error_widget.error_source_href), description='Ok'))
def assemble(self, ui_arg=None): if ui_arg == 'doesnotexist': raise CannotCreate() self.name = 'user_interface-%s' % ui_arg root = self.define_view('/aview', title='Simple user_interface %s' % self.name) root.set_slot('user_interface-slot', P.factory(text='in user_interface slot'))
def __init__(self, form, model_object): self.model_object = model_object super(MyNestedChangingWidget, self).__init__(form.view, css_id='nested_changing_widget') self.enable_refresh() nested_checkbox_input = CheckboxInput(form, model_object.fields.nested_trigger_field, refresh_widget=self) self.add_child(Label(self.view, for_input=nested_checkbox_input)) self.add_child(nested_checkbox_input) if self.model_object.nested_trigger_field: self.add_child(P(self.view, 'My state is now showing nested responsive content'))
def __init__(self, view): super(MyForm, self).__init__(view, 'myform') self.enable_refresh() model_object = fixture.ModelObject() checkbox_input = CheckboxInput(self, model_object.fields.trigger_field, refresh_widget=self) self.add_child(Label(self.view, for_input=checkbox_input)) self.add_child(checkbox_input) if model_object.trigger_field: self.add_child(P(self.view, 'My state is now showing outer responsive content')) self.add_child(MyNestedChangingWidget(self, model_object))
def __init__(self, view): super().__init__(view, 'myform') self.enable_refresh() self.choice = 1 self.use_layout(FormLayout()) if self.exception: self.layout.add_alert_for_domain_exception(self.exception) self.layout.add_input( SelectInput(self, self.fields.choice, refresh_widget=self)) self.define_event_handler(self.events.submit_break) self.add_child(ButtonInput(self, self.events.submit_break)) self.add_child(P(view, 'Chosen: %s' % self.choice))
def __init__(self, view, name, other_view): super(MyForm, self).__init__(view, name) if self.exception: self.add_child( P(view, ','.join(self.exception.detail_messages))) self.define_event_handler(model_object.events.an_event, target=other_view) self.add_child(ButtonInput(self, model_object.events.an_event)) text_input = self.add_child( TextInput(self, model_object.fields.field_name)) if text_input.validation_error: self.add_child(self.create_error_label(text_input))
def __init__(self, view): super().__init__(view) static_div = self.add_child(Div(view)) coactive_div = static_div.add_child(Div(view, css_id='coactive_div')) refreshing_div = self.add_child(RefreshingDiv(view, coactive_div)) text_to_show = 'original' if refreshing_div.fancy_state == 2: text_to_show = 'coactive refreshed' coactive_div.add_child(P(view, text=text_to_show)) fixture.widget = self
def __init__(self, view): super(MyForm, self).__init__(view, 'myform') self.enable_refresh() if self.exception: self.add_child(P(view, text='Exception raised')) model_object = ModelObject() checkbox_input = fixture.trigger_input_type(self, model_object.fields.trigger_field, refresh_widget=self) self.add_child(Label(view, for_input=checkbox_input)) self.add_child(checkbox_input) if model_object.trigger_field: email_input = TextInput(self, model_object.fields.email) self.add_child(Label(self.view, for_input=email_input)) self.add_child(email_input) self.define_event_handler(model_object.events.an_event) self.add_child(ButtonInput(self, model_object.events.an_event))
def __init__(self, view): super(SimplePage, self).__init__(view) self.body.add_child(P(view, text='Hello world!'))
def assemble(self): main = self.define_page(HTML5Page).use_layout( PageLayout(contents_layout=ColumnLayout('main').with_slots())) main.add_default_slot('main', P.factory(text='defaulted slot contents')) self.define_view('/', title='Hello')
def __init__(self, view): super().__init__(view) self.add_child(P(view, text='你好世界!'))
def customise_widget(self): self.widget.add_child( P(self.view, text='This widget is using Mylayout'))
def __init__(self, view): super().__init__(view, css_id='main_panel') child_widget = self.add_child(P(view, text='Child Widget')) out_of_bound_widget = view.add_out_of_bound_widget(P(view, text='Out Of Bound Widget'))
def assemble(self): self.define_page(HTML5Page).use_layout(BasicPageLayout()) home = self.define_view('/', title='Hello') home.set_slot('main', P.factory(text='Hello world')) home.set_slot('nonexistantslotname', P.factory(text='I am breaking'))
def assemble(self): home = self.define_view('/', title='Hello') home.set_page(HTML5Page.factory().use_layout(BasicPageLayout())) home.set_slot('main', P.factory(text='Hello world')) home.set_slot('footer', P.factory(text='I am the footer'))
def __init__(self, view, some_arg): super().__init__(view) self.body.add_child(P(view, text='content for %s' % some_arg))
def assemble(self, some_arg=None): if some_arg == 'doesnotexist': raise CannotCreate() self.title = 'View for: %s' % some_arg self.set_slot('main', P.factory(text='content for %s' % some_arg))