class Image2RML(BrowserView): template = templates.Inline(''' <tal:block xmlns:tal="http://xml.zope.org/namespaces/tal" ><imageAndFlowables tal:attributes="imageName context/@@data_uri" ></imageAndFlowables ></tal:block> ''', content_type="text/xml") def __call__(self, *args, **kw): return self.template()
class ListNavigationBase(object): template = templates.Inline(""" <ul tal:attributes="class view/list_class" tal:condition="view/items"> <li tal:repeat="item view/items" tal:attributes="class item/class" tal:content="structure item/viewlet"> </li> </ul> """) list_class = None @Lazy def all_items(self): result = [] active = self.active_viewlet for viewlet in self.viewlets: html_classes = [] if viewlet.__name__ == active: html_classes.append('active') viewlet_class = getattr(viewlet, 'html_class', None) if viewlet_class: html_classes.append(viewlet_class) result.append({ 'class': ' '.join(html_classes) or None, 'viewlet': viewlet, 'content': viewlet(), }) return result @Lazy def items(self): result = [ item for item in self.all_items if item['content'] and item['content'].strip() ] return result @Lazy def active_viewlet(self): view = self.view name = queryMultiAdapter((view.context, view.request, view, self), interfaces.IActiveViewletName, name='', default=None) return name @property def active(self): name = self.active_viewlet return (name and name in self.order)
class Refine(Viewlet): template = templates.Inline(''' <div class="header" tal:condition="view/title" tal:content="view/title"> [ Filter title ] </div> <div class="body" tal:content="structure view/body_template"> [ options ] </div> ''') body_template = None render = lambda self, *a, **kw: self.template(*a, **kw) title = None
class LinkIdViewlet(LinkViewlet): template = templates.Inline(''' <tal:block define="url view/url"> <a tal:condition="url" tal:attributes="href view/url; id view/html_id" tal:content="view/title"></a> <span tal:condition="not:url" tal:attributes="id view/html_id" tal:content="view/title"></span> </tal:block> ''') @property def html_id(self): return generic_viewlet_html_id(self, 'LinkIdViewlet')
class SimpleModalLinkViewlet(LinkIdViewlet): template = templates.Inline(''' <tal:block define="url view/url"> <a tal:condition="url" href="#" tal:attributes="id view/html_id; onclick view/onclick" tal:content="view/title"></a> <span tal:condition="not:url" tal:attributes="id view/html_id" tal:content="view/title"></span> </tal:block> ''') @property def onclick(self): return "return ST.dialogs.open_modal_form('%s', '%s');" % ( self.url, self.html_id + '-container')
class HeaderNavigationManager(ListNavigationContent): template = templates.Inline(""" <ul tal:attributes="class view/list_class"> <li tal:repeat="item view/items" tal:attributes="class item/class" tal:content="structure item/viewlet"> </li> </ul> """) list_class = "navigation" @Lazy def viewlets(self): if self.cache is None: self.collect() app = ISchoolToolApplication(None) apptabs = IApplicationTabs(app) return [self[key] for key in self.order if apptabs.get(key, True)]
class ContentViewletManager(ViewletManager): template = templates.Inline(""" <tal:block repeat="viewlet view/viewlets"> <div class="content" tal:define="rendered viewlet; stripped rendered/strip|nothing" tal:condition="stripped" tal:content="structure stripped"> </div> </tal:block> """) def render(self, *args, **kw): if not self.viewlets: return '' result = ViewletManager.render(self, *args, **kw) if result is not None: return result.strip()
class TertiaryNavigationManager(ListNavigationContent): template = templates.Inline(""" <ul tal:attributes="class view/list_class" tal:condition="view/items"> <li tal:repeat="item view/items" tal:attributes="class item/class" tal:content="structure item/viewlet"> </li> </ul> """) @property def list_class(self): related_manager = queryMultiAdapter( (self.context, self.request, self.view), interfaces.IContentProvider, 'page_related') # XXX: this check of viewlets might not be safe if related_manager is not None and related_manager.viewlets: return 'third-nav third-nav-narrow' return 'third-nav'
class LinkViewlet(Viewlet): template = templates.Inline(''' <tal:block define="url view/url"> <a tal:condition="url" tal:attributes="href view/url; class view/css_class" tal:content="view/title"></a> <span tal:condition="not:url" tal:content="view/title"></span> </tal:block> ''') title = None css_class = None @property def target(self): return self.context @property def enabled(self): return bool(self.title) @property def link(self): if not self.__name__: return None return self.__name__ @property def url(self): link = self.link if not link: return None return "%s/%s" % (absoluteURL(self.target, self.request), self.link) def render(self, *args, **kw): if not self.enabled: return '' return self.template(*args, **kw)
class CustomCSSViewlet(Viewlet): render = templates.Inline(''' <link rel="stylesheet" type="text/css" href="layout.css" media="screen" tal:attributes="href context/++resource++schooltool.flourish.custom/custom.css" /> ''')