author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 22 Sep 2009 14:08:21 +0200 | |
branch | stable |
changeset 3370 | 62ed9981a770 |
parent 3242 | 390acf7594ed |
child 3293 | 69c0ba095536 |
child 3495 | 438576c5b1d1 |
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 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
13 |
from cubicweb.appobject 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 |
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
16 |
from cubicweb.utils import make_uid, UStringIO, can_do_pdf_conversion |
3242
390acf7594ed
missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
17 |
from cubicweb.schema import display_name |
2555
ca7b122f34fa
fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents:
2381
diff
changeset
|
18 |
|
0 | 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 |
self.template_header('text/html', self.req._('login_action')) |
|
28 |
w(u'<body>\n') |
|
29 |
self.content(w) |
|
30 |
w(u'</body>') |
|
31 |
||
32 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
33 |
w = self.whead |
|
34 |
# 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
|
35 |
w(u'<base href="%s"></base>' % xml_escape(self.req.base_url())) |
0 | 36 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
37 |
% (content_type, self.req.encoding)) |
|
38 |
w(NOINDEX) |
|
39 |
w(NOFOLLOW) |
|
40 |
w(u'\n'.join(additional_headers) + u'\n') |
|
819 | 41 |
self.wview('htmlheader', rset=self.rset) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
42 |
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
|
43 |
|
0 | 44 |
|
45 |
class LogInTemplate(LogInOutTemplate): |
|
46 |
id = 'login' |
|
47 |
title = 'log in' |
|
48 |
||
49 |
def content(self, w): |
|
819 | 50 |
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
|
51 |
|
0 | 52 |
|
53 |
class LoggedOutTemplate(LogInOutTemplate): |
|
54 |
id = 'loggedout' |
|
55 |
title = 'logged out' |
|
56 |
||
57 |
def content(self, w): |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
432
diff
changeset
|
58 |
# FIXME Deprecated code ? |
0 | 59 |
msg = self.req._('you have been logged out') |
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
432
diff
changeset
|
60 |
w(u'<h2>%s</h2>\n' % msg) |
0 | 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>' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
64 |
xml_escape(indexurl), |
0 | 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' |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
82 |
__select__ = ~templatable_view() |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
83 |
|
823
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() |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
86 |
view.set_stream() |
2559
46859078c866
[R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2555
diff
changeset
|
87 |
if (self.req.form.has_key('__notemplate') and view.templatable |
46859078c866
[R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2555
diff
changeset
|
88 |
and view.content_type == self.req.html_content_type()): |
46859078c866
[R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2555
diff
changeset
|
89 |
view.w(self.req.document_surrounding_div()) |
2555
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() |
2559
46859078c866
[R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2555
diff
changeset
|
91 |
view.w(u'</div>') |
2555
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() |
2559
46859078c866
[R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2555
diff
changeset
|
94 |
# have to replace our stream by view's stream (which may be a binary |
46859078c866
[R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2555
diff
changeset
|
95 |
# stream) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
96 |
self._stream = view._stream |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
97 |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
98 |
|
0 | 99 |
class TheMainTemplate(MainTemplate): |
100 |
"""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
|
101 |
|
0 | 102 |
- call header / footer templates |
103 |
""" |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
104 |
id = 'main-template' |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
105 |
__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
|
106 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
107 |
def call(self, view): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
108 |
self.set_request_content_type() |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
109 |
self.template_header(self.content_type, view) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
110 |
w = self.w |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
111 |
w(u'<div id="pageContent">\n') |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
112 |
vtitle = self.req.form.get('vtitle') |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
113 |
if vtitle: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
114 |
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
|
115 |
# display entity type restriction component |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
116 |
etypefilter = self.vreg['components'].select_vobject( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
117 |
'etypenavigation', self.req, rset=self.rset) |
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
|
118 |
if etypefilter: |
1723 | 119 |
etypefilter.render(w=w) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
120 |
self.nav_html = UStringIO() |
872 | 121 |
if view and view.need_navigation: |
122 |
view.paginate(w=self.nav_html.write) |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
123 |
w(_(self.nav_html.getvalue())) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
124 |
w(u'<div id="contentmain">\n') |
1723 | 125 |
view.render(w=w) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
126 |
w(u'</div>\n') # close id=contentmain |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
127 |
w(_(self.nav_html.getvalue())) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
128 |
w(u'</div>\n') # closes id=pageContent |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
129 |
self.template_footer(view) |
0 | 130 |
|
131 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
132 |
page_title = page_title or view.page_title() |
|
133 |
additional_headers = additional_headers or view.html_headers() |
|
134 |
self.template_html_header(content_type, page_title, additional_headers) |
|
135 |
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
|
136 |
|
0 | 137 |
def template_html_header(self, content_type, page_title, additional_headers=()): |
138 |
w = self.whead |
|
139 |
lang = self.req.lang |
|
140 |
self.write_doctype() |
|
2580
6e9453fd11ef
always explicitly close <base> tags because of an old IE6 bug
Florent <florent@secondweb.fr>
parents:
2559
diff
changeset
|
141 |
# explictly close the <base> tag to avoid IE 6 bugs while browsing DOM |
6e9453fd11ef
always explicitly close <base> tags because of an old IE6 bug
Florent <florent@secondweb.fr>
parents:
2559
diff
changeset
|
142 |
w(u'<base href="%s"></base>' % xml_escape(self.req.base_url())) |
0 | 143 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
144 |
% (content_type, self.req.encoding)) |
|
145 |
w(u'\n'.join(additional_headers) + u'\n') |
|
819 | 146 |
self.wview('htmlheader', rset=self.rset) |
0 | 147 |
if page_title: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
148 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 149 |
|
150 |
def template_body_header(self, view): |
|
151 |
w = self.w |
|
152 |
w(u'<body>\n') |
|
819 | 153 |
self.wview('header', rset=self.rset, view=view) |
0 | 154 |
w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n') |
155 |
self.nav_column(view, 'left') |
|
156 |
w(u'<td id="contentcol">\n') |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
157 |
rqlcomp = self.vreg['components'].select_object('rqlinput', self.req, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
158 |
rset=self.rset) |
0 | 159 |
if rqlcomp: |
1723 | 160 |
rqlcomp.render(w=self.w, view=view) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
161 |
msgcomp = self.vreg['components'].select_object('applmessages', |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
162 |
self.req, rset=self.rset) |
0 | 163 |
if msgcomp: |
1723 | 164 |
msgcomp.render(w=self.w) |
0 | 165 |
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
|
166 |
|
0 | 167 |
def template_footer(self, view=None): |
168 |
self.content_footer(view) |
|
169 |
self.w(u'</td>\n') |
|
170 |
self.nav_column(view, 'right') |
|
171 |
self.w(u'</tr></table></div>\n') |
|
819 | 172 |
self.wview('footer', rset=self.rset) |
0 | 173 |
self.w(u'</body>') |
174 |
||
175 |
def nav_column(self, view, context): |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
176 |
boxes = list(self.vreg['boxes'].possible_vobjects( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
177 |
self.req, rset=self.rset, view=view, context=context)) |
0 | 178 |
if boxes: |
179 |
self.w(u'<td class="navcol"><div class="navboxes">\n') |
|
180 |
for box in boxes: |
|
1723 | 181 |
box.render(w=self.w, view=view) |
0 | 182 |
self.w(u'</div></td>\n') |
183 |
||
184 |
def content_header(self, view=None): |
|
185 |
"""by default, display informal messages in content header""" |
|
819 | 186 |
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
|
187 |
|
0 | 188 |
def content_footer(self, view=None): |
819 | 189 |
self.wview('contentfooter', rset=self.rset, view=view) |
0 | 190 |
|
191 |
||
192 |
class ErrorTemplate(TheMainTemplate): |
|
193 |
"""fallback template if an internal error occured during displaying the |
|
194 |
main template. This template may be called for authentication error, |
|
195 |
which means that req.cnx and req.user may not be set. |
|
196 |
""" |
|
832
8e06873d80d3
rename error template to avoid conflicts with the error view
sylvain.thenault@logilab.fr
parents:
828
diff
changeset
|
197 |
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
|
198 |
|
0 | 199 |
def call(self): |
200 |
"""display an unexpected error""" |
|
201 |
self.set_request_content_type() |
|
202 |
self.req.reset_headers() |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
203 |
view = self.vreg['views'].select('error', self.req, rset=self.rset) |
0 | 204 |
self.template_header(self.content_type, view, self.req._('an error occured'), |
205 |
[NOINDEX, NOFOLLOW]) |
|
1723 | 206 |
view.render(w=self.w) |
0 | 207 |
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
|
208 |
|
0 | 209 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
210 |
w = self.whead |
|
211 |
lang = self.req.lang |
|
212 |
self.write_doctype() |
|
213 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
214 |
% (content_type, self.req.encoding)) |
|
215 |
w(u'\n'.join(additional_headers)) |
|
819 | 216 |
self.wview('htmlheader', rset=self.rset) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
217 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 218 |
self.w(u'<body>\n') |
219 |
||
220 |
def template_footer(self, view=None): |
|
221 |
self.w(u'</body>') |
|
222 |
||
223 |
||
224 |
class SimpleMainTemplate(TheMainTemplate): |
|
225 |
||
226 |
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
|
227 |
|
163
451a3e35dbcb
repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
158
diff
changeset
|
228 |
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
|
229 |
page_title = page_title or view.page_title() |
0 | 230 |
additional_headers = additional_headers or view.html_headers() |
231 |
whead = self.whead |
|
232 |
lang = self.req.lang |
|
233 |
self.write_doctype() |
|
234 |
whead(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
235 |
% (content_type, self.req.encoding)) |
|
236 |
whead(u'\n'.join(additional_headers) + u'\n') |
|
819 | 237 |
self.wview('htmlheader', rset=self.rset) |
0 | 238 |
w = self.w |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
239 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 240 |
w(u'<body>\n') |
241 |
w(u'<div id="page">') |
|
242 |
w(u'<table width="100%" height="100%" border="0"><tr>\n') |
|
243 |
w(u'<td class="navcol">\n') |
|
244 |
self.topleft_header() |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
245 |
boxes = list(self.vreg['boxes'].possible_vobjects( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
246 |
self.req, rset=self.rset, view=view, context='left')) |
0 | 247 |
if boxes: |
248 |
w(u'<div class="navboxes">\n') |
|
249 |
for box in boxes: |
|
1723 | 250 |
box.render(w=w) |
0 | 251 |
self.w(u'</div>\n') |
252 |
w(u'</td>') |
|
253 |
w(u'<td id="contentcol" rowspan="2">') |
|
254 |
w(u'<div id="pageContent">\n') |
|
255 |
vtitle = self.req.form.get('vtitle') |
|
256 |
if vtitle: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
257 |
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
|
258 |
|
0 | 259 |
def topleft_header(self): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
260 |
logo = self.vreg['components'].select_vobject('logo', self.req, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
261 |
rset=self.rset) |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
self.w(u'</tr></table>\n') |
0 | 268 |
|
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
269 |
if can_do_pdf_conversion(): |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
270 |
from xml.etree.cElementTree import ElementTree |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
271 |
from subprocess import Popen as sub |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
272 |
from StringIO import StringIO |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
273 |
from tempfile import NamedTemporaryFile |
3080
32c2b6a34ab2
move xhtml2fo to ext, allow to specify the section in url/get param
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3071
diff
changeset
|
274 |
from cubicweb.ext.xhtml2fo import ReportTransformer |
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
275 |
|
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
276 |
class PdfMainTemplate(TheMainTemplate): |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
277 |
id = 'pdf-main-template' |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
278 |
|
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
279 |
def call(self, view): |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
280 |
"""build the standard view, then when it's all done, convert xhtml to pdf |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
281 |
""" |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
282 |
super(PdfMainTemplate, self).call(view) |
3080
32c2b6a34ab2
move xhtml2fo to ext, allow to specify the section in url/get param
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3071
diff
changeset
|
283 |
section = self.req.form.pop('section', 'contentmain') |
32c2b6a34ab2
move xhtml2fo to ext, allow to specify the section in url/get param
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3071
diff
changeset
|
284 |
pdf = self.to_pdf(self._stream, section) |
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
285 |
self.req.set_content_type('application/pdf', filename='report.pdf') |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
286 |
self.binary = True |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
287 |
self.w = None |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
288 |
self.set_stream() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
289 |
# pylint needs help |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
290 |
self.w(pdf) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
291 |
|
3080
32c2b6a34ab2
move xhtml2fo to ext, allow to specify the section in url/get param
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3071
diff
changeset
|
292 |
def to_pdf(self, stream, section): |
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
293 |
# XXX see ticket/345282 |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
294 |
stream = stream.getvalue().replace(' ', ' ').encode('utf-8') |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
295 |
xmltree = ElementTree() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
296 |
xmltree.parse(StringIO(stream)) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
297 |
foptree = ReportTransformer(section).transform(xmltree) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
298 |
foptmp = NamedTemporaryFile() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
299 |
pdftmp = NamedTemporaryFile() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
300 |
foptree.write(foptmp) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
301 |
foptmp.flush() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
302 |
fopproc = sub(['/usr/bin/fop', foptmp.name, pdftmp.name]) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
303 |
fopproc.wait() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
304 |
pdftmp.seek(0) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
305 |
pdf = pdftmp.read() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
306 |
return pdf |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
307 |
|
0 | 308 |
# page parts templates ######################################################## |
309 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
310 |
class HTMLHeader(View): |
0 | 311 |
"""default html headers""" |
312 |
id = 'htmlheader' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
313 |
|
0 | 314 |
def call(self, **kwargs): |
315 |
self.favicon() |
|
316 |
self.stylesheets() |
|
317 |
self.javascripts() |
|
318 |
self.alternates() |
|
319 |
self.pageid() |
|
320 |
||
321 |
def favicon(self): |
|
322 |
favicon = self.req.external_resource('FAVICON', None) |
|
323 |
if favicon: |
|
324 |
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
|
325 |
|
0 | 326 |
def stylesheets(self): |
327 |
req = self.req |
|
328 |
add_css = req.add_css |
|
329 |
for css in req.external_resource('STYLESHEETS'): |
|
330 |
add_css(css, localfile=False) |
|
331 |
for css in req.external_resource('STYLESHEETS_PRINT'): |
|
332 |
add_css(css, u'print', localfile=False) |
|
333 |
for css in req.external_resource('IE_STYLESHEETS'): |
|
334 |
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
|
335 |
|
0 | 336 |
def javascripts(self): |
337 |
for jscript in self.req.external_resource('JAVASCRIPTS'): |
|
338 |
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
|
339 |
|
0 | 340 |
def alternates(self): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
341 |
urlgetter = self.vreg['components'].select_object('rss_feed_url', |
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
|
342 |
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
|
343 |
if urlgetter is not None: |
0 | 344 |
self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n' |
2381 | 345 |
% xml_escape(urlgetter.feed_url())) |
0 | 346 |
|
347 |
def pageid(self): |
|
348 |
req = self.req |
|
349 |
pid = make_uid(id(req)) |
|
350 |
req.pageid = pid |
|
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
351 |
req.html_headers.define_var('pageid', pid) |
0 | 352 |
|
353 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
354 |
class HTMLPageHeader(View): |
0 | 355 |
"""default html page header""" |
356 |
id = 'header' |
|
3053
51f196c212d9
provide facility to override main header components without having to override the whole methode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3020
diff
changeset
|
357 |
main_cell_components = ('appliname', 'breadcrumbs') |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
358 |
|
0 | 359 |
def call(self, view, **kwargs): |
360 |
self.main_header(view) |
|
361 |
self.w(u''' |
|
362 |
<div id="stateheader">''') |
|
363 |
self.state_header() |
|
364 |
self.w(u''' |
|
365 |
</div> |
|
366 |
''') |
|
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 main_header(self, view): |
369 |
"""build the top menu with authentification info and the rql box""" |
|
370 |
self.w(u'<table id="header"><tr>\n') |
|
371 |
self.w(u'<td id="firstcolumn">') |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
372 |
logo = self.vreg['components'].select_vobject( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
373 |
'logo', self.req, rset=self.rset) |
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
|
374 |
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
|
375 |
logo.render(w=self.w) |
0 | 376 |
self.w(u'</td>\n') |
377 |
# appliname and breadcrumbs |
|
378 |
self.w(u'<td id="headtext">') |
|
3053
51f196c212d9
provide facility to override main header components without having to override the whole methode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3020
diff
changeset
|
379 |
for cid in self.main_cell_components: |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
380 |
comp = self.vreg['components'].select_vobject( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
381 |
cid, self.req, rset=self.rset) |
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
|
382 |
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
|
383 |
comp.render(w=self.w) |
0 | 384 |
self.w(u'</td>') |
385 |
# logged user and help |
|
386 |
self.w(u'<td>\n') |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
387 |
comp = self.vreg['components'].select_vobject( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
388 |
'loggeduserlink', self.req, rset=self.rset) |
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
|
389 |
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
|
390 |
comp.render(w=self.w) |
0 | 391 |
self.w(u'</td><td>') |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
392 |
helpcomp = self.vreg['components'].select_vobject( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
393 |
'help', self.req, rset=self.rset) |
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
|
394 |
if helpcomp: |
1723 | 395 |
helpcomp.render(w=self.w) |
0 | 396 |
self.w(u'</td>') |
397 |
# lastcolumn |
|
398 |
self.w(u'<td id="lastcolumn">') |
|
399 |
self.w(u'</td>\n') |
|
400 |
self.w(u'</tr></table>\n') |
|
819 | 401 |
self.wview('logform', rset=self.rset, id='popupLoginBox', klass='hidden', |
402 |
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
|
403 |
|
0 | 404 |
def state_header(self): |
405 |
state = self.req.search_state |
|
406 |
if state[0] == 'normal': |
|
407 |
return |
|
408 |
_ = self.req._ |
|
409 |
value = self.view('oneline', self.req.eid_rset(state[1][1])) |
|
410 |
msg = ' '.join((_("searching for"), |
|
411 |
display_name(self.req, state[1][3]), |
|
412 |
_("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
|
413 |
_("by relation"), '"', |
0 | 414 |
display_name(self.req, state[1][2], state[1][0]), |
415 |
'"')) |
|
416 |
return self.w(u'<div class="stateMessage">%s</div>' % msg) |
|
417 |
||
418 |
||
419 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
420 |
class HTMLPageFooter(View): |
0 | 421 |
"""default html page footer: include logo if any, and close the HTML body |
422 |
""" |
|
423 |
id = 'footer' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
424 |
|
0 | 425 |
def call(self, **kwargs): |
426 |
req = self.req |
|
427 |
self.w(u'<div class="footer">') |
|
428 |
# XXX Take object from the registry if in there? would be |
|
429 |
# better anyway |
|
430 |
from cubicweb.web.views.wdoc import ChangeLogView |
|
431 |
self.w(u'<a href="%s">%s</a> | ' % (req.build_url('changelog'), |
|
432 |
req._(ChangeLogView.title).lower())) |
|
433 |
self.w(u'<a href="%s">%s</a> | ' % (req.build_url('doc/about'), |
|
434 |
req._('about this site'))) |
|
3020
36c5f21c8de7
B in footer, replace "(c) Logilab" with "powered by CubicWeb"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2996
diff
changeset
|
435 |
self.w(u'<a href="http://www.cubicweb.org">%s</a>' % req._('powered by CubicWeb')) |
0 | 436 |
self.w(u'</div>') |
437 |
||
438 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
439 |
class HTMLContentHeader(View): |
0 | 440 |
"""default html page content header: |
441 |
* include message component if selectable for this request |
|
442 |
* include selectable content navigation components |
|
443 |
""" |
|
444 |
id = 'contentheader' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
445 |
|
0 | 446 |
def call(self, view, **kwargs): |
447 |
"""by default, display informal messages in content header""" |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
448 |
components = self.vreg['contentnavigation'].possible_vobjects( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
449 |
self.req, rset=self.rset, view=view, context='navtop') |
0 | 450 |
if components: |
451 |
self.w(u'<div id="contentheader">') |
|
452 |
for comp in components: |
|
1723 | 453 |
comp.render(w=self.w, view=view) |
0 | 454 |
self.w(u'</div><div class="clear"></div>') |
455 |
||
456 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
457 |
class HTMLContentFooter(View): |
0 | 458 |
"""default html page content footer: include selectable content navigation |
459 |
components |
|
460 |
""" |
|
461 |
id = 'contentfooter' |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
462 |
|
0 | 463 |
def call(self, view, **kwargs): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
464 |
components = self.vreg['contentnavigation'].possible_vobjects( |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2580
diff
changeset
|
465 |
self.req, rset=self.rset, view=view, context='navbottom') |
0 | 466 |
if components: |
467 |
self.w(u'<div id="contentfooter">') |
|
468 |
for comp in components: |
|
1723 | 469 |
comp.render(w=self.w, view=view) |
0 | 470 |
self.w(u'</div>') |
471 |
||
472 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
473 |
class LogFormTemplate(View): |
0 | 474 |
id = 'logform' |
826
51cb3d85c059
fix LogFormTemplate selector
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
475 |
__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
|
476 |
|
0 | 477 |
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
|
478 |
|
0 | 479 |
def call(self, id, klass, title=True, message=True): |
480 |
self.req.add_css('cubicweb.login.css') |
|
481 |
self.w(u'<div id="%s" class="%s">' % (id, klass)) |
|
482 |
if title: |
|
3166
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
483 |
stitle = self.req.property_value('ui.site-title') |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
484 |
if stitle: |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
485 |
stitle = xml_escape(stitle) |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
486 |
else: |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
487 |
stitle = u' ' |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
488 |
self.w(u'<div id="loginTitle">%s</div>' % stitle) |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
489 |
self.w(u'<div id="loginContent">\n') |
0 | 490 |
|
491 |
if message: |
|
492 |
self.display_message() |
|
493 |
if self.config['auth-mode'] == 'http': |
|
494 |
# HTTP authentication |
|
495 |
pass |
|
496 |
else: |
|
497 |
# Cookie authentication |
|
498 |
self.login_form(id) |
|
499 |
self.w(u'</div></div>\n') |
|
500 |
||
501 |
def display_message(self): |
|
502 |
message = self.req.message |
|
503 |
if message: |
|
504 |
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
|
505 |
|
0 | 506 |
def login_form(self, id): |
507 |
_ = self.req._ |
|
508 |
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
|
509 |
% xml_escape(login_form_url(self.config, self.req))) |
0 | 510 |
self.w(u'<table>\n') |
511 |
self.w(u'<tr>\n') |
|
1776
4be367276874
adapt login box message to allow-email-login configuration
Florent <florent@secondweb.fr>
parents:
1723
diff
changeset
|
512 |
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
|
513 |
self.w(u'<td><label for="__login">%s</label></td>' % msg) |
0 | 514 |
self.w(u'<td><input name="__login" id="__login" class="data" type="text" /></td>') |
515 |
self.w(u'</tr><tr>\n') |
|
516 |
self.w(u'<td><label for="__password" >%s</label></td>' % _('password')) |
|
517 |
self.w(u'<td><input name="__password" id="__password" class="data" type="password" /></td>\n') |
|
518 |
self.w(u'</tr><tr>\n') |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2657
diff
changeset
|
519 |
self.w(u'<td> </td><td><input type="submit" class="loginButton right" value="%s" />\n</td>' % _('log in')) |
0 | 520 |
self.w(u'</tr>\n') |
521 |
self.w(u'</table>\n') |
|
522 |
self.w(u'</form>\n') |
|
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
16
diff
changeset
|
523 |
self.req.html_headers.add_onload('jQuery("#__login:visible").focus()') |
0 | 524 |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
525 |
|
0 | 526 |
def login_form_url(config, req): |
527 |
if req.https: |
|
528 |
return req.url() |
|
529 |
if config.get('https-url'): |
|
530 |
return req.url().replace(req.base_url(), config['https-url']) |
|
531 |
return req.url() |
|
532 |
||
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
533 |
|
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
534 |
## vregistry registration callback ############################################ |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
535 |
def registration_callback(vreg): |
2936
f35b64718d02
follow name change, fix pdf template registration, add debian package tracking
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2935
diff
changeset
|
536 |
vreg.register_all(globals().values(), __name__) |