author | sylvain.thenault@logilab.fr |
Mon, 16 Feb 2009 20:55:00 +0100 | |
branch | tls-sprint |
changeset 646 | 8a9551089912 |
parent 641 | ed668804af37 |
parent 637 | a78ffe83fadc |
child 811 | c6ebabe9db91 |
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 |
||
592
aae01d81c713
have navigation on top and bottom of search results
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
432
diff
changeset
|
10 |
|
0 | 11 |
from logilab.mtconverter import html_escape |
12 |
||
13 |
from cubicweb import NoSelectableObject, ObjectNotFound |
|
14 |
from cubicweb.common.view import Template, MainTemplate, NOINDEX, NOFOLLOW |
|
15 |
from cubicweb.common.utils import make_uid |
|
597 | 16 |
from cubicweb.common.utils import UStringIO |
0 | 17 |
|
18 |
from cubicweb.web.views.baseviews import vid_from_rset |
|
19 |
||
20 |
# main templates ############################################################## |
|
21 |
||
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
22 |
class LogInOutTemplate(MainTemplate): |
0 | 23 |
|
24 |
def call(self): |
|
25 |
self.set_request_content_type() |
|
26 |
w = self.w |
|
27 |
self.write_doctype() |
|
28 |
lang = self.req.lang |
|
29 |
self.template_header('text/html', self.req._('login_action')) |
|
30 |
w(u'<body>\n') |
|
31 |
self.content(w) |
|
32 |
w(u'</body>') |
|
33 |
||
34 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
35 |
w = self.whead |
|
36 |
# explictly close the <base> tag to avoid IE 6 bugs while browsing DOM |
|
37 |
w(u'<base href="%s"></base>' % html_escape(self.req.base_url())) |
|
38 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
39 |
% (content_type, self.req.encoding)) |
|
40 |
w(NOINDEX) |
|
41 |
w(NOFOLLOW) |
|
42 |
w(u'\n'.join(additional_headers) + u'\n') |
|
43 |
self.template('htmlheader', rset=self.rset) |
|
44 |
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
|
45 |
|
0 | 46 |
|
47 |
class LogInTemplate(LogInOutTemplate): |
|
48 |
id = 'login' |
|
49 |
title = 'log in' |
|
50 |
||
51 |
def content(self, w): |
|
52 |
self.template('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
|
53 |
|
0 | 54 |
|
55 |
class LoggedOutTemplate(LogInOutTemplate): |
|
56 |
id = 'loggedout' |
|
57 |
title = 'logged out' |
|
58 |
||
59 |
def content(self, w): |
|
60 |
msg = self.req._('you have been logged out') |
|
61 |
w(u'<h1 class="noborder">%s</h1>\n' % msg) |
|
62 |
if self.config['anonymous-user']: |
|
63 |
indexurl = self.build_url('view', vid='index', __message=msg) |
|
64 |
w(u'<p><a href="%s">%s</a><p>' % ( |
|
65 |
html_escape(indexurl), |
|
66 |
self.req._('go back to the index page'))) |
|
67 |
||
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
68 |
|
0 | 69 |
class TheMainTemplate(MainTemplate): |
70 |
"""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
|
71 |
|
0 | 72 |
- call header / footer templates |
73 |
- build result set |
|
74 |
- guess and call an appropriate view through the view manager |
|
75 |
""" |
|
76 |
id = 'main' |
|
77 |
||
78 |
def _select_view_and_rset(self): |
|
79 |
req = self.req |
|
80 |
if self.rset is None and not hasattr(req, '_rql_processed'): |
|
81 |
req._rql_processed = True |
|
82 |
rset = self.process_rql(req.form.get('rql')) |
|
83 |
else: |
|
84 |
rset = self.rset |
|
85 |
# handle special "method" param when necessary |
|
86 |
# XXX this should probably not be in the template (controller ?), however: |
|
87 |
# * we need to have the displayed rset |
|
88 |
# * we don't want to handle it in each view |
|
89 |
if rset and rset.rowcount == 1 and '__method' in req.form: |
|
90 |
entity = rset.get_entity(0, 0) |
|
91 |
try: |
|
92 |
method = getattr(entity, req.form.pop('__method')) |
|
93 |
method() |
|
94 |
except Exception, ex: |
|
95 |
self.exception('while handling __method') |
|
96 |
req.set_message(req._("error while handling __method: %s") % req._(ex)) |
|
97 |
vid = req.form.get('vid') or vid_from_rset(req, rset, self.schema) |
|
98 |
try: |
|
99 |
view = self.vreg.select_view(vid, req, rset) |
|
100 |
except ObjectNotFound: |
|
101 |
self.warning("the view %s could not be found", vid) |
|
102 |
req.set_message(req._("The view %s could not be found") % vid) |
|
103 |
vid = vid_from_rset(req, rset, self.schema) |
|
104 |
view = self.vreg.select_view(vid, req, rset) |
|
105 |
except NoSelectableObject: |
|
106 |
if rset: |
|
107 |
req.set_message(req._("The view %s can not be applied to this query") % vid) |
|
108 |
else: |
|
109 |
req.set_message(req._("You have no access to this view or it's not applyable to current data")) |
|
110 |
self.warning("the view %s can not be applied to this query", vid) |
|
111 |
vid = vid_from_rset(req, rset, self.schema) |
|
112 |
view = self.vreg.select_view(vid, req, rset) |
|
113 |
return view, rset |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
114 |
|
0 | 115 |
def call(self): |
116 |
view, rset = self._select_view_and_rset() |
|
117 |
req = self.req |
|
118 |
# update breadcrumps **before** validating cache, unless the view |
|
119 |
# specifies explicitly it should not be added to breadcrumb or the |
|
120 |
# view is a binary view |
|
121 |
if view.add_to_breadcrumbs and not view.binary: |
|
122 |
req.update_breadcrumbs() |
|
123 |
view.set_http_cache_headers() |
|
124 |
req.validate_cache() |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
125 |
with_templates = self.with_templates(view) |
0 | 126 |
if not with_templates: |
127 |
view.set_request_content_type() |
|
128 |
self.set_stream(templatable=False) |
|
129 |
else: |
|
130 |
self.set_request_content_type() |
|
131 |
content_type = self.content_type |
|
132 |
self.template_header(content_type, view) |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
133 |
self.template('page-content', view=view, rset=rset) |
0 | 134 |
if with_templates: |
135 |
self.template_footer(view) |
|
136 |
||
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
137 |
def with_templates(self, view): |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
138 |
return (not view.binary and view.templatable and |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
139 |
not self.req.form.has_key('__notemplate')) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
140 |
|
0 | 141 |
def process_rql(self, rql): |
142 |
"""execute rql if specified""" |
|
143 |
if rql: |
|
144 |
self.ensure_ro_rql(rql) |
|
145 |
if not isinstance(rql, unicode): |
|
146 |
rql = unicode(rql, self.req.encoding) |
|
147 |
pp = self.vreg.select_component('magicsearch', self.req) |
|
148 |
self.rset = pp.process_query(rql, self.req) |
|
149 |
return self.rset |
|
150 |
return None |
|
151 |
||
152 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
153 |
page_title = page_title or view.page_title() |
|
154 |
additional_headers = additional_headers or view.html_headers() |
|
155 |
self.template_html_header(content_type, page_title, additional_headers) |
|
156 |
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
|
157 |
|
0 | 158 |
def template_html_header(self, content_type, page_title, additional_headers=()): |
159 |
w = self.whead |
|
160 |
lang = self.req.lang |
|
161 |
self.write_doctype() |
|
162 |
w(u'<base href="%s" />' % html_escape(self.req.base_url())) |
|
163 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
164 |
% (content_type, self.req.encoding)) |
|
165 |
w(u'\n'.join(additional_headers) + u'\n') |
|
166 |
self.template('htmlheader', rset=self.rset) |
|
167 |
if page_title: |
|
168 |
w(u'<title>%s</title>\n' % html_escape(page_title)) |
|
169 |
||
170 |
def template_body_header(self, view): |
|
171 |
w = self.w |
|
172 |
w(u'<body>\n') |
|
173 |
self.template('header', rset=self.rset, view=view) |
|
174 |
w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n') |
|
175 |
self.nav_column(view, 'left') |
|
176 |
w(u'<td id="contentcol">\n') |
|
177 |
rqlcomp = self.vreg.select_component('rqlinput', self.req, self.rset) |
|
178 |
if rqlcomp: |
|
179 |
rqlcomp.dispatch(w=self.w, view=view) |
|
180 |
msgcomp = self.vreg.select_component('applmessages', self.req, self.rset) |
|
181 |
if msgcomp: |
|
182 |
msgcomp.dispatch(w=self.w) |
|
183 |
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
|
184 |
|
0 | 185 |
def template_footer(self, view=None): |
186 |
self.content_footer(view) |
|
187 |
self.w(u'</td>\n') |
|
188 |
self.nav_column(view, 'right') |
|
189 |
self.w(u'</tr></table></div>\n') |
|
190 |
self.template('footer', rset=self.rset) |
|
191 |
self.w(u'</body>') |
|
192 |
||
193 |
def nav_column(self, view, context): |
|
194 |
boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset, |
|
195 |
view=view, context=context)) |
|
196 |
if boxes: |
|
197 |
self.w(u'<td class="navcol"><div class="navboxes">\n') |
|
198 |
for box in boxes: |
|
199 |
box.dispatch(w=self.w, view=view) |
|
200 |
self.w(u'</div></td>\n') |
|
201 |
||
202 |
def content_header(self, view=None): |
|
203 |
"""by default, display informal messages in content header""" |
|
204 |
self.template('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
|
205 |
|
0 | 206 |
def content_footer(self, view=None): |
207 |
self.template('contentfooter', rset=self.rset, view=view) |
|
208 |
||
209 |
||
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
210 |
class PageContentTemplate(TheMainTemplate): |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
211 |
id = 'page-content' |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
212 |
|
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
213 |
def call(self, view=None, rset=None): |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
214 |
self.req.set_header('x-cubicweb-css', 'a.css;b.css') |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
215 |
if view is None: |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
216 |
view, rset = self._select_view_and_rset() |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
217 |
with_templates = self.with_templates(view) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
218 |
w = self.w |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
219 |
if with_templates: |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
220 |
w(u'<div id="pageContent">\n') |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
221 |
vtitle = self.req.form.get('vtitle') |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
222 |
if vtitle: |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
223 |
w(u'<h1 class="vtitle">%s</h1>\n' % html_escape(vtitle)) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
224 |
# display entity type restriction component |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
225 |
etypefilter = self.vreg.select_component('etypenavigation', |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
226 |
self.req, self.rset) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
227 |
if etypefilter and etypefilter.propval('visible'): |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
228 |
etypefilter.dispatch(w=w) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
229 |
self.nav_html = UStringIO() |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
230 |
self.pagination(self.req, self.rset, self.nav_html.write, |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
231 |
not (view and view.need_navigation)) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
232 |
w(_(self.nav_html.getvalue())) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
233 |
w(u'<div id="contentmain">\n') |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
234 |
if view.binary: |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
235 |
# have to replace our unicode stream using view's binary stream |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
236 |
view.dispatch() |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
237 |
assert self._stream, 'duh, template used as a sub-view ?? (%s)' % self._stream |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
238 |
self._stream = view._stream |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
239 |
else: |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
240 |
view.dispatch(w=w) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
241 |
if with_templates: |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
242 |
w(u'</div>\n') # close id=contentmain |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
243 |
w(_(self.nav_html.getvalue())) |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
244 |
w(u'</div>\n') # closes id=pageContent |
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
245 |
|
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
246 |
|
0 | 247 |
class ErrorTemplate(TheMainTemplate): |
248 |
"""fallback template if an internal error occured during displaying the |
|
249 |
main template. This template may be called for authentication error, |
|
250 |
which means that req.cnx and req.user may not be set. |
|
251 |
""" |
|
252 |
id = 'error' |
|
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 call(self): |
255 |
"""display an unexpected error""" |
|
256 |
self.set_request_content_type() |
|
257 |
self.req.reset_headers() |
|
258 |
view = self.vreg.select_view('error', self.req, self.rset) |
|
259 |
self.template_header(self.content_type, view, self.req._('an error occured'), |
|
260 |
[NOINDEX, NOFOLLOW]) |
|
261 |
view.dispatch(w=self.w) |
|
262 |
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
|
263 |
|
0 | 264 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
265 |
w = self.whead |
|
266 |
lang = self.req.lang |
|
267 |
self.write_doctype() |
|
268 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
269 |
% (content_type, self.req.encoding)) |
|
270 |
w(u'\n'.join(additional_headers)) |
|
271 |
self.template('htmlheader', rset=self.rset) |
|
272 |
w(u'<title>%s</title>\n' % html_escape(page_title)) |
|
273 |
self.w(u'<body>\n') |
|
274 |
||
275 |
def template_footer(self, view=None): |
|
276 |
self.w(u'</body>') |
|
277 |
||
278 |
||
279 |
class SimpleMainTemplate(TheMainTemplate): |
|
280 |
||
281 |
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
|
282 |
|
163
451a3e35dbcb
repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
158
diff
changeset
|
283 |
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
|
284 |
page_title = page_title or view.page_title() |
0 | 285 |
additional_headers = additional_headers or view.html_headers() |
286 |
whead = self.whead |
|
287 |
lang = self.req.lang |
|
288 |
self.write_doctype() |
|
289 |
whead(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
290 |
% (content_type, self.req.encoding)) |
|
291 |
whead(u'\n'.join(additional_headers) + u'\n') |
|
292 |
self.template('htmlheader', rset=self.rset) |
|
293 |
w = self.w |
|
294 |
w(u'<title>%s</title>\n' % html_escape(page_title)) |
|
295 |
w(u'<body>\n') |
|
296 |
w(u'<div id="page">') |
|
297 |
w(u'<table width="100%" height="100%" border="0"><tr>\n') |
|
298 |
w(u'<td class="navcol">\n') |
|
299 |
self.topleft_header() |
|
300 |
boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset, |
|
301 |
view=view, context='left')) |
|
302 |
if boxes: |
|
303 |
w(u'<div class="navboxes">\n') |
|
304 |
for box in boxes: |
|
305 |
box.dispatch(w=w) |
|
306 |
self.w(u'</div>\n') |
|
307 |
w(u'</td>') |
|
308 |
w(u'<td id="contentcol" rowspan="2">') |
|
309 |
w(u'<div id="pageContent">\n') |
|
310 |
vtitle = self.req.form.get('vtitle') |
|
311 |
if vtitle: |
|
432 | 312 |
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
|
313 |
|
0 | 314 |
def topleft_header(self): |
315 |
self.w(u'<table id="header"><tr>\n') |
|
316 |
self.w(u'<td>') |
|
317 |
self.vreg.select_component('logo', self.req, self.rset).dispatch(w=self.w) |
|
318 |
self.w(u'</td>\n') |
|
319 |
self.w(u'</tr></table>\n') |
|
320 |
||
321 |
# page parts templates ######################################################## |
|
322 |
||
323 |
class HTMLHeader(Template): |
|
324 |
"""default html headers""" |
|
325 |
id = 'htmlheader' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
326 |
|
0 | 327 |
def call(self, **kwargs): |
328 |
self.favicon() |
|
329 |
self.stylesheets() |
|
330 |
self.javascripts() |
|
331 |
self.alternates() |
|
332 |
self.pageid() |
|
333 |
||
334 |
def favicon(self): |
|
335 |
favicon = self.req.external_resource('FAVICON', None) |
|
336 |
if favicon: |
|
337 |
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
|
338 |
|
0 | 339 |
def stylesheets(self): |
340 |
req = self.req |
|
341 |
add_css = req.add_css |
|
342 |
for css in req.external_resource('STYLESHEETS'): |
|
343 |
add_css(css, localfile=False) |
|
344 |
for css in req.external_resource('STYLESHEETS_PRINT'): |
|
345 |
add_css(css, u'print', localfile=False) |
|
346 |
for css in req.external_resource('IE_STYLESHEETS'): |
|
347 |
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
|
348 |
|
0 | 349 |
def javascripts(self): |
350 |
for jscript in self.req.external_resource('JAVASCRIPTS'): |
|
351 |
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
|
352 |
|
0 | 353 |
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
|
354 |
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
|
355 |
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
|
356 |
url = urlgetter.feed_url() |
0 | 357 |
self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n' |
144 | 358 |
% html_escape(url)) |
0 | 359 |
|
360 |
def pageid(self): |
|
361 |
req = self.req |
|
362 |
pid = make_uid(id(req)) |
|
363 |
req.pageid = pid |
|
364 |
req.html_headers.define_var('pageid', pid); |
|
365 |
||
366 |
||
367 |
class HTMLPageHeader(Template): |
|
368 |
"""default html page header""" |
|
369 |
id = 'header' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
370 |
|
0 | 371 |
def call(self, view, **kwargs): |
372 |
self.main_header(view) |
|
373 |
self.w(u''' |
|
374 |
<div id="stateheader">''') |
|
375 |
self.state_header() |
|
376 |
self.w(u''' |
|
377 |
</div> |
|
378 |
''') |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
379 |
|
0 | 380 |
def main_header(self, view): |
381 |
"""build the top menu with authentification info and the rql box""" |
|
382 |
self.w(u'<table id="header"><tr>\n') |
|
383 |
self.w(u'<td id="firstcolumn">') |
|
384 |
self.vreg.select_component('logo', self.req, self.rset).dispatch(w=self.w) |
|
385 |
self.w(u'</td>\n') |
|
386 |
# appliname and breadcrumbs |
|
387 |
self.w(u'<td id="headtext">') |
|
388 |
comp = self.vreg.select_component('appliname', self.req, self.rset) |
|
389 |
if comp and comp.propval('visible'): |
|
390 |
comp.dispatch(w=self.w) |
|
391 |
comp = self.vreg.select_component('breadcrumbs', self.req, self.rset, view=view) |
|
392 |
if comp and comp.propval('visible'): |
|
393 |
comp.dispatch(w=self.w, view=view) |
|
394 |
self.w(u'</td>') |
|
395 |
# logged user and help |
|
396 |
self.w(u'<td>\n') |
|
397 |
comp = self.vreg.select_component('loggeduserlink', self.req, self.rset) |
|
398 |
comp.dispatch(w=self.w) |
|
399 |
self.w(u'</td><td>') |
|
400 |
helpcomp = self.vreg.select_component('help', self.req, self.rset) |
|
401 |
if helpcomp: # may not be available if Card is not defined in the schema |
|
402 |
helpcomp.dispatch(w=self.w) |
|
403 |
self.w(u'</td>') |
|
404 |
# lastcolumn |
|
405 |
self.w(u'<td id="lastcolumn">') |
|
406 |
self.w(u'</td>\n') |
|
407 |
self.w(u'</tr></table>\n') |
|
408 |
self.template('logform', rset=self.rset, id='popupLoginBox', klass='hidden', |
|
409 |
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
|
410 |
|
0 | 411 |
def state_header(self): |
412 |
state = self.req.search_state |
|
413 |
if state[0] == 'normal': |
|
414 |
return |
|
415 |
_ = self.req._ |
|
416 |
value = self.view('oneline', self.req.eid_rset(state[1][1])) |
|
417 |
msg = ' '.join((_("searching for"), |
|
418 |
display_name(self.req, state[1][3]), |
|
419 |
_("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
|
420 |
_("by relation"), '"', |
0 | 421 |
display_name(self.req, state[1][2], state[1][0]), |
422 |
'"')) |
|
423 |
return self.w(u'<div class="stateMessage">%s</div>' % msg) |
|
424 |
||
425 |
||
426 |
||
427 |
class HTMLPageFooter(Template): |
|
428 |
"""default html page footer: include logo if any, and close the HTML body |
|
429 |
""" |
|
430 |
id = 'footer' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
431 |
|
0 | 432 |
def call(self, **kwargs): |
433 |
req = self.req |
|
434 |
self.w(u'<div class="footer">') |
|
435 |
# XXX Take object from the registry if in there? would be |
|
436 |
# better anyway |
|
437 |
from cubicweb.web.views.wdoc import ChangeLogView |
|
438 |
self.w(u'<a href="%s">%s</a> | ' % (req.build_url('changelog'), |
|
439 |
req._(ChangeLogView.title).lower())) |
|
440 |
self.w(u'<a href="%s">%s</a> | ' % (req.build_url('doc/about'), |
|
441 |
req._('about this site'))) |
|
580 | 442 |
self.w(u'© 2001-2009 <a href="http://www.logilab.fr">Logilab S.A.</a>') |
0 | 443 |
self.w(u'</div>') |
444 |
||
445 |
||
446 |
class HTMLContentHeader(Template): |
|
447 |
"""default html page content header: |
|
448 |
* include message component if selectable for this request |
|
449 |
* include selectable content navigation components |
|
450 |
""" |
|
451 |
id = 'contentheader' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
452 |
|
0 | 453 |
def call(self, view, **kwargs): |
454 |
"""by default, display informal messages in content header""" |
|
455 |
components = self.vreg.possible_vobjects('contentnavigation', |
|
456 |
self.req, self.rset, |
|
457 |
view=view, context='navtop') |
|
458 |
if components: |
|
459 |
self.w(u'<div id="contentheader">') |
|
460 |
for comp in components: |
|
461 |
comp.dispatch(w=self.w, view=view) |
|
462 |
self.w(u'</div><div class="clear"></div>') |
|
463 |
||
464 |
||
465 |
class HTMLContentFooter(Template): |
|
466 |
"""default html page content footer: include selectable content navigation |
|
467 |
components |
|
468 |
""" |
|
469 |
id = 'contentfooter' |
|
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 call(self, view, **kwargs): |
472 |
components = self.vreg.possible_vobjects('contentnavigation', |
|
473 |
self.req, self.rset, |
|
474 |
view=view, context='navbottom') |
|
475 |
if components: |
|
476 |
self.w(u'<div id="contentfooter">') |
|
477 |
for comp in components: |
|
478 |
comp.dispatch(w=self.w, view=view) |
|
479 |
self.w(u'</div>') |
|
480 |
||
481 |
||
482 |
class LogFormTemplate(Template): |
|
483 |
id = 'logform' |
|
484 |
title = 'log in' |
|
485 |
||
486 |
def call(self, id, klass, title=True, message=True): |
|
487 |
self.req.add_css('cubicweb.login.css') |
|
488 |
self.w(u'<div id="%s" class="%s">' % (id, klass)) |
|
489 |
if title: |
|
490 |
self.w(u'<div id="loginTitle">%s</div>' |
|
491 |
% 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
|
492 |
self.w(u'<div id="loginContent">\n') |
0 | 493 |
|
494 |
if message: |
|
495 |
self.display_message() |
|
496 |
if self.config['auth-mode'] == 'http': |
|
497 |
# HTTP authentication |
|
498 |
pass |
|
499 |
else: |
|
500 |
# Cookie authentication |
|
501 |
self.login_form(id) |
|
502 |
self.w(u'</div></div>\n') |
|
503 |
||
504 |
def display_message(self): |
|
505 |
message = self.req.message |
|
506 |
if message: |
|
507 |
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
|
508 |
|
0 | 509 |
def login_form(self, id): |
510 |
_ = self.req._ |
|
511 |
self.w(u'<form method="post" action="%s" id="login_form">\n' |
|
512 |
% html_escape(login_form_url(self.config, self.req))) |
|
513 |
self.w(u'<table>\n') |
|
514 |
self.w(u'<tr>\n') |
|
637
a78ffe83fadc
change label for new registered users
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
609
diff
changeset
|
515 |
self.w(u'<td><label for="__login">%s</label></td>' % _('login or email')) |
0 | 516 |
self.w(u'<td><input name="__login" id="__login" class="data" type="text" /></td>') |
517 |
self.w(u'</tr><tr>\n') |
|
518 |
self.w(u'<td><label for="__password" >%s</label></td>' % _('password')) |
|
519 |
self.w(u'<td><input name="__password" id="__password" class="data" type="password" /></td>\n') |
|
520 |
self.w(u'</tr><tr>\n') |
|
521 |
self.w(u'<td> </td><td><input type="submit" class="loginButton right" value="%s" />\n</td>' % _('log in')) |
|
522 |
self.w(u'</tr>\n') |
|
523 |
self.w(u'</table>\n') |
|
524 |
self.w(u'</form>\n') |
|
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
16
diff
changeset
|
525 |
self.req.html_headers.add_onload('jQuery("#__login:visible").focus()') |
0 | 526 |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
527 |
|
0 | 528 |
def login_form_url(config, req): |
529 |
if req.https: |
|
530 |
return req.url() |
|
531 |
if config.get('https-url'): |
|
532 |
return req.url().replace(req.base_url(), config['https-url']) |
|
533 |
return req.url() |
|
534 |