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