Example #1
0
    def new_wsgi_app(self,
                     site_root=None,
                     enable_js=False,
                     config=None,
                     child_factory=None):
        """Creates a :class:`ReahlWSGIApplication` containing a :class:`UserInterface` with a single View.

        :keyword site_root: an optional supplied :class:`UserInterface` for the webapp 
        :keyword enable_js: If True, JS files will be served. The default is False, to save time.
        :keyword config: A configuration to use.
        :keyword child_factory: A Widget to include in the single-view site (only applicable if no site_root) is given.
        """
        wsgi_app_class = ReahlWSGIApplicationStub
        if enable_js:
            wsgi_app_class = ReahlWSGIApplication
        child_factory = child_factory or Widget.factory()
        config = config or self.config

        class MainUI(UserInterface):
            def assemble(self):
                self.define_page(HTML5Page).use_layout(BasicPageLayout())
                view = self.define_view('/', title='Home page')
                view.set_slot('main', child_factory)

        site_root = site_root or MainUI
        config.web.site_root = site_root
        return wsgi_app_class(config)
Example #2
0
    def new_wsgi_app(self,
                     site_root=None,
                     enable_js=False,
                     config=None,
                     view_slots=None,
                     child_factory=None):
        wsgi_app_class = ReahlWSGIApplicationStub
        if enable_js:
            wsgi_app_class = ReahlWSGIApplication
        view_slots = view_slots or {}
        child_factory = child_factory or Widget.factory()
        if 'main' not in view_slots:
            view_slots['main'] = child_factory
        config = config or self.config

        class MainUI(UserInterface):
            def assemble(self):
                self.define_page(HTML5Page).use_layout(
                    PageLayout(contents_layout=ColumnLayout(
                        *view_slots.keys()).with_slots()))
                self.define_view('/',
                                 title='Home page',
                                 slot_definitions=view_slots)

        site_root = site_root or MainUI
        config.web.site_root = site_root
        return wsgi_app_class(config)
Example #3
0
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)
Example #4
0
 def assemble(self):
     self.define_view('/a_page',
                      page=Widget.factory(),
                      view_class=BrokenView)