4
This module is the basis for Mantissa-based web applications. It provides
5
several basic pluggable application-level features, most notably Powerup-based
6
integration of the extensible hierarchical navigation system defined in
12
from xmantissa.webtheme import getAllThemes
13
from xmantissa.webnav import getTabs
15
def _reorderForPreference(themeList, preferredThemeName):
17
Re-order the input themeList according to the preferred theme.
22
if preferredThemeName == t.name:
28
class NavFragment(Fragment):
29
def __init__(self, docFactory, navigation):
30
Fragment.__init__(self, docFactory)
31
self.navigation = navigation
33
def data_navigation(self, ctx):
34
return self.navigation
36
def render_tab(self, ctx, data):
37
ctx.fillSlots('name', self.stuff.name)
38
ctx.fillSlots('link', self.linkTarget)
41
def render_subtabs(self, ctx, data):
42
return NavFragment(docFactory=self.docFactory, navigation=data.subtabs)
45
class NavMixin(object):
49
def __init__(self, siteconf, navigation):
50
self.siteconf = siteconf
51
self.navigation = navigation
53
def getDocFactory(self):
54
return self.siteconf.getDocFactory(self.fragmentName)
56
def render_content(self, ctx, data):
57
raise NotImplementedError("implement render_context in subclasses")
59
def render_navigation(self, ctx, data):
60
return NavFragment(self.getDocFactory('navigation'), self.navigation)
63
class PrivatePage(Page, NavMixin):
64
def __init__(self, siteConf, navigation):
65
docFactory = siteConf.getDocFactory('shell')
67
NavMixin.__init__(self, siteConf, navigation)
70
class PrivateApplication(Item):
71
# Installed on Avatar stores.
72
implements(ISiteRootPlugin)
74
typeName = 'private_web_application'
77
preferredTheme = text()
81
self.store.powerUp(self, ISiteRootPlugin)
83
def resourceFactory(self, segments):
85
if segments and segments[0] == 'private':
86
nav = getTabs(self.store.powerupsFor(INavigableElement))
87
return PrivatePage(self, nav), segments[1:]
89
def getDocFactory(self, fragmentName):
90
l = list(getAllThemes())
91
_reorderForPreference(l, self.preferredTheme)
93
fact = t.getDocFactory(fragmentName)
96
raise KeyError("No such theme element: %r in themes: %r" %