author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 09 Feb 2010 12:54:44 +0100 | |
changeset 4518 | 5690bf6d6081 |
parent 4279 | e6b9fd79a247 |
child 4594 | 7b9824d1b734 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
"""default templates for CubicWeb web client |
|
3 |
||
4 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3818
diff
changeset
|
5 |
:copyright: 2001-2010 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 |
3816
37b376bb4088
[web] set pageid at request instanciation rather than in htmlheader template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3795
diff
changeset
|
16 |
from cubicweb.utils import 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() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
27 |
self.template_header('text/html', self._cw._('login_action')) |
0 | 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 |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
35 |
w(u'<base href="%s"></base>' % xml_escape(self._cw.base_url())) |
0 | 36 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
37 |
% (content_type, self._cw.encoding)) |
0 | 38 |
w(NOINDEX) |
39 |
w(NOFOLLOW) |
|
40 |
w(u'\n'.join(additional_headers) + u'\n') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
41 |
self.wview('htmlheader', rset=self.cw_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): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
46 |
__regid__ = 'login' |
0 | 47 |
title = 'log in' |
48 |
||
49 |
def content(self, w): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
50 |
self.wview('logform', rset=self.cw_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): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
54 |
__regid__ = 'loggedout' |
0 | 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 ? |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
59 |
msg = self._cw._('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) |
3659 | 61 |
if self._cw.vreg.config['anonymous-user']: |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
62 |
indexurl = self._cw.build_url('view', vid='index', __message=msg) |
0 | 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), |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
65 |
self._cw._('go back to the index page'))) |
0 | 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.)""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
81 |
__regid__ = '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() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
87 |
if (self._cw.form.has_key('__notemplate') and view.templatable |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
88 |
and view.content_type == self._cw.html_content_type()): |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
89 |
view.w(self._cw.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 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
104 |
__regid__ = 'main-template' |
823
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') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
112 |
vtitle = self._cw.form.get('vtitle') |
823
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 |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
116 |
etypefilter = self._cw.vreg['components'].select_or_none( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
117 |
'etypenavigation', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
118 |
if etypefilter and etypefilter.cw_propval('visible'): |
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() |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
121 |
if view: |
872 | 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 |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
139 |
lang = self._cw.lang |
0 | 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 |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
142 |
w(u'<base href="%s"></base>' % xml_escape(self._cw.base_url())) |
0 | 143 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
144 |
% (content_type, self._cw.encoding)) |
0 | 145 |
w(u'\n'.join(additional_headers) + u'\n') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
146 |
self.wview('htmlheader', rset=self.cw_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') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
153 |
self.wview('header', rset=self.cw_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') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
157 |
components = self._cw.vreg['components'] |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
158 |
rqlcomp = components.select_or_none('rqlinput', self._cw, rset=self.cw_rset) |
0 | 159 |
if rqlcomp: |
1723 | 160 |
rqlcomp.render(w=self.w, view=view) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
161 |
msgcomp = components.select_or_none('applmessages', self._cw, rset=self.cw_rset) |
0 | 162 |
if msgcomp: |
1723 | 163 |
msgcomp.render(w=self.w) |
0 | 164 |
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
|
165 |
|
0 | 166 |
def template_footer(self, view=None): |
167 |
self.content_footer(view) |
|
168 |
self.w(u'</td>\n') |
|
169 |
self.nav_column(view, 'right') |
|
170 |
self.w(u'</tr></table></div>\n') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
171 |
self.wview('footer', rset=self.cw_rset) |
0 | 172 |
self.w(u'</body>') |
173 |
||
174 |
def nav_column(self, view, context): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
175 |
boxes = list(self._cw.vreg['boxes'].poss_visible_objects( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
176 |
self._cw, rset=self.cw_rset, view=view, context=context)) |
0 | 177 |
if boxes: |
178 |
self.w(u'<td class="navcol"><div class="navboxes">\n') |
|
179 |
for box in boxes: |
|
1723 | 180 |
box.render(w=self.w, view=view) |
0 | 181 |
self.w(u'</div></td>\n') |
182 |
||
183 |
def content_header(self, view=None): |
|
184 |
"""by default, display informal messages in content header""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
185 |
self.wview('contentheader', rset=self.cw_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
|
186 |
|
0 | 187 |
def content_footer(self, view=None): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
188 |
self.wview('contentfooter', rset=self.cw_rset, view=view) |
0 | 189 |
|
190 |
||
191 |
class ErrorTemplate(TheMainTemplate): |
|
192 |
"""fallback template if an internal error occured during displaying the |
|
193 |
main template. This template may be called for authentication error, |
|
194 |
which means that req.cnx and req.user may not be set. |
|
195 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
196 |
__regid__ = 'error-template' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
197 |
|
0 | 198 |
def call(self): |
199 |
"""display an unexpected error""" |
|
200 |
self.set_request_content_type() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
201 |
self._cw.reset_headers() |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
202 |
view = self._cw.vreg['views'].select('error', self._cw, rset=self.cw_rset) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
203 |
self.template_header(self.content_type, view, self._cw._('an error occured'), |
0 | 204 |
[NOINDEX, NOFOLLOW]) |
1723 | 205 |
view.render(w=self.w) |
0 | 206 |
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
|
207 |
|
0 | 208 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
209 |
w = self.whead |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
210 |
lang = self._cw.lang |
0 | 211 |
self.write_doctype() |
212 |
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
213 |
% (content_type, self._cw.encoding)) |
0 | 214 |
w(u'\n'.join(additional_headers)) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
215 |
self.wview('htmlheader', rset=self.cw_rset) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
216 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 217 |
self.w(u'<body>\n') |
218 |
||
219 |
def template_footer(self, view=None): |
|
220 |
self.w(u'</body>') |
|
221 |
||
222 |
||
223 |
class SimpleMainTemplate(TheMainTemplate): |
|
224 |
||
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
225 |
__regid__ = '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
|
226 |
|
163
451a3e35dbcb
repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
158
diff
changeset
|
227 |
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
|
228 |
page_title = page_title or view.page_title() |
0 | 229 |
additional_headers = additional_headers or view.html_headers() |
230 |
whead = self.whead |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
231 |
lang = self._cw.lang |
0 | 232 |
self.write_doctype() |
233 |
whead(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n' |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
234 |
% (content_type, self._cw.encoding)) |
0 | 235 |
whead(u'\n'.join(additional_headers) + u'\n') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
236 |
self.wview('htmlheader', rset=self.cw_rset) |
0 | 237 |
w = self.w |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
238 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 239 |
w(u'<body>\n') |
240 |
w(u'<div id="page">') |
|
241 |
w(u'<table width="100%" height="100%" border="0"><tr>\n') |
|
242 |
w(u'<td class="navcol">\n') |
|
243 |
self.topleft_header() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
244 |
boxes = list(self._cw.vreg['boxes'].poss_visible_objects( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
245 |
self._cw, rset=self.cw_rset, view=view, context='left')) |
0 | 246 |
if boxes: |
247 |
w(u'<div class="navboxes">\n') |
|
248 |
for box in boxes: |
|
1723 | 249 |
box.render(w=w) |
0 | 250 |
self.w(u'</div>\n') |
251 |
w(u'</td>') |
|
252 |
w(u'<td id="contentcol" rowspan="2">') |
|
253 |
w(u'<div id="pageContent">\n') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
254 |
vtitle = self._cw.form.get('vtitle') |
0 | 255 |
if vtitle: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
256 |
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
|
257 |
|
0 | 258 |
def topleft_header(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
259 |
logo = self._cw.vreg['components'].select_or_none('logo', self._cw, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
260 |
rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
261 |
if logo and logo.cw_propval('visible'): |
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 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
self.w(u'</tr></table>\n') |
0 | 267 |
|
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
268 |
if can_do_pdf_conversion(): |
4254
966f62e97c72
Fix element tree import for python2.4
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4244
diff
changeset
|
269 |
try: |
966f62e97c72
Fix element tree import for python2.4
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4244
diff
changeset
|
270 |
from xml.etree.cElementTree import ElementTree |
966f62e97c72
Fix element tree import for python2.4
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4244
diff
changeset
|
271 |
except ImportError: #python2.4 |
966f62e97c72
Fix element tree import for python2.4
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4244
diff
changeset
|
272 |
from elementtree import ElementTree |
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
273 |
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
|
274 |
from StringIO import StringIO |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
275 |
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
|
276 |
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
|
277 |
|
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
278 |
class PdfMainTemplate(TheMainTemplate): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
279 |
__regid__ = 'pdf-main-template' |
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
280 |
|
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
281 |
def call(self, view): |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
282 |
"""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
|
283 |
""" |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
284 |
super(PdfMainTemplate, self).call(view) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
285 |
section = self._cw.form.pop('section', 'contentmain') |
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
|
286 |
pdf = self.to_pdf(self._stream, section) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
287 |
self._cw.set_content_type('application/pdf', filename='report.pdf') |
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
288 |
self.binary = True |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
289 |
self.w = None |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
290 |
self.set_stream() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
291 |
# pylint needs help |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
292 |
self.w(pdf) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
293 |
|
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
|
294 |
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
|
295 |
# XXX see ticket/345282 |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
296 |
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
|
297 |
xmltree = ElementTree() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
298 |
xmltree.parse(StringIO(stream)) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
299 |
foptree = ReportTransformer(section).transform(xmltree) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
300 |
foptmp = NamedTemporaryFile() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
301 |
pdftmp = NamedTemporaryFile() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
302 |
foptree.write(foptmp) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
303 |
foptmp.flush() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
304 |
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
|
305 |
fopproc.wait() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
306 |
pdftmp.seek(0) |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
307 |
pdf = pdftmp.read() |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
308 |
return pdf |
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
309 |
|
0 | 310 |
# page parts templates ######################################################## |
311 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
312 |
class HTMLHeader(View): |
0 | 313 |
"""default html headers""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
314 |
__regid__ = 'htmlheader' |
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, **kwargs): |
317 |
self.favicon() |
|
318 |
self.stylesheets() |
|
319 |
self.javascripts() |
|
320 |
self.alternates() |
|
321 |
||
322 |
def favicon(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
323 |
favicon = self._cw.external_resource('FAVICON', None) |
0 | 324 |
if favicon: |
325 |
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
|
326 |
|
0 | 327 |
def stylesheets(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
328 |
req = self._cw |
0 | 329 |
add_css = req.add_css |
330 |
for css in req.external_resource('STYLESHEETS'): |
|
331 |
add_css(css, localfile=False) |
|
332 |
for css in req.external_resource('STYLESHEETS_PRINT'): |
|
333 |
add_css(css, u'print', localfile=False) |
|
334 |
for css in req.external_resource('IE_STYLESHEETS'): |
|
335 |
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
|
336 |
|
0 | 337 |
def javascripts(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
338 |
for jscript in self._cw.external_resource('JAVASCRIPTS'): |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
339 |
self._cw.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
|
340 |
|
0 | 341 |
def alternates(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
342 |
urlgetter = self._cw.vreg['components'].select_or_none('rss_feed_url', |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
343 |
self._cw, rset=self.cw_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
|
344 |
if urlgetter is not None: |
0 | 345 |
self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n' |
2381 | 346 |
% xml_escape(urlgetter.feed_url())) |
0 | 347 |
|
348 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
349 |
class HTMLPageHeader(View): |
0 | 350 |
"""default html page header""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
351 |
__regid__ = '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
|
352 |
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
|
353 |
|
0 | 354 |
def call(self, view, **kwargs): |
355 |
self.main_header(view) |
|
356 |
self.w(u''' |
|
357 |
<div id="stateheader">''') |
|
358 |
self.state_header() |
|
359 |
self.w(u''' |
|
360 |
</div> |
|
361 |
''') |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
362 |
|
0 | 363 |
def main_header(self, view): |
364 |
"""build the top menu with authentification info and the rql box""" |
|
365 |
self.w(u'<table id="header"><tr>\n') |
|
366 |
self.w(u'<td id="firstcolumn">') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
367 |
logo = self._cw.vreg['components'].select_or_none( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
368 |
'logo', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
369 |
if logo and logo.cw_propval('visible'): |
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
|
370 |
logo.render(w=self.w) |
0 | 371 |
self.w(u'</td>\n') |
372 |
# appliname and breadcrumbs |
|
373 |
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
|
374 |
for cid in self.main_cell_components: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
375 |
comp = self._cw.vreg['components'].select_or_none( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
376 |
cid, self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
377 |
if comp and comp.cw_propval('visible'): |
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
|
378 |
comp.render(w=self.w) |
0 | 379 |
self.w(u'</td>') |
380 |
# logged user and help |
|
381 |
self.w(u'<td>\n') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
382 |
comp = self._cw.vreg['components'].select_or_none( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
383 |
'loggeduserlink', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
384 |
if comp and comp.cw_propval('visible'): |
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
|
385 |
comp.render(w=self.w) |
0 | 386 |
self.w(u'</td>') |
387 |
# lastcolumn |
|
388 |
self.w(u'<td id="lastcolumn">') |
|
389 |
self.w(u'</td>\n') |
|
390 |
self.w(u'</tr></table>\n') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
391 |
self.wview('logform', rset=self.cw_rset, id='popupLoginBox', klass='hidden', |
819 | 392 |
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
|
393 |
|
0 | 394 |
def state_header(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
395 |
state = self._cw.search_state |
0 | 396 |
if state[0] == 'normal': |
397 |
return |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
398 |
_ = self._cw._ |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
399 |
value = self.view('oneline', self._cw.eid_rset(state[1][1])) |
0 | 400 |
msg = ' '.join((_("searching for"), |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
401 |
display_name(self._cw, state[1][3]), |
0 | 402 |
_("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
|
403 |
_("by relation"), '"', |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
404 |
display_name(self._cw, state[1][2], state[1][0]), |
0 | 405 |
'"')) |
406 |
return self.w(u'<div class="stateMessage">%s</div>' % msg) |
|
407 |
||
408 |
||
409 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
410 |
class HTMLPageFooter(View): |
3795
ce6381416a12
[doc] fix inaccurate docstring
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3498
diff
changeset
|
411 |
"""default html page footer: include footer actions |
0 | 412 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
413 |
__regid__ = 'footer' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
414 |
|
0 | 415 |
def call(self, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
416 |
req = self._cw |
0 | 417 |
self.w(u'<div class="footer">') |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3503
diff
changeset
|
418 |
actions = self._cw.vreg['actions'].possible_actions(self._cw, |
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3503
diff
changeset
|
419 |
rset=self.cw_rset) |
3495
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
420 |
footeractions = actions.get('footer', ()) |
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
421 |
for i, action in enumerate(footeractions): |
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
422 |
self.w(u'<a href="%s">%s</a>' % (action.url(), |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3503
diff
changeset
|
423 |
self._cw._(action.title))) |
3495
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
424 |
if i < (len(footeractions) - 1): |
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
425 |
self.w(u' | ') |
0 | 426 |
self.w(u'</div>') |
427 |
||
428 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
429 |
class HTMLContentHeader(View): |
0 | 430 |
"""default html page content header: |
431 |
* include message component if selectable for this request |
|
432 |
* include selectable content navigation components |
|
433 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
434 |
__regid__ = 'contentheader' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
435 |
|
0 | 436 |
def call(self, view, **kwargs): |
437 |
"""by default, display informal messages in content header""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
438 |
components = self._cw.vreg['contentnavigation'].poss_visible_objects( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
439 |
self._cw, rset=self.cw_rset, view=view, context='navtop') |
0 | 440 |
if components: |
441 |
self.w(u'<div id="contentheader">') |
|
442 |
for comp in components: |
|
1723 | 443 |
comp.render(w=self.w, view=view) |
0 | 444 |
self.w(u'</div><div class="clear"></div>') |
445 |
||
446 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
447 |
class HTMLContentFooter(View): |
0 | 448 |
"""default html page content footer: include selectable content navigation |
449 |
components |
|
450 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
451 |
__regid__ = 'contentfooter' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
452 |
|
0 | 453 |
def call(self, view, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
454 |
components = self._cw.vreg['contentnavigation'].poss_visible_objects( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
455 |
self._cw, rset=self.cw_rset, view=view, context='navbottom') |
0 | 456 |
if components: |
457 |
self.w(u'<div id="contentfooter">') |
|
458 |
for comp in components: |
|
1723 | 459 |
comp.render(w=self.w, view=view) |
0 | 460 |
self.w(u'</div>') |
461 |
||
462 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
463 |
class LogFormTemplate(View): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
464 |
__regid__ = 'logform' |
826
51cb3d85c059
fix LogFormTemplate selector
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
465 |
__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
|
466 |
|
0 | 467 |
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
|
468 |
|
0 | 469 |
def call(self, id, klass, title=True, message=True): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
470 |
self._cw.add_css('cubicweb.login.css') |
0 | 471 |
self.w(u'<div id="%s" class="%s">' % (id, klass)) |
472 |
if title: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
473 |
stitle = self._cw.property_value('ui.site-title') |
3166
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
474 |
if stitle: |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
475 |
stitle = xml_escape(stitle) |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
476 |
else: |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
477 |
stitle = u' ' |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
478 |
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
|
479 |
self.w(u'<div id="loginContent">\n') |
0 | 480 |
|
481 |
if message: |
|
482 |
self.display_message() |
|
3659 | 483 |
if self._cw.vreg.config['auth-mode'] == 'http': |
0 | 484 |
# HTTP authentication |
485 |
pass |
|
486 |
else: |
|
487 |
# Cookie authentication |
|
488 |
self.login_form(id) |
|
489 |
self.w(u'</div></div>\n') |
|
490 |
||
491 |
def display_message(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
492 |
message = self._cw.message |
0 | 493 |
if message: |
494 |
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
|
495 |
|
0 | 496 |
def login_form(self, id): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
497 |
_ = self._cw._ |
3661 | 498 |
# XXX turn into a form |
0 | 499 |
self.w(u'<form method="post" action="%s" id="login_form">\n' |
3659 | 500 |
% xml_escape(login_form_url(self._cw.vreg.config, self._cw))) |
0 | 501 |
self.w(u'<table>\n') |
3659 | 502 |
self.add_fields() |
0 | 503 |
self.w(u'<tr>\n') |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2657
diff
changeset
|
504 |
self.w(u'<td> </td><td><input type="submit" class="loginButton right" value="%s" />\n</td>' % _('log in')) |
0 | 505 |
self.w(u'</tr>\n') |
506 |
self.w(u'</table>\n') |
|
507 |
self.w(u'</form>\n') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
508 |
self._cw.html_headers.add_onload('jQuery("#__login:visible").focus()') |
0 | 509 |
|
3659 | 510 |
def add_fields(self): |
511 |
msg = (self._cw.vreg.config['allow-email-login'] and _('login or email')) or _('login') |
|
512 |
self.add_field('__login', msg, 'text') |
|
513 |
self.add_field('__password', self._cw._('password'), 'password') |
|
514 |
||
515 |
def add_field(self, name, label, inputtype): |
|
516 |
self.w(u'<tr>\n') |
|
517 |
self.w(u'<td><label for="%s" >%s</label></td>' % (name, label)) |
|
518 |
self.w(u'<td><input name="%s" id="%s" class="data" type="%s" /></td>\n' % |
|
519 |
(name, name, inputtype)) |
|
520 |
self.w(u'</tr>\n') |
|
0 | 521 |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
522 |
|
0 | 523 |
def login_form_url(config, req): |
524 |
if req.https: |
|
525 |
return req.url() |
|
526 |
if config.get('https-url'): |
|
527 |
return req.url().replace(req.base_url(), config['https-url']) |
|
528 |
return req.url() |