def bookmarks_overrides(self, fixture): """Various bits of information can be overridden from the defaults when creating a bookmark from a View. """ user_interface = UserInterface(None, '/a_ui', {}, False, 'test_ui') view = UrlBoundView(user_interface, '/aview', 'A View title', {}) bookmark = view.as_bookmark(description='different description', query_arguments={'arg1': 'val1'}, locale='af') # What the bookmark knows vassert(bookmark.description == 'different description') vassert(bookmark.query_arguments == {'arg1': 'val1'}) vassert(bookmark.locale == 'af')
def create_view(self, relative_path, user_interface, file_path=None): if not user_interface is self: raise ProgrammerError('get_file called on %s with %s as user_interface' % (self, user_interface)) file_url_path = file_path filename = self.filesystem_path(file_url_path) logging.debug('Finding a static file on filesystem %s' % filename) if self.is_dynamic(filename): statics = self.statics(file_url_path) view = UrlBoundView(user_interface, file_url_path, statics['title'], cacheable=True) view.set_slot('main_slot', DJHTMLWidget.factory(statics['div'])) return view elif self.is_static(filename): return FileView(user_interface, FileOnDisk(filename, file_url_path)) raise CannotCreate()
def new_view(self, user_interface=None, relative_path='/', title='A view', slot_definitions={}): user_interface = user_interface or self.user_interface return UrlBoundView(user_interface, relative_path, title, slot_definitions)
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 new_view(self): """An :class:`UrlBoundView` to use when constructing :class:`Widget`\s for testing.""" current_path = Url(ExecutionContext.get_context().request.url).path view = UrlBoundView(self.user_interface, current_path, 'A view') return view
def new_view(self): current_path = Url(WebExecutionContext.get_context().request.url).path view = UrlBoundView(self.user_interface, current_path, 'A view', {}) return view