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