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