web/views/basetemplates.py
author Rémi Cardona <remi.cardona@logilab.fr>
Mon, 23 Sep 2013 11:13:28 +0200
branchstable
changeset 9239 dde9fe1e0ce3
parent 9176 8139f82c8bbe
child 9378 4a668dcfa0a0
permissions -rw-r--r--
[facets] Correctly replace old 'edit box' HTML on facet-induced page refresh (closes #3161100)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8009
diff changeset
     1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
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
# 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
     3
#
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
# 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
     5
#
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
# 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
     7
# 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
     8
# 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
     9
# 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
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# 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
    12
# 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
    13
# 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
    14
# 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
    15
#
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
# 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
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5584
c1823448f81d [web] disallow authenticated users to access to the login form (closes #914873)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    18
"""default templates for CubicWeb web client"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6453
diff changeset
    21
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
    23
from logilab.mtconverter import xml_escape
4599
dafa39be525d bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4596
diff changeset
    24
from logilab.common.deprecation import class_renamed
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8009
diff changeset
    25
from logilab.common.registry import objectify_predicate
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
    26
from logilab.common.decorators import classproperty
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8009
diff changeset
    28
from cubicweb.predicates import match_kwargs, no_cnx, anonymous_user
7432
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    29
from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW, StartupView
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
# main templates ##############################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        self.set_request_content_type()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
        w = self.w
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
        w(u'<body>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        self.content(w)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        w(u'</body>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
        w = self.whead
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        w(NOINDEX)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
        w(NOFOLLOW)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7432
diff changeset
    60
    def content(self):
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7432
diff changeset
    61
        raise NotImplementedError()
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7432
diff changeset
    62
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
class LogInTemplate(LogInOutTemplate):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
    65
    __regid__ = 'login'
5584
c1823448f81d [web] disallow authenticated users to access to the login form (closes #914873)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    66
    __select__ = anonymous_user()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
    title = 'log in'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    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
    70
        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
    71
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
7432
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    73
class LoggedOutTemplate(StartupView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
    74
    __regid__ = 'loggedout'
7432
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    75
    __select__ = anonymous_user()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
    title = 'logged out'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
7432
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    78
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    79
        msg = self._cw._('you have been logged out')
7432
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    80
        if self._cw.cnx:
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    81
            comp = self._cw.vreg['components'].select('applmessages', self._cw)
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    82
            comp.render(w=self.w, msg=msg)
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    83
            self.wview('index')
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    84
        else:
cab99ccdb774 [ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7428
diff changeset
    85
            self.w(u'<h2>%s</h2>' % msg)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
5584
c1823448f81d [web] disallow authenticated users to access to the login form (closes #914873)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    87
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8009
diff changeset
    88
@objectify_predicate
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    89
def templatable_view(cls, req, rset, *args, **kwargs):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    90
    view = kwargs.pop('view', None)
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    91
    if view is None:
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    92
        return 1
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    93
    if view.binary:
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    94
        return 0
8697
574bb05e40a4 [toward py3k] rewrite has_key() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8485
diff changeset
    95
    if '__notemplate' in req.form:
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    96
        return 0
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    97
    return view.templatable
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    98
6005
0300fae1f7cb [views] link to public url when trying https without an account
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5988
diff changeset
    99
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   100
class NonTemplatableViewTemplate(MainTemplate):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   101
    """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
   102
    __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
   103
    __select__ = ~templatable_view()
77ee26df178f doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents: 1149
diff changeset
   104
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   105
    def call(self, view):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   106
        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
   107
        view.set_stream()
8697
574bb05e40a4 [toward py3k] rewrite has_key() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8485
diff changeset
   108
        if (('__notemplate' in self._cw.form)
574bb05e40a4 [toward py3k] rewrite has_key() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8485
diff changeset
   109
            and view.templatable
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   110
            and view.content_type == self._cw.html_content_type()):
8974
c8520188eb4b [web request] drop no more necessary request.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8706
diff changeset
   111
            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
   112
            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
   113
            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
   114
        else:
ca7b122f34fa fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents: 2381
diff changeset
   115
            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
   116
        # 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
   117
        # stream)
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   118
        self._stream = view._stream
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   119
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   120
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
class TheMainTemplate(MainTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
    """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
   123
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
    - call header / footer templates
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   126
    __regid__ = 'main-template'
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   127
    __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
   128
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   129
    def call(self, view):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   130
        self.set_request_content_type()
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   131
        self.template_header(self.content_type, view)
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   132
        w = self.w
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   133
        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
   134
        vtitle = self._cw.form.get('vtitle')
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   135
        if vtitle:
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   136
            w(u'<div class="vtitle">%s</div>\n' % xml_escape(vtitle))
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   137
        # 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
   138
        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
   139
            'etypenavigation', self._cw, rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   140
        if etypefilter and etypefilter.cw_propval('visible'):
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   141
            etypefilter.render(w=w)
5988
d8ac8acd27f9 [basetemplate nav] no need for an attribute here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5854
diff changeset
   142
        nav_html = UStringIO()
8009
75638a6ff159 [tableview,basetemplates,pagination] some views internally handle the pagination, in which case the base template should not try to paginate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7879
diff changeset
   143
        if view and not view.handle_pagination:
5988
d8ac8acd27f9 [basetemplate nav] no need for an attribute here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5854
diff changeset
   144
            view.paginate(w=nav_html.write)
6178
9b596b11e375 remove buggy call to builtins._ on navigation content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   145
        w(nav_html.getvalue())
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   146
        w(u'<div id="contentmain">\n')
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   147
        view.render(w=w)
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   148
        w(u'</div>\n') # close id=contentmain
6178
9b596b11e375 remove buggy call to builtins._ on navigation content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   149
        w(nav_html.getvalue())
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   150
        w(u'</div>\n') # closes id=pageContent
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   151
        self.template_footer(view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
        page_title = page_title or view.page_title()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
        additional_headers = additional_headers or view.html_headers()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        self.template_html_header(content_type, page_title, additional_headers)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
        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
   158
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
    def template_html_header(self, content_type, page_title, additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
        w = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   161
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
        self.write_doctype()
2580
6e9453fd11ef always explicitly close <base> tags because of an old IE6 bug
Florent <florent@secondweb.fr>
parents: 2559
diff changeset
   163
        # explictly close the <base> tag to avoid IE 6 bugs while browsing DOM
7069
8bf2337a6f3b [views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6786
diff changeset
   164
        self._cw.html_headers.define_var('BASE_URL', self._cw.base_url())
9176
8139f82c8bbe [facets,js] fix bogus checkbox icon appearing after the first interaction (closes #2790332)
David Douard <david.douard@logilab.fr>
parents: 8974
diff changeset
   165
        self._cw.html_headers.define_var('DATA_URL', self._cw.datadir_url)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        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
   167
          % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        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
   169
        self.wview('htmlheader', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
        if page_title:
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
   171
            w(u'<title>%s</title>\n' % xml_escape(page_title))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    def template_body_header(self, view):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
        w = self.w
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
        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
   176
        self.wview('header', rset=self.cw_rset, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
        w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
        self.nav_column(view, 'left')
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5477
diff changeset
   179
        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
   180
        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
   181
        rqlcomp = components.select_or_none('rqlinput', self._cw, rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        if rqlcomp:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   183
            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
   184
        msgcomp = components.select_or_none('applmessages', self._cw, rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
        if msgcomp:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   186
            msgcomp.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        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
   188
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
    def template_footer(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
        self.content_footer(view)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
        self.w(u'</td>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
        self.nav_column(view, 'right')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
        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
   194
        self.wview('footer', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
        self.w(u'</body>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
    def nav_column(self, view, context):
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   198
        boxes = list(self._cw.vreg['ctxcomponents'].poss_visible_objects(
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   199
            self._cw, rset=self.cw_rset, view=view, context=context))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        if boxes:
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   201
            getlayout = self._cw.vreg['components'].select
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5477
diff changeset
   202
            self.w(u'<td id="navColumn%s"><div class="navboxes">\n' % context.capitalize())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
            for box in boxes:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   204
                box.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
            self.w(u'</div></td>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
    def content_header(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
        """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
   209
        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
   210
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
    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
   212
        self.wview('contentfooter', rset=self.cw_rset, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
class ErrorTemplate(TheMainTemplate):
6109
47d9c0e0f7b7 integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6091
diff changeset
   216
    """fallback template if an internal error occurred during displaying the main
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
   217
    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
   218
    that req.cnx and req.user may not be set.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   220
    __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
   221
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
        """display an unexpected error"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
        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
   225
        self._cw.reset_headers()
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   226
        view = self._cw.vreg['views'].select('error', self._cw, rset=self.cw_rset)
6109
47d9c0e0f7b7 integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6091
diff changeset
   227
        self.template_header(self.content_type, view, self._cw._('an error occurred'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
                             [NOINDEX, NOFOLLOW])
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   229
        view.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
        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
   231
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
        w = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   234
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
        self.write_doctype()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
        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
   237
          % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
        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
   239
        self.wview('htmlheader', rset=self.cw_rset)
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
        self.w(u'<body>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
    def template_footer(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
        self.w(u'</body>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
class SimpleMainTemplate(TheMainTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   249
    __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
   250
163
451a3e35dbcb repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 158
diff changeset
   251
    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
   252
        page_title = page_title or view.page_title()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
        additional_headers = additional_headers or view.html_headers()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
        whead = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   255
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
        self.write_doctype()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
        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
   258
              % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
        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
   260
        self.wview('htmlheader', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
        w = self.w
8269
80d37fb56312 [web templates] fix invalid html in main-no-top template; closes #2174806
Florent Cayré <florent.cayre@logilab.fr>
parents: 8009
diff changeset
   262
        whead(u'<title>%s</title>\n' % xml_escape(page_title))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
        w(u'<body>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   264
        w(u'<div id="page">')
8269
80d37fb56312 [web templates] fix invalid html in main-no-top template; closes #2174806
Florent Cayré <florent.cayre@logilab.fr>
parents: 8009
diff changeset
   265
        w(u'<table width="100%" border="0" id="mainLayout"><tr>\n')
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5477
diff changeset
   266
        w(u'<td id="navColumnLeft">\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
        self.topleft_header()
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   268
        boxes = list(self._cw.vreg['ctxcomponents'].poss_visible_objects(
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   269
            self._cw, rset=self.cw_rset, view=view, context='left'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
        if boxes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
            w(u'<div class="navboxes">\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
            for box in boxes:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   273
                box.render(w=w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
        w(u'</td>')
8269
80d37fb56312 [web templates] fix invalid html in main-no-top template; closes #2174806
Florent Cayré <florent.cayre@logilab.fr>
parents: 8009
diff changeset
   276
        w(u'<td id="contentColumn" rowspan="2">')
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   277
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   278
    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
   279
        logo = self._cw.vreg['components'].select_or_none('logo', self._cw,
5854
b49f58a320e6 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5849
diff changeset
   280
                                                          rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   281
        if logo and logo.cw_propval('visible'):
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   282
            w = self.w
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   283
            w(u'<table id="header"><tr>\n')
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   284
            w(u'<td>')
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   285
            logo.render(w=w)
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   286
            w(u'</td>\n')
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   287
            w(u'</tr></table>\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   288
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   289
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   290
# page parts templates ########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   291
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   292
class HTMLHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   293
    """default html headers"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   294
    __regid__ = 'htmlheader'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   295
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
        self.favicon()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
        self.stylesheets()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
        self.javascripts()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
        self.alternates()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
    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
   303
        favicon = self._cw.uiprops.get('FAVICON', None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
        if favicon:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
            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
   306
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
    def stylesheets(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   308
        req = self._cw
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
        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
   310
        for css in req.uiprops['STYLESHEETS']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
            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
   312
        for css in req.uiprops['STYLESHEETS_PRINT']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
            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
   314
        for css in req.uiprops['STYLESHEETS_IE']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
            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
   316
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
    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
   318
        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
   319
            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
   320
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
    def alternates(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   322
        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
   323
                                                           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
   324
        if urlgetter is not None:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
            self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n'
2381
caad2367d940 backport stable branch
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2144 2312
diff changeset
   326
                       %  xml_escape(urlgetter.feed_url()))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   329
class HTMLPageHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
    """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
   331
    __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
   332
    main_cell_components = ('appliname', 'breadcrumbs')
6697
ffc644fafcb4 [basetemplates] define header ctx components categories as attribute to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6678
diff changeset
   333
    headers = (('headtext', 'header-left'),
8326
2e793b2cdb57 [view] breadcrumbs layout broken with long elements (closes #1347486)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8324
diff changeset
   334
               ('header-center', 'header-center'),
2e793b2cdb57 [view] breadcrumbs layout broken with long elements (closes #1347486)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8324
diff changeset
   335
               ('header-right', 'header-right')
2e793b2cdb57 [view] breadcrumbs layout broken with long elements (closes #1347486)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8324
diff changeset
   336
               )
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   337
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   338
    def call(self, view, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
        self.main_header(view)
6091
560df423149a [login template] missing xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6005
diff changeset
   340
        self.w(u'<div id="stateheader">')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
        self.state_header()
6091
560df423149a [login template] missing xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6005
diff changeset
   342
        self.w(u'</div>')
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   343
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
    def main_header(self, view):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
        """build the top menu with authentification info and the rql box"""
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   346
        w = self.w
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   347
        w(u'<table id="header"><tr>\n')
6697
ffc644fafcb4 [basetemplates] define header ctx components categories as attribute to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6678
diff changeset
   348
        for colid, context in self.headers:
6428
de95bbed8781 [components] refactor main template header: make it much more flexible by using CtxComponent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6389
diff changeset
   349
            w(u'<td id="%s">' % colid)
de95bbed8781 [components] refactor main template header: make it much more flexible by using CtxComponent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6389
diff changeset
   350
            components = self._cw.vreg['ctxcomponents'].poss_visible_objects(
de95bbed8781 [components] refactor main template header: make it much more flexible by using CtxComponent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6389
diff changeset
   351
                self._cw, rset=self.cw_rset, view=view, context=context)
de95bbed8781 [components] refactor main template header: make it much more flexible by using CtxComponent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6389
diff changeset
   352
            for comp in components:
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   353
                comp.render(w=w)
6764
b2c1b481f310 [web/views/basetemplates] nbsp breaks tests, use #160 instead
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6697
diff changeset
   354
                w(u'&#160;')
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   355
            w(u'</td>')
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   356
        w(u'</tr></table>\n')
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   357
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
    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
   359
        state = self._cw.search_state
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   360
        if state[0] == 'normal':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   361
            return
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   362
        _ = self._cw._
4604
96cc3d296d75 remove 3.6 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4603
diff changeset
   363
        value = self._cw.view('oneline', self._cw.eid_rset(state[1][1]))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
        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
   365
                        display_name(self._cw, state[1][3]),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
                        _("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
   367
                        _("by relation"), '"',
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   368
                        display_name(self._cw, state[1][2], state[1][0]),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
                        '"'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
        return self.w(u'<div class="stateMessage">%s</div>' % msg)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   373
class HTMLPageFooter(View):
6786
ce35c6f2f219 [footer template] refactor to ease addition of some content into the footer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6764
diff changeset
   374
    """default html page footer: include footer actions"""
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
    def call(self, **kwargs):
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5477
diff changeset
   378
        self.w(u'<div id="footer">')
6786
ce35c6f2f219 [footer template] refactor to ease addition of some content into the footer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6764
diff changeset
   379
        self.footer_content()
ce35c6f2f219 [footer template] refactor to ease addition of some content into the footer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6764
diff changeset
   380
        self.w(u'</div>')
ce35c6f2f219 [footer template] refactor to ease addition of some content into the footer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6764
diff changeset
   381
ce35c6f2f219 [footer template] refactor to ease addition of some content into the footer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6764
diff changeset
   382
    def footer_content(self):
3655
af86ab65a282 3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3503
diff changeset
   383
        actions = self._cw.vreg['actions'].possible_actions(self._cw,
af86ab65a282 3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3503
diff changeset
   384
                                                            rset=self.cw_rset)
3495
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   385
        footeractions = actions.get('footer', ())
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   386
        for i, action in enumerate(footeractions):
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   387
            self.w(u'<a href="%s">%s</a>' % (action.url(),
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   388
                                             self._cw._(action.title)))
3495
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   389
            if i < (len(footeractions) - 1):
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   390
                self.w(u' | ')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   392
class HTMLContentHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   393
    """default html page content header:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   394
    * include message component if selectable for this request
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   395
    * include selectable content navigation components
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   397
    __regid__ = 'contentheader'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   398
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   399
    def call(self, view, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   400
        """by default, display informal messages in content header"""
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   401
        components = self._cw.vreg['ctxcomponents'].poss_visible_objects(
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   402
            self._cw, rset=self.cw_rset, view=view, context='navtop')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
        if components:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
            self.w(u'<div id="contentheader">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
            for comp in components:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   406
                comp.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
            self.w(u'</div><div class="clear"></div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   410
class HTMLContentFooter(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
    """default html page content footer: include selectable content navigation
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   412
    components
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   413
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   414
    __regid__ = 'contentfooter'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   415
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
    def call(self, view, **kwargs):
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   417
        components = self._cw.vreg['ctxcomponents'].poss_visible_objects(
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   418
            self._cw, rset=self.cw_rset, view=view, context='navbottom')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
        if components:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   420
            self.w(u'<div id="contentfooter">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   421
            for comp in components:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   422
                comp.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
            self.w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   424
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   425
class BaseLogForm(forms.FieldsForm):
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   426
    """Abstract Base login form to be used by any login form
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   427
    """
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   428
    __abstract__ = True
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   429
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
   430
    __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
   431
    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
   432
    needs_css = ('cubicweb.login.css',)
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   433
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   434
    onclick_base = "javascript: cw.htmlhelpers.popupLoginBox('%s', '%s');"
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   435
    onclick_args = (None, None)
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   436
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   437
    @classproperty
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   438
    def form_buttons(cls):
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   439
        # we use a property because sub class will need to define their own onclick_args.
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   440
        # Therefor we can't juste make the string formating when instanciating this class
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   441
        onclick = cls.onclick_base % cls.onclick_args
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   442
        form_buttons = [fw.SubmitButton(label=_('log in'),
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   443
                                    attrs={'class': 'loginButton'}),
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   444
                        fw.ResetButton(label=_('cancel'),
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   445
                                       attrs={'class': 'loginButton',
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   446
                                              'onclick': onclick}),]
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   447
        ## Can't shortcut next access because __dict__ is a "dictproxy" which 
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   448
        ## does not support items assignement.
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   449
        # cls.__dict__['form_buttons'] = form_buttons
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   450
        return form_buttons
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
   451
5588
377c9adfe81e [forms] refactor action handling to ease overriding while keeping action overrideable by instance (closes #969167)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5584
diff changeset
   452
    def form_action(self):
377c9adfe81e [forms] refactor action handling to ease overriding while keeping action overrideable by instance (closes #969167)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5584
diff changeset
   453
        if self.action is None:
8485
8de41063d629 [web login] fix after login redirection: redirect expect an url not a relative path. Breaks on cases like '?vid=aview'. Closes #2423575
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8326
diff changeset
   454
            # reuse existing redirection if it exists
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8310
diff changeset
   455
            target = self._cw.form.get('postlogin_path',
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8310
diff changeset
   456
                                       self._cw.relative_path())
8324
75694a61f089 [login redirect] only add postlogin_path argument when meaningful
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   457
            url_args = {}
75694a61f089 [login redirect] only add postlogin_path argument when meaningful
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   458
            if target and target != '/':
75694a61f089 [login redirect] only add postlogin_path argument when meaningful
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   459
                url_args['postlogin_path'] = target
75694a61f089 [login redirect] only add postlogin_path argument when meaningful
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   460
            return self._cw.build_url('login', __secure__=True, **url_args)
5588
377c9adfe81e [forms] refactor action handling to ease overriding while keeping action overrideable by instance (closes #969167)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5584
diff changeset
   461
        return super(LogForm, self).form_action()
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
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   463
class LogForm(BaseLogForm):
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   464
    """Simple login form that send username and password
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   465
    """
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   466
    __regid__ = 'logform'
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   467
    domid = 'loginForm'
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   468
    needs_css = ('cubicweb.login.css',)
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   469
    # XXX have to recall fields name since python is mangling __login/__password
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   470
    __login = ff.StringField('__login', widget=fw.TextInput({'class': 'data'}))
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   471
    __password = ff.StringField('__password', label=_('password'),
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   472
                                widget=fw.PasswordSingleInput({'class': 'data'}))
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   473
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   474
    onclick_args =  ('popupLoginBox', '__login')
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   475
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
   476
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
class LogFormView(View):
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   478
    # XXX an awfull lot of hardcoded assumptions there
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   479
    #     makes it unobvious to reuse/specialize
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   480
    __regid__ = 'logform'
826
51cb3d85c059 fix LogFormTemplate selector
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 823
diff changeset
   481
    __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
   482
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
    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
   484
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
   485
    def call(self, id, klass, title=True, showmessage=True):
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   486
        w = self.w
6429
72669e7950c1 [login] fix some previously introduced login box css breakage
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6428
diff changeset
   487
        w(u'<div id="%s" class="%s">' % (id, klass))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
        if title:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   489
            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
   490
            if stitle:
2413e5291e8d properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3053
diff changeset
   491
                stitle = xml_escape(stitle)
2413e5291e8d properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3053
diff changeset
   492
            else:
2413e5291e8d properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3053
diff changeset
   493
                stitle = u'&#160;'
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   494
            w(u'<div class="loginTitle">%s</div>' % stitle)
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   495
        w(u'<div class="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
   496
        if showmessage and self._cw.message:
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   497
            w(u'<div class="loginMessage">%s</div>\n' % self._cw.message)
6005
0300fae1f7cb [views] link to public url when trying https without an account
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5988
diff changeset
   498
        config = self._cw.vreg.config
0300fae1f7cb [views] link to public url when trying https without an account
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5988
diff changeset
   499
        if config['auth-mode'] != 'http':
0300fae1f7cb [views] link to public url when trying https without an account
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5988
diff changeset
   500
            self.login_form(id) # Cookie authentication
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   501
        w(u'</div>')
8706
e362054d9701 [login] don't redirect to http url if we allow anonymous on https
Julien Cristau <julien.cristau@logilab.fr>
parents: 8697
diff changeset
   502
        if self._cw.https and config.anonymous_user()[0] and config['https-deny-anonymous']:
6091
560df423149a [login template] missing xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6005
diff changeset
   503
            path = xml_escape(config['base-url'] + self._cw.relative_path())
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   504
            w(u'<div class="loginMessage"><a href="%s">%s</a></div>\n'
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   505
              % (path, self._cw._('No account? Try public access at %s') % path))
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   506
        w(u'</div>\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
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
   508
    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
   509
        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
   510
        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
   511
        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
   512
            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
   513
        else:
5838
68187d50968e [login form] fix bad login field label by using pgettext
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5588
diff changeset
   514
            label = cw.pgettext('CWUser', 'login')
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
   515
        form.field_by_name('__login').label = label
6453
7fdd780d87e4 [form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6429
diff changeset
   516
        form.render(w=self.w, 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
   517
        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
   518
4599
dafa39be525d bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4596
diff changeset
   519
LogFormTemplate = class_renamed('LogFormTemplate', LogFormView)