def add_column(self, name, size=None, offsets=None, vertical_align=None, column_widget=None): """Called to add a column with given options. :param name: (See :class:`ColumnOptions`) :keyword size: (See :class:`ColumnOptions`) :keyword offsets: (See :class:`ColumnOptions`) :keyword vertical_align: (See :class:`ColumnOptions`) :keyword column_widget: If given, this Widget is added as the column instead of a Div (the default). .. versionchanged:: 4.0 Changed to create a named column with all possible options. """ column_options = ColumnOptions(name, size=size, offsets=offsets, vertical_align=vertical_align) if ResponsiveSize.wraps_for_some_device_class(self.added_column_definitions+[column_options]): self.add_clearfix(column_options) column = self.widget.add_child(column_widget or Div(self.view)) column_options.size.add_css_classes(column, prefix='col') column_options.offsets.add_css_classes(column, prefix='offset') column_options.vertical_align.add_css_classes(column) self.added_column_definitions.append(column_options) self.columns[column_options.name] = column column.append_class('column-%s' % column_options.name) if self.add_slots: column.add_child(Slot(self.view, column_options.name)) return column
def __init__(self, view): super().__init__(view) self.add_child(WidgetWithJavaScript(view, 'js1')) self.add_child(WidgetWithJavaScript(view, 'js2')) self.add_child(WidgetWithJavaScript(view, 'js1')) #intended duplicate self.add_child(Slot(view, 'reahl_footer'))
def customise_widget(self): for name, size in self.column_sizes.items(): column = self.add_column(size) self.columns[name] = column column.append_class('column-%s' % name) if self.add_slots: column.add_child(Slot(self.view, name))
def test_the_lifecycle_of_a_ui(web_fixture): """This test illustrates the steps a UserInterface goes through from being specified, to being used. It tests a couple of lower-level implementation issues (see comments).""" def current_view_is_plugged_in(page): return page.slot_contents['main_slot'].__class__ is Div @stubclass(UserInterface) class UserInterfaceStub(UserInterface): assembled = False def assemble(self, **ui_arguments): self.controller_at_assemble_time = self.controller root = self.define_view('/some/path', title='A view') root.set_slot('slotA', Div.factory()) self.assembled = True fixture = web_fixture # Phase1: specifying a user_interface and assembleing it to a site (with kwargs) parent_ui = None # parent_ui = EmptyStub(base_path='/') slot_map = {'slotA': 'main_slot'} ui_factory = UserInterfaceFactory(parent_ui, RegexPath('/', '/', {}), slot_map, UserInterfaceStub, 'test_ui') # Phase2: creating a user_interface request = Request.blank('/some/path') fixture.context.request = request user_interface = ui_factory.create('/some/path', for_bookmark=False) # - Assembly happened correctly assert user_interface.parent_ui is parent_ui assert user_interface.slot_map is slot_map assert user_interface.name is 'test_ui' assert user_interface.relative_base_path == '/' assert user_interface.controller_at_assemble_time is not None assert user_interface.controller is not None assert user_interface.assembled # - Create for_bookmark empties the relative_path user_interface = ui_factory.create('/some/path', for_bookmark=True) assert user_interface.relative_path == '' # - The relative_path is reset if not done for_bookmark # This is done in case a for_bookmark call just # happened to be done for the same UserInterface in the same request # before the "real" caal is done user_interface = ui_factory.create('/some/path', for_bookmark=False) assert user_interface.relative_path == '/some/path' # Phase5: create the page and plug the view into it page = Widget.factory().create(user_interface.current_view) page.add_child(Slot(user_interface.current_view, 'main_slot')) page.plug_in(user_interface.current_view) assert current_view_is_plugged_in(page) assert isinstance(user_interface.sub_resources, FactoryDict)
def customise_widget(self): self.document = self.widget.body.add_child(Div(self.view)) self.document.set_id('doc') if self.document_layout: self.document.use_layout(self.document_layout) self.header = self.document.add_child(Header(self.view)) self.header.add_child(Slot(self.view, 'header')) self.header.set_id('hd') if self.header_layout: self.header.use_layout(self.header_layout) self.contents = self.document.add_child(Div(self.view)) if self.contents_layout: self.contents.use_layout(self.contents_layout) self.contents.set_id('bd') self.contents.set_attribute('role', 'main') self.footer = self.document.add_child(Footer(self.view)) self.footer.add_child(Slot(self.view, 'footer')) self.footer.set_id('ft') if self.footer_layout: self.footer.use_layout(self.footer_layout)
def __init__(self, view): super().__init__(view) self.add_child(Slot(view, 'slot3')) self.add_default_slot('slot3', P.factory(text='default'))
def __init__(self, view): super().__init__(view) self.add_child(Slot(view, 'slot1')) self.add_child(Slot(view, 'slot2'))
def customise_widget(self): for slot_name in self.slots: slot_div = self.widget.body.add_child(Div(self.view)) slot_div.append_class('column-%s' % slot_name) slot_div.add_child(Slot(self.view, slot_name))
def __init__(self, view): super(MyPage, self).__init__(view) self.add_child(WidgetWithJavaScript(view, 'js1')) self.add_child(WidgetWithJavaScript(view, 'js2')) self.add_child(WidgetWithJavaScript(view, 'js1')) self.add_child(Slot(view, 'reahl_footer'))