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