author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 23 Apr 2010 13:25:31 +0200 | |
changeset 5387 | aed0c441923a |
parent 5223 | 6abd6e3599f4 |
child 5423 | e15abfdcce38 |
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 |
4599 | 12 |
from logilab.common.deprecation import class_renamed |
0 | 13 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
14 |
from cubicweb.appobject import objectify_selector |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5195
diff
changeset
|
15 |
from cubicweb.selectors import match_kwargs, no_cnx |
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
|
16 |
from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW |
5195
e8235b2789fc
le patch move-pdf-export-to-cubes a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
17 |
from cubicweb.utils import UStringIO |
3242
390acf7594ed
missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
18 |
from cubicweb.schema import display_name |
4935
f710770e6e90
move pdf icon component with it's template so we don't see it when the template isn't available due to missing dependancies
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4781
diff
changeset
|
19 |
from cubicweb.web import component, formfields as ff, formwidgets as fw |
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
20 |
from cubicweb.web.views import forms |
2555
ca7b122f34fa
fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents:
2381
diff
changeset
|
21 |
|
0 | 22 |
# main templates ############################################################## |
23 |
||
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
24 |
class LogInOutTemplate(MainTemplate): |
0 | 25 |
|
26 |
def call(self): |
|
27 |
self.set_request_content_type() |
|
28 |
w = self.w |
|
29 |
self.write_doctype() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
30 |
self.template_header('text/html', self._cw._('login_action')) |
0 | 31 |
w(u'<body>\n') |
32 |
self.content(w) |
|
33 |
w(u'</body>') |
|
34 |
||
35 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
36 |
w = self.whead |
|
37 |
# 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
|
38 |
w(u'<base href="%s"></base>' % xml_escape(self._cw.base_url())) |
0 | 39 |
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
|
40 |
% (content_type, self._cw.encoding)) |
0 | 41 |
w(NOINDEX) |
42 |
w(NOFOLLOW) |
|
43 |
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
|
44 |
self.wview('htmlheader', rset=self.cw_rset) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
45 |
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
|
46 |
|
0 | 47 |
|
48 |
class LogInTemplate(LogInOutTemplate): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
49 |
__regid__ = 'login' |
0 | 50 |
title = 'log in' |
51 |
||
52 |
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
|
53 |
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
|
54 |
|
0 | 55 |
|
56 |
class LoggedOutTemplate(LogInOutTemplate): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
57 |
__regid__ = 'loggedout' |
0 | 58 |
title = 'logged out' |
59 |
||
60 |
def content(self, w): |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
432
diff
changeset
|
61 |
# FIXME Deprecated code ? |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
62 |
msg = self._cw._('you have been logged out') |
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
432
diff
changeset
|
63 |
w(u'<h2>%s</h2>\n' % msg) |
3659 | 64 |
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
|
65 |
indexurl = self._cw.build_url('view', vid='index', __message=msg) |
0 | 66 |
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
|
67 |
xml_escape(indexurl), |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
68 |
self._cw._('go back to the index page'))) |
0 | 69 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
70 |
@objectify_selector |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
71 |
def templatable_view(cls, req, rset, *args, **kwargs): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
72 |
view = kwargs.pop('view', None) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
73 |
if view is None: |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
74 |
return 1 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
75 |
if view.binary: |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
76 |
return 0 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
77 |
if req.form.has_key('__notemplate'): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
78 |
return 0 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
79 |
return view.templatable |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
80 |
|
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
81 |
class NonTemplatableViewTemplate(MainTemplate): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
82 |
"""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
|
83 |
__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
|
84 |
__select__ = ~templatable_view() |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
85 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
86 |
def call(self, view): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
87 |
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
|
88 |
view.set_stream() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
else: |
ca7b122f34fa
fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents:
2381
diff
changeset
|
95 |
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
|
96 |
# 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
|
97 |
# stream) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
98 |
self._stream = view._stream |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
99 |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
100 |
|
0 | 101 |
class TheMainTemplate(MainTemplate): |
102 |
"""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
|
103 |
|
0 | 104 |
- call header / footer templates |
105 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
106 |
__regid__ = 'main-template' |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
107 |
__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
|
108 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
109 |
def call(self, view): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
110 |
self.set_request_content_type() |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
111 |
self.template_header(self.content_type, view) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
112 |
w = self.w |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
113 |
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
|
114 |
vtitle = self._cw.form.get('vtitle') |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
115 |
if vtitle: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
116 |
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
|
117 |
# 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
|
118 |
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
|
119 |
'etypenavigation', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
120 |
if etypefilter and etypefilter.cw_propval('visible'): |
1723 | 121 |
etypefilter.render(w=w) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
122 |
self.nav_html = UStringIO() |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
123 |
if view: |
872 | 124 |
view.paginate(w=self.nav_html.write) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
125 |
w(_(self.nav_html.getvalue())) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
126 |
w(u'<div id="contentmain">\n') |
1723 | 127 |
view.render(w=w) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
128 |
w(u'</div>\n') # close id=contentmain |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
129 |
w(_(self.nav_html.getvalue())) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
130 |
w(u'</div>\n') # closes id=pageContent |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
131 |
self.template_footer(view) |
0 | 132 |
|
133 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
134 |
page_title = page_title or view.page_title() |
|
135 |
additional_headers = additional_headers or view.html_headers() |
|
136 |
self.template_html_header(content_type, page_title, additional_headers) |
|
137 |
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
|
138 |
|
0 | 139 |
def template_html_header(self, content_type, page_title, additional_headers=()): |
140 |
w = self.whead |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
141 |
lang = self._cw.lang |
0 | 142 |
self.write_doctype() |
2580
6e9453fd11ef
always explicitly close <base> tags because of an old IE6 bug
Florent <florent@secondweb.fr>
parents:
2559
diff
changeset
|
143 |
# 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
|
144 |
w(u'<base href="%s"></base>' % xml_escape(self._cw.base_url())) |
0 | 145 |
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
|
146 |
% (content_type, self._cw.encoding)) |
0 | 147 |
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
|
148 |
self.wview('htmlheader', rset=self.cw_rset) |
0 | 149 |
if page_title: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
150 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 151 |
|
152 |
def template_body_header(self, view): |
|
153 |
w = self.w |
|
154 |
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
|
155 |
self.wview('header', rset=self.cw_rset, view=view) |
0 | 156 |
w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n') |
157 |
self.nav_column(view, 'left') |
|
158 |
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
|
159 |
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
|
160 |
rqlcomp = components.select_or_none('rqlinput', self._cw, rset=self.cw_rset) |
0 | 161 |
if rqlcomp: |
1723 | 162 |
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
|
163 |
msgcomp = components.select_or_none('applmessages', self._cw, rset=self.cw_rset) |
0 | 164 |
if msgcomp: |
1723 | 165 |
msgcomp.render(w=self.w) |
0 | 166 |
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
|
167 |
|
0 | 168 |
def template_footer(self, view=None): |
169 |
self.content_footer(view) |
|
170 |
self.w(u'</td>\n') |
|
171 |
self.nav_column(view, 'right') |
|
172 |
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
|
173 |
self.wview('footer', rset=self.cw_rset) |
0 | 174 |
self.w(u'</body>') |
175 |
||
176 |
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
|
177 |
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
|
178 |
self._cw, rset=self.cw_rset, view=view, context=context)) |
0 | 179 |
if boxes: |
180 |
self.w(u'<td class="navcol"><div class="navboxes">\n') |
|
181 |
for box in boxes: |
|
1723 | 182 |
box.render(w=self.w, view=view) |
0 | 183 |
self.w(u'</div></td>\n') |
184 |
||
185 |
def content_header(self, view=None): |
|
186 |
"""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
|
187 |
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
|
188 |
|
0 | 189 |
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
|
190 |
self.wview('contentfooter', rset=self.cw_rset, view=view) |
0 | 191 |
|
192 |
||
193 |
class ErrorTemplate(TheMainTemplate): |
|
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5195
diff
changeset
|
194 |
"""fallback template if an internal error occured during displaying the main |
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5195
diff
changeset
|
195 |
template. This template may be called for authentication error, which means |
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5195
diff
changeset
|
196 |
that req.cnx and req.user may not be set. |
0 | 197 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
198 |
__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
|
199 |
|
0 | 200 |
def call(self): |
201 |
"""display an unexpected error""" |
|
202 |
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
|
203 |
self._cw.reset_headers() |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
204 |
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
|
205 |
self.template_header(self.content_type, view, self._cw._('an error occured'), |
0 | 206 |
[NOINDEX, NOFOLLOW]) |
1723 | 207 |
view.render(w=self.w) |
0 | 208 |
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
|
209 |
|
0 | 210 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
211 |
w = self.whead |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
212 |
lang = self._cw.lang |
0 | 213 |
self.write_doctype() |
214 |
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
|
215 |
% (content_type, self._cw.encoding)) |
0 | 216 |
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
|
217 |
self.wview('htmlheader', rset=self.cw_rset) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
218 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 219 |
self.w(u'<body>\n') |
220 |
||
221 |
def template_footer(self, view=None): |
|
222 |
self.w(u'</body>') |
|
223 |
||
224 |
||
225 |
class SimpleMainTemplate(TheMainTemplate): |
|
226 |
||
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
227 |
__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
|
228 |
|
163
451a3e35dbcb
repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
158
diff
changeset
|
229 |
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
|
230 |
page_title = page_title or view.page_title() |
0 | 231 |
additional_headers = additional_headers or view.html_headers() |
232 |
whead = self.whead |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
233 |
lang = self._cw.lang |
0 | 234 |
self.write_doctype() |
235 |
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
|
236 |
% (content_type, self._cw.encoding)) |
0 | 237 |
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
|
238 |
self.wview('htmlheader', rset=self.cw_rset) |
0 | 239 |
w = self.w |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
240 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 241 |
w(u'<body>\n') |
242 |
w(u'<div id="page">') |
|
243 |
w(u'<table width="100%" height="100%" border="0"><tr>\n') |
|
244 |
w(u'<td class="navcol">\n') |
|
245 |
self.topleft_header() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
246 |
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
|
247 |
self._cw, rset=self.cw_rset, view=view, context='left')) |
0 | 248 |
if boxes: |
249 |
w(u'<div class="navboxes">\n') |
|
250 |
for box in boxes: |
|
1723 | 251 |
box.render(w=w) |
0 | 252 |
self.w(u'</div>\n') |
253 |
w(u'</td>') |
|
254 |
w(u'<td id="contentcol" rowspan="2">') |
|
255 |
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
|
256 |
vtitle = self._cw.form.get('vtitle') |
0 | 257 |
if vtitle: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
258 |
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
|
259 |
|
0 | 260 |
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
|
261 |
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
|
262 |
rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
self.w(u'</tr></table>\n') |
0 | 269 |
|
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
270 |
|
0 | 271 |
# page parts templates ######################################################## |
272 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
273 |
class HTMLHeader(View): |
0 | 274 |
"""default html headers""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
275 |
__regid__ = 'htmlheader' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
276 |
|
0 | 277 |
def call(self, **kwargs): |
278 |
self.favicon() |
|
279 |
self.stylesheets() |
|
280 |
self.javascripts() |
|
281 |
self.alternates() |
|
282 |
||
283 |
def favicon(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
284 |
favicon = self._cw.external_resource('FAVICON', None) |
0 | 285 |
if favicon: |
286 |
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
|
287 |
|
0 | 288 |
def stylesheets(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
289 |
req = self._cw |
0 | 290 |
add_css = req.add_css |
291 |
for css in req.external_resource('STYLESHEETS'): |
|
292 |
add_css(css, localfile=False) |
|
293 |
for css in req.external_resource('STYLESHEETS_PRINT'): |
|
294 |
add_css(css, u'print', localfile=False) |
|
295 |
for css in req.external_resource('IE_STYLESHEETS'): |
|
296 |
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
|
297 |
|
0 | 298 |
def javascripts(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
299 |
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
|
300 |
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
|
301 |
|
0 | 302 |
def alternates(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
303 |
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
|
304 |
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
|
305 |
if urlgetter is not None: |
0 | 306 |
self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n' |
2381 | 307 |
% xml_escape(urlgetter.feed_url())) |
0 | 308 |
|
309 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
310 |
class HTMLPageHeader(View): |
0 | 311 |
"""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
|
312 |
__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
|
313 |
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
|
314 |
|
0 | 315 |
def call(self, view, **kwargs): |
316 |
self.main_header(view) |
|
317 |
self.w(u''' |
|
318 |
<div id="stateheader">''') |
|
319 |
self.state_header() |
|
320 |
self.w(u''' |
|
321 |
</div> |
|
322 |
''') |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
323 |
|
0 | 324 |
def main_header(self, view): |
325 |
"""build the top menu with authentification info and the rql box""" |
|
326 |
self.w(u'<table id="header"><tr>\n') |
|
327 |
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
|
328 |
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
|
329 |
'logo', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
330 |
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
|
331 |
logo.render(w=self.w) |
0 | 332 |
self.w(u'</td>\n') |
333 |
# appliname and breadcrumbs |
|
334 |
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
|
335 |
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
|
336 |
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
|
337 |
cid, self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
338 |
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
|
339 |
comp.render(w=self.w) |
0 | 340 |
self.w(u'</td>') |
341 |
# logged user and help |
|
342 |
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
|
343 |
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
|
344 |
'loggeduserlink', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
345 |
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
|
346 |
comp.render(w=self.w) |
0 | 347 |
self.w(u'</td>') |
348 |
# lastcolumn |
|
349 |
self.w(u'<td id="lastcolumn">') |
|
350 |
self.w(u'</td>\n') |
|
351 |
self.w(u'</tr></table>\n') |
|
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5195
diff
changeset
|
352 |
if self._cw.session.anonymous_session: |
4781
d12cbd0b7574
Suppress the hidden logform when the user is already connected
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4604
diff
changeset
|
353 |
self.wview('logform', rset=self.cw_rset, id='popupLoginBox', |
d12cbd0b7574
Suppress the hidden logform when the user is already connected
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4604
diff
changeset
|
354 |
klass='hidden', title=False, showmessage=False) |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
355 |
|
0 | 356 |
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
|
357 |
state = self._cw.search_state |
0 | 358 |
if state[0] == 'normal': |
359 |
return |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
360 |
_ = self._cw._ |
4604
96cc3d296d75
remove 3.6 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4603
diff
changeset
|
361 |
value = self._cw.view('oneline', self._cw.eid_rset(state[1][1])) |
0 | 362 |
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
|
363 |
display_name(self._cw, state[1][3]), |
0 | 364 |
_("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
|
365 |
_("by relation"), '"', |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
366 |
display_name(self._cw, state[1][2], state[1][0]), |
0 | 367 |
'"')) |
368 |
return self.w(u'<div class="stateMessage">%s</div>' % msg) |
|
369 |
||
370 |
||
371 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
372 |
class HTMLPageFooter(View): |
3795
ce6381416a12
[doc] fix inaccurate docstring
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3498
diff
changeset
|
373 |
"""default html page footer: include footer actions |
0 | 374 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
375 |
__regid__ = 'footer' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
376 |
|
0 | 377 |
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
|
378 |
req = self._cw |
0 | 379 |
self.w(u'<div class="footer">') |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3503
diff
changeset
|
380 |
actions = self._cw.vreg['actions'].possible_actions(self._cw, |
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3503
diff
changeset
|
381 |
rset=self.cw_rset) |
3495
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
382 |
footeractions = actions.get('footer', ()) |
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
383 |
for i, action in enumerate(footeractions): |
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
384 |
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
|
385 |
self._cw._(action.title))) |
3495
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
386 |
if i < (len(footeractions) - 1): |
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
387 |
self.w(u' | ') |
0 | 388 |
self.w(u'</div>') |
389 |
||
390 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
391 |
class HTMLContentHeader(View): |
0 | 392 |
"""default html page content header: |
393 |
* include message component if selectable for this request |
|
394 |
* include selectable content navigation components |
|
395 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
396 |
__regid__ = 'contentheader' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
397 |
|
0 | 398 |
def call(self, view, **kwargs): |
399 |
"""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
|
400 |
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
|
401 |
self._cw, rset=self.cw_rset, view=view, context='navtop') |
0 | 402 |
if components: |
403 |
self.w(u'<div id="contentheader">') |
|
404 |
for comp in components: |
|
1723 | 405 |
comp.render(w=self.w, view=view) |
0 | 406 |
self.w(u'</div><div class="clear"></div>') |
407 |
||
408 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
409 |
class HTMLContentFooter(View): |
0 | 410 |
"""default html page content footer: include selectable content navigation |
411 |
components |
|
412 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
413 |
__regid__ = 'contentfooter' |
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, view, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
416 |
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
|
417 |
self._cw, rset=self.cw_rset, view=view, context='navbottom') |
0 | 418 |
if components: |
419 |
self.w(u'<div id="contentfooter">') |
|
420 |
for comp in components: |
|
1723 | 421 |
comp.render(w=self.w, view=view) |
0 | 422 |
self.w(u'</div>') |
423 |
||
424 |
||
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
425 |
class LogForm(forms.FieldsForm): |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
426 |
__regid__ = 'logform' |
4596
13fd398916c2
specify login form dom id, don't render progress div
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4594
diff
changeset
|
427 |
domid = 'loginForm' |
4600
ae95c3241226
use needs_css so you can change login form css without redefining LogFormView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4599
diff
changeset
|
428 |
needs_css = ('cubicweb.login.css',) |
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
429 |
# XXX have to recall fields name since python is mangling __login/__password |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
430 |
__login = ff.StringField('__login', widget=fw.TextInput({'class': 'data'})) |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
431 |
__password = ff.StringField('__password', label=_('password'), |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
432 |
widget=fw.PasswordSingleInput({'class': 'data'})) |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
433 |
form_buttons = [fw.SubmitButton(label=_('log in'), |
4603
ce19b0a05db3
login form style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4600
diff
changeset
|
434 |
attrs={'class': 'loginButton'})] |
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
435 |
|
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
436 |
@property |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
437 |
def action(self): |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
438 |
return xml_escape(login_form_url(self._cw)) |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
439 |
|
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
440 |
|
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
441 |
class LogFormView(View): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
442 |
__regid__ = 'logform' |
826
51cb3d85c059
fix LogFormTemplate selector
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
443 |
__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
|
444 |
|
0 | 445 |
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
|
446 |
|
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
447 |
def call(self, id, klass, title=True, showmessage=True): |
0 | 448 |
self.w(u'<div id="%s" class="%s">' % (id, klass)) |
449 |
if title: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
450 |
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
|
451 |
if stitle: |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
452 |
stitle = xml_escape(stitle) |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
453 |
else: |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
454 |
stitle = u' ' |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
455 |
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
|
456 |
self.w(u'<div id="loginContent">\n') |
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
457 |
if showmessage and self._cw.message: |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
458 |
self.w(u'<div class="simpleMessage">%s</div>\n' % self._cw.message) |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
459 |
if self._cw.vreg.config['auth-mode'] != 'http': |
0 | 460 |
# Cookie authentication |
461 |
self.login_form(id) |
|
462 |
self.w(u'</div></div>\n') |
|
463 |
||
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
464 |
def login_form(self, id): |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
465 |
cw = self._cw |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
466 |
form = cw.vreg['forms'].select('logform', cw) |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
467 |
if cw.vreg.config['allow-email-login']: |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
468 |
label = cw._('login or email') |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
469 |
else: |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
470 |
label = cw._('login') |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
471 |
form.field_by_name('__login').label = label |
4596
13fd398916c2
specify login form dom id, don't render progress div
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4594
diff
changeset
|
472 |
self.w(form.render(table_class='', display_progress_div=False)) |
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
473 |
cw.html_headers.add_onload('jQuery("#__login:visible").focus()') |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
474 |
|
4599 | 475 |
LogFormTemplate = class_renamed('LogFormTemplate', LogFormView) |
476 |
||
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
477 |
def login_form_url(req): |
0 | 478 |
if req.https: |
479 |
return req.url() |
|
4594
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
480 |
httpsurl = req.vreg.config.get('https-url') |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
481 |
if httpsurl: |
7b9824d1b734
use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
482 |
return req.url().replace(req.base_url(), httpsurl) |
0 | 483 |
return req.url() |