from template.template import Template
from template.login import LoginTemplate
from template.usermenu import UsermenuTemplate
from template.errors import ErrorsTemplate
class CommonTemplate(Template):
def __init__(self):
super().__init__()
self.login = LoginTemplate()
self.usermenu = UsermenuTemplate()
self.errors = ErrorsTemplate()
def wrap(self, answer):
titles = list()
uipath = list()
for i in answer.uipath:
title = answer.e(i[0])
link = answer.request.get_urlpath_escaped(i[1])
titles.insert(0, title)
uipath.append('<a href="%s">%s</a>' % (link, title))
title = titles[0] if titles else ''
return '''
<html>
<head>
<title>%(titlechain)s</title>
<link rel="stylesheet" href="%(dataprefix)s/common.css" />
</head>
<body>
<div class="header">
<div id="logo"><a href="%(prefix)s/"><img src="%(dataprefix)s/logo.png" /></a></div>
%(usermenu)s
</div>
<div class="errors">
%(errors)s
</div>
<div class="uipath">
%(uipath)s
</div>
<div class="content">
<h1>%(title)s</h1>
%(content)s
</div>
<div class="footer">
powered by magic
</div>
</body>
</html>
''' % {
'titlechain' : ' | '.join(titles),
'uipath' : ' : '.join(uipath),
'title' : title,
'prefix' : answer.urlprefix,
'dataprefix' : answer.urldataprefix,
'usermenu' : (self.usermenu if answer.request.session else self.login).wrap(answer),
'errors' : self.errors.wrap(answer),
'content' : answer.content,
}