author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 25 May 2010 09:50:12 +0200 | |
changeset 5575 | 8a531340c3ef |
parent 5479 | 6ba3587c5cda |
child 5590 | a56eb02f9ce7 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4952
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
"""default templates for CubicWeb web client |
20 |
||
21 |
""" |
|
22 |
__docformat__ = "restructuredtext en" |
|
23 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
24 |
from logilab.mtconverter import xml_escape |
4599 | 25 |
from logilab.common.deprecation import class_renamed |
0 | 26 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
27 |
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
|
28 |
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
|
29 |
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
|
30 |
from cubicweb.utils import UStringIO |
3242
390acf7594ed
missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
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
|
34 |
|
0 | 35 |
# main templates ############################################################## |
36 |
||
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
37 |
class LogInOutTemplate(MainTemplate): |
0 | 38 |
|
39 |
def call(self): |
|
40 |
self.set_request_content_type() |
|
41 |
w = self.w |
|
42 |
self.write_doctype() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
43 |
self.template_header('text/html', self._cw._('login_action')) |
0 | 44 |
w(u'<body>\n') |
45 |
self.content(w) |
|
46 |
w(u'</body>') |
|
47 |
||
48 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
49 |
w = self.whead |
|
50 |
# 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
|
51 |
w(u'<base href="%s"></base>' % xml_escape(self._cw.base_url())) |
0 | 52 |
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
|
53 |
% (content_type, self._cw.encoding)) |
0 | 54 |
w(NOINDEX) |
55 |
w(NOFOLLOW) |
|
56 |
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
|
57 |
self.wview('htmlheader', rset=self.cw_rset) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
58 |
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
|
59 |
|
0 | 60 |
|
61 |
class LogInTemplate(LogInOutTemplate): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
62 |
__regid__ = 'login' |
0 | 63 |
title = 'log in' |
64 |
||
65 |
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
|
66 |
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
|
67 |
|
0 | 68 |
|
69 |
class LoggedOutTemplate(LogInOutTemplate): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
70 |
__regid__ = 'loggedout' |
0 | 71 |
title = 'logged out' |
72 |
||
73 |
def content(self, w): |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
432
diff
changeset
|
74 |
# FIXME Deprecated code ? |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
75 |
msg = self._cw._('you have been logged out') |
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
432
diff
changeset
|
76 |
w(u'<h2>%s</h2>\n' % msg) |
3659 | 77 |
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
|
78 |
indexurl = self._cw.build_url('view', vid='index', __message=msg) |
0 | 79 |
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
|
80 |
xml_escape(indexurl), |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
81 |
self._cw._('go back to the index page'))) |
0 | 82 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
83 |
@objectify_selector |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
84 |
def templatable_view(cls, req, rset, *args, **kwargs): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
85 |
view = kwargs.pop('view', None) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
86 |
if view is None: |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
87 |
return 1 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
88 |
if view.binary: |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
89 |
return 0 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
90 |
if req.form.has_key('__notemplate'): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
91 |
return 0 |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
92 |
return view.templatable |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
93 |
|
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
94 |
class NonTemplatableViewTemplate(MainTemplate): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
95 |
"""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
|
96 |
__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
|
97 |
__select__ = ~templatable_view() |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1149
diff
changeset
|
98 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
99 |
def call(self, view): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
100 |
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
|
101 |
view.set_stream() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
else: |
ca7b122f34fa
fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents:
2381
diff
changeset
|
108 |
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
|
109 |
# 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
|
110 |
# stream) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
111 |
self._stream = view._stream |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
112 |
|
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
113 |
|
0 | 114 |
class TheMainTemplate(MainTemplate): |
115 |
"""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
|
116 |
|
0 | 117 |
- call header / footer templates |
118 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
119 |
__regid__ = 'main-template' |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
120 |
__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
|
121 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
122 |
def call(self, view): |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
123 |
self.set_request_content_type() |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
124 |
self.template_header(self.content_type, view) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
125 |
w = self.w |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
126 |
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
|
127 |
vtitle = self._cw.form.get('vtitle') |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
128 |
if vtitle: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
129 |
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
|
130 |
# 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
|
131 |
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
|
132 |
'etypenavigation', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
133 |
if etypefilter and etypefilter.cw_propval('visible'): |
1723 | 134 |
etypefilter.render(w=w) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
135 |
self.nav_html = UStringIO() |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
136 |
if view: |
872 | 137 |
view.paginate(w=self.nav_html.write) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
138 |
w(_(self.nav_html.getvalue())) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
139 |
w(u'<div id="contentmain">\n') |
1723 | 140 |
view.render(w=w) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
141 |
w(u'</div>\n') # close id=contentmain |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
142 |
w(_(self.nav_html.getvalue())) |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
143 |
w(u'</div>\n') # closes id=pageContent |
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
822
diff
changeset
|
144 |
self.template_footer(view) |
0 | 145 |
|
146 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
|
147 |
page_title = page_title or view.page_title() |
|
148 |
additional_headers = additional_headers or view.html_headers() |
|
149 |
self.template_html_header(content_type, page_title, additional_headers) |
|
150 |
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
|
151 |
|
0 | 152 |
def template_html_header(self, content_type, page_title, additional_headers=()): |
153 |
w = self.whead |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
154 |
lang = self._cw.lang |
0 | 155 |
self.write_doctype() |
2580
6e9453fd11ef
always explicitly close <base> tags because of an old IE6 bug
Florent <florent@secondweb.fr>
parents:
2559
diff
changeset
|
156 |
# 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
|
157 |
w(u'<base href="%s"></base>' % xml_escape(self._cw.base_url())) |
0 | 158 |
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
|
159 |
% (content_type, self._cw.encoding)) |
0 | 160 |
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
|
161 |
self.wview('htmlheader', rset=self.cw_rset) |
0 | 162 |
if page_title: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
163 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 164 |
|
165 |
def template_body_header(self, view): |
|
166 |
w = self.w |
|
167 |
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
|
168 |
self.wview('header', rset=self.cw_rset, view=view) |
0 | 169 |
w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n') |
170 |
self.nav_column(view, 'left') |
|
5478
c52124b7a00e
[css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5477
diff
changeset
|
171 |
w(u'<td id="contentColumn">\n') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
172 |
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
|
173 |
rqlcomp = components.select_or_none('rqlinput', self._cw, rset=self.cw_rset) |
0 | 174 |
if rqlcomp: |
1723 | 175 |
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
|
176 |
msgcomp = components.select_or_none('applmessages', self._cw, rset=self.cw_rset) |
0 | 177 |
if msgcomp: |
1723 | 178 |
msgcomp.render(w=self.w) |
0 | 179 |
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
|
180 |
|
0 | 181 |
def template_footer(self, view=None): |
182 |
self.content_footer(view) |
|
183 |
self.w(u'</td>\n') |
|
184 |
self.nav_column(view, 'right') |
|
185 |
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
|
186 |
self.wview('footer', rset=self.cw_rset) |
0 | 187 |
self.w(u'</body>') |
188 |
||
189 |
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
|
190 |
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
|
191 |
self._cw, rset=self.cw_rset, view=view, context=context)) |
0 | 192 |
if boxes: |
5478
c52124b7a00e
[css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5477
diff
changeset
|
193 |
self.w(u'<td id="navColumn%s"><div class="navboxes">\n' % context.capitalize()) |
0 | 194 |
for box in boxes: |
1723 | 195 |
box.render(w=self.w, view=view) |
0 | 196 |
self.w(u'</div></td>\n') |
197 |
||
198 |
def content_header(self, view=None): |
|
199 |
"""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
|
200 |
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
|
201 |
|
0 | 202 |
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
|
203 |
self.wview('contentfooter', rset=self.cw_rset, view=view) |
0 | 204 |
|
205 |
||
206 |
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
|
207 |
"""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
|
208 |
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
|
209 |
that req.cnx and req.user may not be set. |
0 | 210 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
211 |
__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
|
212 |
|
0 | 213 |
def call(self): |
214 |
"""display an unexpected error""" |
|
215 |
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
|
216 |
self._cw.reset_headers() |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
217 |
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
|
218 |
self.template_header(self.content_type, view, self._cw._('an error occured'), |
0 | 219 |
[NOINDEX, NOFOLLOW]) |
1723 | 220 |
view.render(w=self.w) |
0 | 221 |
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
|
222 |
|
0 | 223 |
def template_header(self, content_type, view=None, page_title='', additional_headers=()): |
224 |
w = self.whead |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
225 |
lang = self._cw.lang |
0 | 226 |
self.write_doctype() |
227 |
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
|
228 |
% (content_type, self._cw.encoding)) |
0 | 229 |
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
|
230 |
self.wview('htmlheader', rset=self.cw_rset) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
231 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 232 |
self.w(u'<body>\n') |
233 |
||
234 |
def template_footer(self, view=None): |
|
235 |
self.w(u'</body>') |
|
236 |
||
237 |
||
238 |
class SimpleMainTemplate(TheMainTemplate): |
|
239 |
||
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
240 |
__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
|
241 |
|
163
451a3e35dbcb
repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
158
diff
changeset
|
242 |
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
|
243 |
page_title = page_title or view.page_title() |
0 | 244 |
additional_headers = additional_headers or view.html_headers() |
245 |
whead = self.whead |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
246 |
lang = self._cw.lang |
0 | 247 |
self.write_doctype() |
248 |
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
|
249 |
% (content_type, self._cw.encoding)) |
0 | 250 |
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
|
251 |
self.wview('htmlheader', rset=self.cw_rset) |
0 | 252 |
w = self.w |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
253 |
w(u'<title>%s</title>\n' % xml_escape(page_title)) |
0 | 254 |
w(u'<body>\n') |
255 |
w(u'<div id="page">') |
|
256 |
w(u'<table width="100%" height="100%" border="0"><tr>\n') |
|
5478
c52124b7a00e
[css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5477
diff
changeset
|
257 |
w(u'<td id="navColumnLeft">\n') |
0 | 258 |
self.topleft_header() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
259 |
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
|
260 |
self._cw, rset=self.cw_rset, view=view, context='left')) |
0 | 261 |
if boxes: |
262 |
w(u'<div class="navboxes">\n') |
|
263 |
for box in boxes: |
|
1723 | 264 |
box.render(w=w) |
0 | 265 |
self.w(u'</div>\n') |
266 |
w(u'</td>') |
|
267 |
w(u'<td id="contentcol" rowspan="2">') |
|
268 |
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
|
269 |
vtitle = self._cw.form.get('vtitle') |
0 | 270 |
if vtitle: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
271 |
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
|
272 |
|
0 | 273 |
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
|
274 |
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
|
275 |
rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
self.w(u'</tr></table>\n') |
0 | 282 |
|
2935
e06b3eadef31
[views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2657
diff
changeset
|
283 |
|
0 | 284 |
# page parts templates ######################################################## |
285 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
286 |
class HTMLHeader(View): |
0 | 287 |
"""default html headers""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
288 |
__regid__ = 'htmlheader' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
289 |
|
0 | 290 |
def call(self, **kwargs): |
291 |
self.favicon() |
|
292 |
self.stylesheets() |
|
293 |
self.javascripts() |
|
294 |
self.alternates() |
|
295 |
||
296 |
def favicon(self): |
|
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
297 |
favicon = self._cw.uiprops.get('FAVICON', None) |
0 | 298 |
if favicon: |
299 |
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
|
300 |
|
0 | 301 |
def stylesheets(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
302 |
req = self._cw |
0 | 303 |
add_css = req.add_css |
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
304 |
for css in req.uiprops['STYLESHEETS']: |
0 | 305 |
add_css(css, localfile=False) |
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
306 |
for css in req.uiprops['STYLESHEETS_PRINT']: |
0 | 307 |
add_css(css, u'print', localfile=False) |
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
308 |
for css in req.uiprops['STYLESHEETS_IE']: |
0 | 309 |
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
|
310 |
|
0 | 311 |
def javascripts(self): |
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
312 |
for jscript in self._cw.uiprops['JAVASCRIPTS']: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
313 |
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
|
314 |
|
0 | 315 |
def alternates(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
316 |
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
|
317 |
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
|
318 |
if urlgetter is not None: |
0 | 319 |
self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n' |
2381 | 320 |
% xml_escape(urlgetter.feed_url())) |
0 | 321 |
|
322 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
323 |
class HTMLPageHeader(View): |
0 | 324 |
"""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
|
325 |
__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
|
326 |
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
|
327 |
|
0 | 328 |
def call(self, view, **kwargs): |
329 |
self.main_header(view) |
|
330 |
self.w(u''' |
|
331 |
<div id="stateheader">''') |
|
332 |
self.state_header() |
|
333 |
self.w(u''' |
|
334 |
</div> |
|
335 |
''') |
|
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 main_header(self, view): |
338 |
"""build the top menu with authentification info and the rql box""" |
|
339 |
self.w(u'<table id="header"><tr>\n') |
|
340 |
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
|
341 |
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
|
342 |
'logo', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
343 |
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
|
344 |
logo.render(w=self.w) |
0 | 345 |
self.w(u'</td>\n') |
346 |
# appliname and breadcrumbs |
|
347 |
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
|
348 |
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
|
349 |
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
|
350 |
cid, self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
351 |
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
|
352 |
comp.render(w=self.w) |
0 | 353 |
self.w(u'</td>') |
354 |
# logged user and help |
|
355 |
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
|
356 |
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
|
357 |
'loggeduserlink', self._cw, rset=self.cw_rset) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
358 |
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
|
359 |
comp.render(w=self.w) |
0 | 360 |
self.w(u'</td>') |
361 |
# lastcolumn |
|
362 |
self.w(u'<td id="lastcolumn">') |
|
363 |
self.w(u'</td>\n') |
|
364 |
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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
|
0 | 369 |
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
|
370 |
state = self._cw.search_state |
0 | 371 |
if state[0] == 'normal': |
372 |
return |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
373 |
_ = self._cw._ |
4604
96cc3d296d75
remove 3.6 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4603
diff
changeset
|
374 |
value = self._cw.view('oneline', self._cw.eid_rset(state[1][1])) |
0 | 375 |
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
|
376 |
display_name(self._cw, state[1][3]), |
0 | 377 |
_("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
|
378 |
_("by relation"), '"', |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
379 |
display_name(self._cw, state[1][2], state[1][0]), |
0 | 380 |
'"')) |
381 |
return self.w(u'<div class="stateMessage">%s</div>' % msg) |
|
382 |
||
383 |
||
384 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
385 |
class HTMLPageFooter(View): |
3795
ce6381416a12
[doc] fix inaccurate docstring
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3498
diff
changeset
|
386 |
"""default html page footer: include footer actions |
0 | 387 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
388 |
__regid__ = 'footer' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
389 |
|
0 | 390 |
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
|
391 |
req = self._cw |
5478
c52124b7a00e
[css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5477
diff
changeset
|
392 |
self.w(u'<div id="footer">') |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3503
diff
changeset
|
393 |
actions = self._cw.vreg['actions'].possible_actions(self._cw, |
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3503
diff
changeset
|
394 |
rset=self.cw_rset) |
3495
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
395 |
footeractions = actions.get('footer', ()) |
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
396 |
for i, action in enumerate(footeractions): |
5477
f79c39be0b9b
[css] introducing scale and rhythm composition
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5467
diff
changeset
|
397 |
self.w(u'<a href="%s"' % action.url()) |
f79c39be0b9b
[css] introducing scale and rhythm composition
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5467
diff
changeset
|
398 |
if getattr(action, 'html_class'): |
f79c39be0b9b
[css] introducing scale and rhythm composition
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5467
diff
changeset
|
399 |
self.w(u' class="%s"' % action.html_class()) |
f79c39be0b9b
[css] introducing scale and rhythm composition
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5467
diff
changeset
|
400 |
self.w(u'>%s</a>' % self._cw._(action.title)) |
3495
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
401 |
if i < (len(footeractions) - 1): |
438576c5b1d1
[ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3242
diff
changeset
|
402 |
self.w(u' | ') |
0 | 403 |
self.w(u'</div>') |
404 |
||
405 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
406 |
class HTMLContentHeader(View): |
0 | 407 |
"""default html page content header: |
408 |
* include message component if selectable for this request |
|
409 |
* include selectable content navigation components |
|
410 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
411 |
__regid__ = 'contentheader' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
412 |
|
0 | 413 |
def call(self, view, **kwargs): |
414 |
"""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
|
415 |
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
|
416 |
self._cw, rset=self.cw_rset, view=view, context='navtop') |
0 | 417 |
if components: |
418 |
self.w(u'<div id="contentheader">') |
|
419 |
for comp in components: |
|
1723 | 420 |
comp.render(w=self.w, view=view) |
0 | 421 |
self.w(u'</div><div class="clear"></div>') |
422 |
||
423 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
424 |
class HTMLContentFooter(View): |
0 | 425 |
"""default html page content footer: include selectable content navigation |
426 |
components |
|
427 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
428 |
__regid__ = 'contentfooter' |
641
ed668804af37
split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
609
diff
changeset
|
429 |
|
0 | 430 |
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
|
431 |
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
|
432 |
self._cw, rset=self.cw_rset, view=view, context='navbottom') |
0 | 433 |
if components: |
434 |
self.w(u'<div id="contentfooter">') |
|
435 |
for comp in components: |
|
1723 | 436 |
comp.render(w=self.w, view=view) |
0 | 437 |
self.w(u'</div>') |
438 |
||
439 |
||
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
|
440 |
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
|
441 |
__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
|
442 |
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
|
443 |
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
|
444 |
# 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
|
445 |
__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
|
446 |
__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
|
447 |
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
|
448 |
form_buttons = [fw.SubmitButton(label=_('log in'), |
4603
ce19b0a05db3
login form style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4600
diff
changeset
|
449 |
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
|
450 |
|
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
|
451 |
@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
|
452 |
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
|
453 |
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
|
454 |
|
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
|
455 |
|
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
|
456 |
class LogFormView(View): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
457 |
__regid__ = 'logform' |
826
51cb3d85c059
fix LogFormTemplate selector
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
458 |
__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
|
459 |
|
0 | 460 |
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
|
461 |
|
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
|
462 |
def call(self, id, klass, title=True, showmessage=True): |
0 | 463 |
self.w(u'<div id="%s" class="%s">' % (id, klass)) |
464 |
if title: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
465 |
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
|
466 |
if stitle: |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
467 |
stitle = xml_escape(stitle) |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
468 |
else: |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
469 |
stitle = u' ' |
2413e5291e8d
properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3053
diff
changeset
|
470 |
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
|
471 |
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
|
472 |
if showmessage and self._cw.message: |
5479
6ba3587c5cda
[css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
5478
diff
changeset
|
473 |
self.w(u'<div class="loginMessage">%s</div>\n' % self._cw.message) |
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
|
474 |
if self._cw.vreg.config['auth-mode'] != 'http': |
0 | 475 |
# Cookie authentication |
476 |
self.login_form(id) |
|
477 |
self.w(u'</div></div>\n') |
|
478 |
||
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
|
479 |
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
|
480 |
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
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
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
|
487 |
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
|
488 |
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
|
489 |
|
4599 | 490 |
LogFormTemplate = class_renamed('LogFormTemplate', LogFormView) |
491 |
||
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
|
492 |
def login_form_url(req): |
0 | 493 |
if req.https: |
494 |
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
|
495 |
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
|
496 |
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
|
497 |
return req.url().replace(req.base_url(), httpsurl) |
0 | 498 |
return req.url() |