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