def assemble(self): self.define_page(HTML5Page).use_layout(BasicPageLayout()) step1 = self.define_view('/firstStepOfDetour', title='Step 1', detour=True) step1.set_slot('main', A.factory_from_bookmark(step1.as_bookmark(self))) home = self.define_view('/initial', title='View a') home.set_slot('main', A.factory_from_bookmark(step1.as_bookmark(self)))
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 assemble(self, bookmark=None): self.bookmark = bookmark slot_definitions = { 'main': A.factory_from_bookmark(self.bookmark) } self.define_view('/initial', title='View a', slot_definitions=slot_definitions)
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 bookmarks_support_such_fragments(self, fixture): """Page-internal bookmarks support such bookmarkable widgets. These Bookmarks usually do not affect an URL - they just set widget states in different ways, depending on whether the client has javascript support or not. However, if a page was opened using the widget arguments on the querystring, a bookmark that would normally only have changed that argument on the hash will point to a new url on which the argument has been removed from the querystring and changed on the hash. """ internal_bookmark = Bookmark.for_widget( 'an ajax bookmark', query_arguments={'fancy_state': 2}) normal_bookmark = Bookmark('/', '', 'a normal bookmark') # You can query whether a bookmark is page_internal or not vassert(internal_bookmark.is_page_internal) vassert(not normal_bookmark.is_page_internal) # page-internal bookmarks must be added to normal ones to be useful usable_bookmark = normal_bookmark + internal_bookmark wsgi_app = fixture.new_wsgi_app( widget_factory=A.factory_from_bookmark(usable_bookmark)) # Case: when rendered without javascript browser = Browser(wsgi_app) browser.open('/') a = browser.lxml_html.xpath('//a')[0] vassert(a.attrib['href'] == '/?fancy_state=2') vassert(a.text == 'an ajax bookmark') # Case: when rendered in a browser with javascript support fixture.reahl_server.set_app(wsgi_app) fixture.driver_browser.open('/') vassert( fixture.driver_browser.is_element_present( "//a[@href='/#fancy_state=2']")) vassert(not fixture.driver_browser.is_element_present( "//a[@href='/?fancy_state=2']")) # Case: when the argument was given on the query string of the current page fixture.driver_browser.open('/?fancy_state=4') vassert( fixture.driver_browser.is_element_present( "//a[@href='/#fancy_state=2']"))
def bookmarks(self, fixture): """Bookmarks are pointers to Views. You need them, because Views are relative to a UserInterface and a Bookmark can, at run time, turn these into absolute URLs. Bookmarks also contain metadata, such as the title of the View it points to. """ user_interface = UserInterface(None, '/a_ui', {}, False, 'test_ui') view = UrlBoundView(user_interface, '/aview', 'A View title', {}) bookmark = view.as_bookmark() # What the bookmark knows vassert(bookmark.href.path == '/a_ui/aview') vassert(bookmark.description == 'A View title') vassert(bookmark.base_path == '/a_ui') vassert(bookmark.relative_path == '/aview') # How you would use a bookmark in other views (possibly in other UserInterfaces) a = A.from_bookmark(fixture.view, bookmark) vassert(str(a.href) == str(bookmark.href))
def assemble(self, bookmark=None): self.bookmark = bookmark self.define_view('/initial', title='View a').set_slot('main', A.factory_from_bookmark(self.bookmark))