author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 27 May 2009 11:26:15 +0200 | |
branch | stable |
changeset 1955 | 6539ce84f043 |
parent 1851 | c707419980f8 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
"""default templates for CubicWeb web client |
|
3 |
||
4 |
:organization: Logilab |
|
580 | 5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 |
""" |
|
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from logilab.mtconverter import html_escape |
|
11 |
||
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
12 |
from cubicweb.vregistry import objectify_selector |
822 | 13 |
from cubicweb.selectors import match_kwargs |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
14 |
from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW, STRICT_DOCTYPE |
811 | 15 |
from cubicweb.utils import make_uid, UStringIO |
0 | 16 |
|
17 |
# main templates ############################################################## |
|
18 |
||
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
19 |
class LogInOutTemplate(MainTemplate): |
0 | 20 |
|
21 |
def call(self): |
|
22 |
self.set_request_content_type() |
|
23 |
w = self.w |
|
24 |
self.write_doctype() |
|
25 |
self.template_header('text/html', self.req._('login_action')) |
|
26 |
w(u'<body>\n') |
|
27 |
self.content(w) |
|
28 |
w(u'</body>') |
|
29 |
||
30 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
31 |
w = self.whead |
|
32 |
# explictly close the <base> tag to avoid IE 6 bugs while browsing DOM |
|
33 |
w(u'<base href="%s"></base>' % html_escape(self.req.base_url())) |
|
34 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
35 |
% (content_type, self.req.encoding)) |
|
36 |
w(NOINDEX) |
|
37 |
w(NOFOLLOW) |
|
38 |
w(u'\n'.join(additional_headers) + u'\n') |
|
819 | 39 |
self.wview('htmlheader', rset=self.rset) |
0 | 40 |
w(u'<title>%s</title>\n' % html_escape(page_title)) |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
41 |
|
0 | 42 |
|
43 |
class LogInTemplate(LogInOutTemplate): |
|
44 |
id = 'login' |
|
45 |
title = 'log in' |
|
46 |
||
47 |
def content(self, w): |
|
819 | 48 |
self.wview('logform', rset=self.rset, id='loginBox', klass='') |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
49 |
|
0 | 50 |
|
51 |
class LoggedOutTemplate(LogInOutTemplate): |
|
52 |
id = 'loggedout' |
|
53 |
title = 'logged out' |
|
54 |
||
55 |
def content(self, w): |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
432
diff
changeset
|
56 |
# FIXME Deprecated code ? |
0 | 57 |
msg = self.req._('you have been logged out') |
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
432
diff
changeset
|
58 |
w(u'<h2>%s</h2>\n' % msg) |
0 | 59 |
if self.config['anonymous-user']: |
60 |
indexurl = self.build_url('view', vid='index', __message=msg) |
|
61 |
w(u'<p><a href="%s">%s</a><p>' % ( |
|
62 |
html_escape(indexurl), |
|
63 |
self.req._('go back to the index page'))) |
|
64 |
||
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
65 |
@objectify_selector |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
66 |
def templatable_view(cls, req, rset, *args, **kwargs): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
67 |
view = kwargs.pop('view', None) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
68 |
if view is None: |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
69 |
return 1 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
70 |
if view.binary: |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
71 |
return 0 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
72 |
if req.form.has_key('__notemplate'): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
73 |
return 0 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
74 |
return view.templatable |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
75 |
|
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
76 |
|
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
77 |
class NonTemplatableViewTemplate(MainTemplate): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
78 |
"""main template for any non templatable views (xml, binaries, etc.)""" |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
79 |
id = 'main-template' |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
80 |
__select__ = ~templatable_view() |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
81 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
82 |
def call(self, view): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
83 |
view.set_request_content_type() |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
84 |
view.set_stream() |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
85 |
xhtml_wrap = (self.req.form.has_key('__notemplate') and view.templatable |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
86 |
and view.content_type == self.req.html_content_type()) |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
87 |
if xhtml_wrap: |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
88 |
view.w(u'<?xml version="1.0"?>\n' + STRICT_DOCTYPE) |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
89 |
view.w(u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">') |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
90 |
# have to replace our unicode stream using view's binary stream |
1723 | 91 |
view.render() |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
92 |
if xhtml_wrap: |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
93 |
view.w(u'</div>') |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
94 |
self._stream = view._stream |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
95 |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
96 |
|
0 | 97 |
class TheMainTemplate(MainTemplate): |
98 |
"""default main template : |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
99 |
|
0 | 100 |
- call header / footer templates |
101 |
""" |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
102 |
id = 'main-template' |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
103 |
__select__ = templatable_view() |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
104 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
105 |
def call(self, view): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
106 |
self.set_request_content_type() |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
107 |
self.template_header(self.content_type, view) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
108 |
w = self.w |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
109 |
w(u'<div id="pageContent">\n') |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
110 |
vtitle = self.req.form.get('vtitle') |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
111 |
if vtitle: |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
112 |
w(u'<h1 class="vtitle">%s</h1>\n' % html_escape(vtitle)) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
113 |
# display entity type restriction component |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
114 |
etypefilter = self.vreg.select_component('etypenavigation', |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
115 |
self.req, self.rset) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
116 |
if etypefilter and etypefilter.propval('visible'): |
1723 | 117 |
etypefilter.render(w=w) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
118 |
self.nav_html = UStringIO() |
872 | 119 |
if view and view.need_navigation: |
120 |
view.paginate(w=self.nav_html.write) |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
121 |
w(_(self.nav_html.getvalue())) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
122 |
w(u'<div id="contentmain">\n') |
1723 | 123 |
view.render(w=w) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
124 |
w(u'</div>\n') # close id=contentmain |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
125 |
w(_(self.nav_html.getvalue())) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
126 |
w(u'</div>\n') # closes id=pageContent |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
127 |
self.template_footer(view) |
0 | 128 |
|
129 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
130 |
page_title = page_title or view.page_title() |
|
131 |
additional_headers = additional_headers or view.html_headers() |
|
132 |
self.template_html_header(content_type, page_title, additional_headers) |
|
133 |
self.template_body_header(view) |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
134 |
|
0 | 135 |
def template_html_header(self, content_type, page_title, additional_headers=()): |
136 |
w = self.whead |
|
137 |
lang = self.req.lang |
|
138 |
self.write_doctype() |
|
139 |
w(u'<base href="%s" />' % html_escape(self.req.base_url())) |
|
140 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
141 |
% (content_type, self.req.encoding)) |
|
142 |
w(u'\n'.join(additional_headers) + u'\n') |
|
819 | 143 |
self.wview('htmlheader', rset=self.rset) |
0 | 144 |
if page_title: |
145 |
w(u'<title>%s</title>\n' % html_escape(page_title)) |
|
146 |
||
147 |
def template_body_header(self, view): |
|
148 |
w = self.w |
|
149 |
w(u'<body>\n') |
|
819 | 150 |
self.wview('header', rset=self.rset, view=view) |
0 | 151 |
w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n') |
152 |
self.nav_column(view, 'left') |
|
153 |
w(u'<td id="contentcol">\n') |
|
154 |
rqlcomp = self.vreg.select_component('rqlinput', self.req, self.rset) |
|
155 |
if rqlcomp: |
|
1723 | 156 |
rqlcomp.render(w=self.w, view=view) |
0 | 157 |
msgcomp = self.vreg.select_component('applmessages', self.req, self.rset) |
158 |
if msgcomp: |
|
1723 | 159 |
msgcomp.render(w=self.w) |
0 | 160 |
self.content_header(view) |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
161 |
|
0 | 162 |
def template_footer(self, view=None): |
163 |
self.content_footer(view) |
|
164 |
self.w(u'</td>\n') |
|
165 |
self.nav_column(view, 'right') |
|
166 |
self.w(u'</tr></table></div>\n') |
|
819 | 167 |
self.wview('footer', rset=self.rset) |
0 | 168 |
self.w(u'</body>') |
169 |
||
170 |
def nav_column(self, view, context): |
|
171 |
boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset, |
|
172 |
view=view, context=context)) |
|
173 |
if boxes: |
|
174 |
self.w(u'<td class="navcol"><div class="navboxes">\n') |
|
175 |
for box in boxes: |
|
1723 | 176 |
box.render(w=self.w, view=view) |
0 | 177 |
self.w(u'</div></td>\n') |
178 |
||
179 |
def content_header(self, view=None): |
|
180 |
"""by default, display informal messages in content header""" |
|
819 | 181 |
self.wview('contentheader', rset=self.rset, view=view) |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
182 |
|
0 | 183 |
def content_footer(self, view=None): |
819 | 184 |
self.wview('contentfooter', rset=self.rset, view=view) |
0 | 185 |
|
186 |
||
187 |
class ErrorTemplate(TheMainTemplate): |
|
188 |
"""fallback template if an internal error occured during displaying the |
|
189 |
main template. This template may be called for authentication error, |
|
190 |
which means that req.cnx and req.user may not be set. |
|
191 |
""" |
|
832
8e06873d80d3
rename error template to avoid conflicts with the error view
sylvain.thenault@logilab.fr
parents:
828
diff
changeset
|
192 |
id = 'error-template' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
193 |
|
0 | 194 |
def call(self): |
195 |
"""display an unexpected error""" |
|
196 |
self.set_request_content_type() |
|
197 |
self.req.reset_headers() |
|
198 |
view = self.vreg.select_view('error', self.req, self.rset) |
|
199 |
self.template_header(self.content_type, view, self.req._('an error occured'), |
|
200 |
[NOINDEX, NOFOLLOW]) |
|
1723 | 201 |
view.render(w=self.w) |
0 | 202 |
self.template_footer(view) |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
203 |
|
0 | 204 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
205 |
w = self.whead |
|
206 |
lang = self.req.lang |
|
207 |
self.write_doctype() |
|
208 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
209 |
% (content_type, self.req.encoding)) |
|
210 |
w(u'\n'.join(additional_headers)) |
|
819 | 211 |
self.wview('htmlheader', rset=self.rset) |
0 | 212 |
w(u'<title>%s</title>\n' % html_escape(page_title)) |
213 |
self.w(u'<body>\n') |
|
214 |
||
215 |
def template_footer(self, view=None): |
|
216 |
self.w(u'</body>') |
|
217 |
||
218 |
||
219 |
class SimpleMainTemplate(TheMainTemplate): |
|
220 |
||
221 |
id = 'main-no-top' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
222 |
|
163
451a3e35dbcb
repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
158
diff
changeset
|
223 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
451a3e35dbcb
repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
158
diff
changeset
|
224 |
page_title = page_title or view.page_title() |
0 | 225 |
additional_headers = additional_headers or view.html_headers() |
226 |
whead = self.whead |
|
227 |
lang = self.req.lang |
|
228 |
self.write_doctype() |
|
229 |
whead(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
230 |
% (content_type, self.req.encoding)) |
|
231 |
whead(u'\n'.join(additional_headers) + u'\n') |
|
819 | 232 |
self.wview('htmlheader', rset=self.rset) |
0 | 233 |
w = self.w |
234 |
w(u'<title>%s</title>\n' % html_escape(page_title)) |
|
235 |
w(u'<body>\n') |
|
236 |
w(u'<div id="page">') |
|
237 |
w(u'<table width="100%" height="100%" border="0"><tr>\n') |
|
238 |
w(u'<td class="navcol">\n') |
|
239 |
self.topleft_header() |
|
240 |
boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset, |
|
241 |
view=view, context='left')) |
|
242 |
if boxes: |
|
243 |
w(u'<div class="navboxes">\n') |
|
244 |
for box in boxes: |
|
1723 | 245 |
box.render(w=w) |
0 | 246 |
self.w(u'</div>\n') |
247 |
w(u'</td>') |
|
248 |
w(u'<td id="contentcol" rowspan="2">') |
|
249 |
w(u'<div id="pageContent">\n') |
|
250 |
vtitle = self.req.form.get('vtitle') |
|
251 |
if vtitle: |
|
432 | 252 |
w(u'<h1 class="vtitle">%s</h1>' % html_escape(vtitle)) |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
253 |
|
0 | 254 |
def topleft_header(self): |
255 |
self.w(u'<table id="header"><tr>\n') |
|
256 |
self.w(u'<td>') |
|
1723 | 257 |
self.vreg.select_component('logo', self.req, self.rset).render(w=self.w) |
0 | 258 |
self.w(u'</td>\n') |
259 |
self.w(u'</tr></table>\n') |
|
260 |
||
261 |
# page parts templates ######################################################## |
|
262 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
263 |
class HTMLHeader(View): |
0 | 264 |
"""default html headers""" |
265 |
id = 'htmlheader' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
266 |
|
0 | 267 |
def call(self, **kwargs): |
268 |
self.favicon() |
|
269 |
self.stylesheets() |
|
270 |
self.javascripts() |
|
271 |
self.alternates() |
|
272 |
self.pageid() |
|
273 |
||
274 |
def favicon(self): |
|
275 |
favicon = self.req.external_resource('FAVICON', None) |
|
276 |
if favicon: |
|
277 |
self.whead(u'<link rel="shortcut icon" href="%s"/>\n' % favicon) |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
278 |
|
0 | 279 |
def stylesheets(self): |
280 |
req = self.req |
|
281 |
add_css = req.add_css |
|
282 |
for css in req.external_resource('STYLESHEETS'): |
|
283 |
add_css(css, localfile=False) |
|
284 |
for css in req.external_resource('STYLESHEETS_PRINT'): |
|
285 |
add_css(css, u'print', localfile=False) |
|
286 |
for css in req.external_resource('IE_STYLESHEETS'): |
|
287 |
add_css(css, localfile=False, ieonly=True) |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
288 |
|
0 | 289 |
def javascripts(self): |
290 |
for jscript in self.req.external_resource('JAVASCRIPTS'): |
|
291 |
self.req.add_js(jscript, localfile=False) |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
292 |
|
0 | 293 |
def alternates(self): |
142
0425ee84cfa6
add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
29
diff
changeset
|
294 |
urlgetter = self.vreg.select_component('rss_feed_url', self.req, self.rset) |
0425ee84cfa6
add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
29
diff
changeset
|
295 |
if urlgetter is not None: |
0425ee84cfa6
add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
29
diff
changeset
|
296 |
url = urlgetter.feed_url() |
0 | 297 |
self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n' |
144 | 298 |
% html_escape(url)) |
0 | 299 |
|
300 |
def pageid(self): |
|
301 |
req = self.req |
|
302 |
pid = make_uid(id(req)) |
|
303 |
req.pageid = pid |
|
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
304 |
req.html_headers.define_var('pageid', pid) |
0 | 305 |
|
306 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
307 |
class HTMLPageHeader(View): |
0 | 308 |
"""default html page header""" |
309 |
id = 'header' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
310 |
|
0 | 311 |
def call(self, view, **kwargs): |
312 |
self.main_header(view) |
|
313 |
self.w(u''' |
|
314 |
<div id="stateheader">''') |
|
315 |
self.state_header() |
|
316 |
self.w(u''' |
|
317 |
</div> |
|
318 |
''') |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
319 |
|
0 | 320 |
def main_header(self, view): |
321 |
"""build the top menu with authentification info and the rql box""" |
|
322 |
self.w(u'<table id="header"><tr>\n') |
|
323 |
self.w(u'<td id="firstcolumn">') |
|
1723 | 324 |
self.vreg.select_component('logo', self.req, self.rset).render(w=self.w) |
0 | 325 |
self.w(u'</td>\n') |
326 |
# appliname and breadcrumbs |
|
327 |
self.w(u'<td id="headtext">') |
|
328 |
comp = self.vreg.select_component('appliname', self.req, self.rset) |
|
329 |
if comp and comp.propval('visible'): |
|
1723 | 330 |
comp.render(w=self.w) |
0 | 331 |
comp = self.vreg.select_component('breadcrumbs', self.req, self.rset, view=view) |
332 |
if comp and comp.propval('visible'): |
|
1723 | 333 |
comp.render(w=self.w, view=view) |
0 | 334 |
self.w(u'</td>') |
335 |
# logged user and help |
|
336 |
self.w(u'<td>\n') |
|
337 |
comp = self.vreg.select_component('loggeduserlink', self.req, self.rset) |
|
1723 | 338 |
comp.render(w=self.w) |
0 | 339 |
self.w(u'</td><td>') |
340 |
helpcomp = self.vreg.select_component('help', self.req, self.rset) |
|
341 |
if helpcomp: # may not be available if Card is not defined in the schema |
|
1723 | 342 |
helpcomp.render(w=self.w) |
0 | 343 |
self.w(u'</td>') |
344 |
# lastcolumn |
|
345 |
self.w(u'<td id="lastcolumn">') |
|
346 |
self.w(u'</td>\n') |
|
347 |
self.w(u'</tr></table>\n') |
|
819 | 348 |
self.wview('logform', rset=self.rset, id='popupLoginBox', klass='hidden', |
349 |
title=False, message=False) |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
350 |
|
0 | 351 |
def state_header(self): |
352 |
state = self.req.search_state |
|
353 |
if state[0] == 'normal': |
|
354 |
return |
|
355 |
_ = self.req._ |
|
356 |
value = self.view('oneline', self.req.eid_rset(state[1][1])) |
|
357 |
msg = ' '.join((_("searching for"), |
|
358 |
display_name(self.req, state[1][3]), |
|
359 |
_("to associate with"), value, |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
360 |
_("by relation"), '"', |
0 | 361 |
display_name(self.req, state[1][2], state[1][0]), |
362 |
'"')) |
|
363 |
return self.w(u'<div class="stateMessage">%s</div>' % msg) |
|
364 |
||
365 |
||
366 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
367 |
class HTMLPageFooter(View): |
0 | 368 |
"""default html page footer: include logo if any, and close the HTML body |
369 |
""" |
|
370 |
id = 'footer' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
371 |
|
0 | 372 |
def call(self, **kwargs): |
373 |
req = self.req |
|
374 |
self.w(u'<div class="footer">') |
|
375 |
# XXX Take object from the registry if in there? would be |
|
376 |
# better anyway |
|
377 |
from cubicweb.web.views.wdoc import ChangeLogView |
|
378 |
self.w(u'<a href="%s">%s</a> | ' % (req.build_url('changelog'), |
|
379 |
req._(ChangeLogView.title).lower())) |
|
380 |
self.w(u'<a href="%s">%s</a> | ' % (req.build_url('doc/about'), |
|
381 |
req._('about this site'))) |
|
580 | 382 |
self.w(u'© 2001-2009 <a href="http://www.logilab.fr">Logilab S.A.</a>') |
0 | 383 |
self.w(u'</div>') |
384 |
||
385 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
386 |
class HTMLContentHeader(View): |
0 | 387 |
"""default html page content header: |
388 |
* include message component if selectable for this request |
|
389 |
* include selectable content navigation components |
|
390 |
""" |
|
391 |
id = 'contentheader' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
392 |
|
0 | 393 |
def call(self, view, **kwargs): |
394 |
"""by default, display informal messages in content header""" |
|
395 |
components = self.vreg.possible_vobjects('contentnavigation', |
|
396 |
self.req, self.rset, |
|
397 |
view=view, context='navtop') |
|
398 |
if components: |
|
399 |
self.w(u'<div id="contentheader">') |
|
400 |
for comp in components: |
|
1723 | 401 |
comp.render(w=self.w, view=view) |
0 | 402 |
self.w(u'</div><div class="clear"></div>') |
403 |
||
404 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
405 |
class HTMLContentFooter(View): |
0 | 406 |
"""default html page content footer: include selectable content navigation |
407 |
components |
|
408 |
""" |
|
409 |
id = 'contentfooter' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
410 |
|
0 | 411 |
def call(self, view, **kwargs): |
412 |
components = self.vreg.possible_vobjects('contentnavigation', |
|
413 |
self.req, self.rset, |
|
414 |
view=view, context='navbottom') |
|
415 |
if components: |
|
416 |
self.w(u'<div id="contentfooter">') |
|
417 |
for comp in components: |
|
1723 | 418 |
comp.render(w=self.w, view=view) |
0 | 419 |
self.w(u'</div>') |
420 |
||
421 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
422 |
class LogFormTemplate(View): |
0 | 423 |
id = 'logform' |
826
51cb3d85c059
fix LogFormTemplate selector
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
424 |
__select__ = match_kwargs('id', 'klass') |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
425 |
|
0 | 426 |
title = 'log in' |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
427 |
|
0 | 428 |
def call(self, id, klass, title=True, message=True): |
429 |
self.req.add_css('cubicweb.login.css') |
|
430 |
self.w(u'<div id="%s" class="%s">' % (id, klass)) |
|
431 |
if title: |
|
432 |
self.w(u'<div id="loginTitle">%s</div>' |
|
433 |
% self.req.property_value('ui.site-title')) |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
434 |
self.w(u'<div id="loginContent">\n') |
0 | 435 |
|
436 |
if message: |
|
437 |
self.display_message() |
|
438 |
if self.config['auth-mode'] == 'http': |
|
439 |
# HTTP authentication |
|
440 |
pass |
|
441 |
else: |
|
442 |
# Cookie authentication |
|
443 |
self.login_form(id) |
|
444 |
self.w(u'</div></div>\n') |
|
445 |
||
446 |
def display_message(self): |
|
447 |
message = self.req.message |
|
448 |
if message: |
|
449 |
self.w(u'<div class="simpleMessage">%s</div>\n' % message) |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
450 |
|
0 | 451 |
def login_form(self, id): |
452 |
_ = self.req._ |
|
453 |
self.w(u'<form method="post" action="%s" id="login_form">\n' |
|
454 |
% html_escape(login_form_url(self.config, self.req))) |
|
455 |
self.w(u'<table>\n') |
|
456 |
self.w(u'<tr>\n') |
|
1776
4be367276874
adapt login box message to allow-email-login configuration
Florent <florent@secondweb.fr>
parents:
1723
diff
changeset
|
457 |
msg = (self.config['allow-email-login'] and _('login or email')) or _('login') |
4be367276874
adapt login box message to allow-email-login configuration
Florent <florent@secondweb.fr>
parents:
1723
diff
changeset
|
458 |
self.w(u'<td><label for="__login">%s</label></td>' % msg) |
0 | 459 |
self.w(u'<td><input name="__login" id="__login" class="data" type="text" /></td>') |
460 |
self.w(u'</tr><tr>\n') |
|
461 |
self.w(u'<td><label for="__password" >%s</label></td>' % _('password')) |
|
462 |
self.w(u'<td><input name="__password" id="__password" class="data" type="password" /></td>\n') |
|
463 |
self.w(u'</tr><tr>\n') |
|
464 |
self.w(u'<td> </td><td><input type="submit" class="loginButton right" value="%s" />\n</td>' % _('log in')) |
|
465 |
self.w(u'</tr>\n') |
|
466 |
self.w(u'</table>\n') |
|
467 |
self.w(u'</form>\n') |
|
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
16
diff
changeset
|
468 |
self.req.html_headers.add_onload('jQuery("#__login:visible").focus()') |
0 | 469 |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
470 |
|
0 | 471 |
def login_form_url(config, req): |
472 |
if req.https: |
|
473 |
return req.url() |
|
474 |
if config.get('https-url'): |
|
475 |
return req.url().replace(req.base_url(), config['https-url']) |
|
476 |
return req.url() |
|
477 |
||
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
478 |
|
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
479 |
## vregistry registration callback ############################################ |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
480 |
def registration_callback(vreg): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
481 |
vreg.register_all(globals().values(), modname=__name__) |