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