from Page import Page class SidebarPage(Page): """WebKit page template class for pages with a sidebar. SidebarPage is an abstract superclass for pages that have a sidebar (as well as a header and "content well"). Sidebars are normally used for navigation (e.g., a menu or list of links), showing small bits of info and occasionally a simple form (such as login or search). Subclasses should override cornerTitle(), writeSidebar() and writeContent() (and title() if necessary; see Page). The utility methods menuHeading() and menuItem() can be used by subclasses, typically in their implementation of writeSidebar(). WebKit itself uses this class: Examples/ExamplePage and Admin/AdminPage both inherit from it. TO DO * More consequent use style sheets; get rid of tables completely. * The header, corner and colors are not easy to customize via subclasses. """ ## StyleSheet ## _styleSheet = ''' ''' def writeStyleSheet(self): """We're using a simple internal style sheet. This way we avoid having to care about where an external style sheet should be located when this class is used in another context. """ self.writeln('' % self._styleSheet) ## Content methods ## def writeBodyParts(self): wr = self.writeln wr('') self.writeBanner() wr('') wr('') wr('
') self.writeContent() wr('
') def writeBanner(self): self.writeln('%s' % self.cornerTitle(), '%s' % self.title()) def writeSidebar(self): self.writeWebKitSidebarSections() def cornerTitle(self): return '' ## Menu ## def menuHeading(self, title): self.writeln('' % title) def menuItem(self, title, url=None, suffix=None, indentLevel=1): if suffix: suffix = ' ' + suffix else: suffix = '' if url is not None: title = '%s' % (url, title) self.writeln('
%s%s
' % (4*indentLevel, title, suffix)) ## WebKit sidebar sections ## def writeWebKitSidebarSections(self): """Write sidebar sections. This method (and consequently the methods it invokes) are provided for WebKit's example and admin pages. It writes sections such as contexts, e-mails, exits and versions. """ self.writeContextsMenu() self.writeWebwareEmailMenu() self.writeWebwareExitsMenu() self.writeVersions() def writeContextsMenu(self): self.menuHeading('Contexts') servletPath = self.request().servletPath() ctxs = self.application().contexts().keys() ctxs = filter(lambda ctx: ctx != 'default' and not '/' in ctx, ctxs) ctxs.sort() for ctx in ctxs: self.menuItem(ctx, '%s/%s/' % (servletPath, ctx)) def writeWebwareEmailMenu(self): self.menuHeading('E-mail') self.menuItem('webware-discuss', 'mailto:webware-discuss@lists.sourceforge.net') def writeWebwareExitsMenu(self): self.menuHeading('Exits') self.menuItem('Webware', 'http://www.webwareforpython.org') self.menuItem('Python', 'http://www.python.org') def writeVersions(self): app = self.application() self.menuHeading('Versions') self.menuItem('WebKit ' + app.webKitVersionString()) self.menuItem('Webware ' + app.webwareVersionString()) from sys import version self.menuItem('Python ' + version.split(' ', 1)[0]) def writeContent(self): self.writeln('Woops, someone forgot to override writeContent().')