web/views/basetemplates.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 15 Mar 2012 17:42:31 +0100
changeset 8311 76a44a0d7f4b
parent 8310 87f2f18a77ef
child 8324 75694a61f089
permissions -rw-r--r--
[login] split authentication logic from post authentication logic (closes #2200755) * The Session manager is now only in charge of providing a valid session. * LoginControllers are now used in all case but wrong credential. * The LoginControllers are in charge of redirecting the user to the page wanted to see in the first place, expected to see. * The login form is now always submitted to the login controller with an extra argument pointing to the url we should redirect too after successful authentication. The ``"log out first logic"`` logic on login controller is removed because: 1. Other web actor do not do that. 2. Removed code do not need to be reimplemented. 3. We can only get it to work again in a single case: use do a GET request on http://www.my-cw-stuff.io/login 4. I do not see it's purpose.
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
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    95
    if req.form.has_key('__notemplate'):
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()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   108
        if (self._cw.form.has_key('__notemplate') and view.templatable
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   109
            and view.content_type == self._cw.html_content_type()):
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   110
            view.w(self._cw.document_surrounding_div())
2555
ca7b122f34fa fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents: 2381
diff changeset
   111
            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
   112
            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
   113
        else:
ca7b122f34fa fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents: 2381
diff changeset
   114
            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
   115
        # 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
   116
        # stream)
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   117
        self._stream = view._stream
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   118
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   119
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
class TheMainTemplate(MainTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
    """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
   122
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
    - call header / footer templates
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   125
    __regid__ = 'main-template'
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   126
    __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
   127
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   128
    def call(self, view):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   129
        self.set_request_content_type()
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   130
        self.template_header(self.content_type, view)
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   131
        w = self.w
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   132
        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
   133
        vtitle = self._cw.form.get('vtitle')
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   134
        if vtitle:
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   135
            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
   136
        # 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
   137
        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
   138
            'etypenavigation', self._cw, rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   139
        if etypefilter and etypefilter.cw_propval('visible'):
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   140
            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
   141
        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
   142
        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
   143
            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
   144
        w(nav_html.getvalue())
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   145
        w(u'<div id="contentmain">\n')
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   146
        view.render(w=w)
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   147
        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
   148
        w(nav_html.getvalue())
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   149
        w(u'</div>\n') # closes id=pageContent
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   150
        self.template_footer(view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
        page_title = page_title or view.page_title()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
        additional_headers = additional_headers or view.html_headers()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
        self.template_html_header(content_type, page_title, additional_headers)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        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
   157
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
    def template_html_header(self, content_type, page_title, additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
        w = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   160
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
        self.write_doctype()
2580
6e9453fd11ef always explicitly close <base> tags because of an old IE6 bug
Florent <florent@secondweb.fr>
parents: 2559
diff changeset
   162
        # 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
   163
        self._cw.html_headers.define_var('BASE_URL', self._cw.base_url())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
        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
   165
          % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        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
   167
        self.wview('htmlheader', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        if page_title:
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
   169
            w(u'<title>%s</title>\n' % xml_escape(page_title))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
    def template_body_header(self, view):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        w = self.w
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
        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
   174
        self.wview('header', rset=self.cw_rset, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
        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
   176
        self.nav_column(view, 'left')
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5477
diff changeset
   177
        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
   178
        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
   179
        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
   180
        if rqlcomp:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   181
            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
   182
        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
   183
        if msgcomp:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   184
            msgcomp.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
        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
   186
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
    def template_footer(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
        self.content_footer(view)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
        self.w(u'</td>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
        self.nav_column(view, 'right')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
        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
   192
        self.wview('footer', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
        self.w(u'</body>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
    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
   196
        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
   197
            self._cw, rset=self.cw_rset, view=view, context=context))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
        if boxes:
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   199
            getlayout = self._cw.vreg['components'].select
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5477
diff changeset
   200
            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
   201
            for box in boxes:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   202
                box.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
            self.w(u'</div></td>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
    def content_header(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
        """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
   207
        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
   208
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
    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
   210
        self.wview('contentfooter', rset=self.cw_rset, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
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
   214
    """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
   215
    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
   216
    that req.cnx and req.user may not be set.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   218
    __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
   219
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
        """display an unexpected error"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
        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
   223
        self._cw.reset_headers()
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   224
        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
   225
        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
   226
                             [NOINDEX, NOFOLLOW])
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   227
        view.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
        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
   229
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
        w = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   232
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
        self.write_doctype()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
        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
   235
          % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
        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
   237
        self.wview('htmlheader', rset=self.cw_rset)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
   238
        w(u'<title>%s</title>\n' % xml_escape(page_title))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
        self.w(u'<body>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
    def template_footer(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
        self.w(u'</body>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
class SimpleMainTemplate(TheMainTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   247
    __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
   248
163
451a3e35dbcb repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 158
diff changeset
   249
    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
   250
        page_title = page_title or view.page_title()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
        additional_headers = additional_headers or view.html_headers()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
        whead = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   253
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
        self.write_doctype()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
        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
   256
              % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
        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
   258
        self.wview('htmlheader', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
        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
   260
        whead(u'<title>%s</title>\n' % xml_escape(page_title))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
        w(u'<body>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   262
        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
   263
        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
   264
        w(u'<td id="navColumnLeft">\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   265
        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
   266
        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
   267
            self._cw, rset=self.cw_rset, view=view, context='left'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
        if boxes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
            w(u'<div class="navboxes">\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
            for box in boxes:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   271
                box.render(w=w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
        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
   274
        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
   275
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
    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
   277
        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
   278
                                                          rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   279
        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
   280
            w = self.w
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   281
            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
   282
            w(u'<td>')
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   283
            logo.render(w=w)
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   284
            w(u'</td>\n')
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   285
            w(u'</tr></table>\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   286
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   287
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   288
# page parts templates ########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   289
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   290
class HTMLHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   291
    """default html headers"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   292
    __regid__ = 'htmlheader'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   293
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
        self.favicon()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
        self.stylesheets()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
        self.javascripts()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
        self.alternates()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
    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
   301
        favicon = self._cw.uiprops.get('FAVICON', None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
        if favicon:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
            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
   304
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
    def stylesheets(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   306
        req = self._cw
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
        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
   308
        for css in req.uiprops['STYLESHEETS']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
            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
   310
        for css in req.uiprops['STYLESHEETS_PRINT']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
            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
   312
        for css in req.uiprops['STYLESHEETS_IE']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
            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
   314
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
    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
   316
        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
   317
            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
   318
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
    def alternates(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   320
        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
   321
                                                           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
   322
        if urlgetter is not None:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
            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
   324
                       %  xml_escape(urlgetter.feed_url()))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   327
class HTMLPageHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
    """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
   329
    __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
   330
    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
   331
    headers = (('headtext', 'header-left'),
ffc644fafcb4 [basetemplates] define header ctx components categories as attribute to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6678
diff changeset
   332
               ('header-right', 'header-right'))
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   333
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
    def call(self, view, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   335
        self.main_header(view)
6091
560df423149a [login template] missing xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6005
diff changeset
   336
        self.w(u'<div id="stateheader">')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
        self.state_header()
6091
560df423149a [login template] missing xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6005
diff changeset
   338
        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
   339
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
    def main_header(self, view):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
        """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
   342
        w = self.w
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   343
        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
   344
        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
   345
            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
   346
            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
   347
                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
   348
            for comp in components:
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   349
                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
   350
                w(u'&#160;')
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   351
            w(u'</td>')
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   352
        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
   353
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
    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
   355
        state = self._cw.search_state
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
        if state[0] == 'normal':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
            return
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   358
        _ = self._cw._
4604
96cc3d296d75 remove 3.6 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4603
diff changeset
   359
        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
   360
        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
   361
                        display_name(self._cw, state[1][3]),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   362
                        _("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
   363
                        _("by relation"), '"',
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   364
                        display_name(self._cw, state[1][2], state[1][0]),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
                        '"'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
        return self.w(u'<div class="stateMessage">%s</div>' % msg)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   369
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
   370
    """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
   371
    __regid__ = 'footer'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   372
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
    def call(self, **kwargs):
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5477
diff changeset
   374
        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
   375
        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
   376
        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
   377
ce35c6f2f219 [footer template] refactor to ease addition of some content into the footer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6764
diff changeset
   378
    def footer_content(self):
3655
af86ab65a282 3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3503
diff changeset
   379
        actions = self._cw.vreg['actions'].possible_actions(self._cw,
af86ab65a282 3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3503
diff changeset
   380
                                                            rset=self.cw_rset)
3495
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   381
        footeractions = actions.get('footer', ())
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   382
        for i, action in enumerate(footeractions):
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   383
            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
   384
                                             self._cw._(action.title)))
3495
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   385
            if i < (len(footeractions) - 1):
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   386
                self.w(u' | ')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   387
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   388
class HTMLContentHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
    """default html page content header:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
    * include message component if selectable for this request
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
    * include selectable content navigation components
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   393
    __regid__ = 'contentheader'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   394
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   395
    def call(self, view, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
        """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
   397
        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
   398
            self._cw, rset=self.cw_rset, view=view, context='navtop')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   399
        if components:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   400
            self.w(u'<div id="contentheader">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   401
            for comp in components:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   402
                comp.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
            self.w(u'</div><div class="clear"></div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   406
class HTMLContentFooter(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
    """default html page content footer: include selectable content navigation
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
    components
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   410
    __regid__ = 'contentfooter'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   411
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   412
    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
   413
        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
   414
            self._cw, rset=self.cw_rset, view=view, context='navbottom')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
        if components:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
            self.w(u'<div id="contentfooter">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
            for comp in components:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   418
                comp.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
            self.w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   420
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   421
class BaseLogForm(forms.FieldsForm):
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   422
    """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
   423
    """
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   424
    __abstract__ = True
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   425
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
   426
    __regid__ = 'logform'
4596
13fd398916c2 specify login form dom id, don't render progress div
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4594
diff changeset
   427
    domid = 'loginForm'
4600
ae95c3241226 use needs_css so you can change login form css without redefining LogFormView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4599
diff changeset
   428
    needs_css = ('cubicweb.login.css',)
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   429
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   430
    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
   431
    onclick_args = (None, None)
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   432
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   433
    @classproperty
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   434
    def form_buttons(cls):
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   435
        # 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
   436
        # 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
   437
        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
   438
        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
   439
                                    attrs={'class': 'loginButton'}),
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   440
                        fw.ResetButton(label=_('cancel'),
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   441
                                       attrs={'class': 'loginButton',
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   442
                                              'onclick': onclick}),]
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   443
        ## 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
   444
        ## does not support items assignement.
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   445
        # 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
   446
        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
   447
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
   448
    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
   449
        if self.action is None:
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8310
diff changeset
   450
            # reuse existing redirection if it exist
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8310
diff changeset
   451
            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
   452
                                       self._cw.relative_path())
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8310
diff changeset
   453
            return self._cw.build_url('login', __secure__=True,
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8310
diff changeset
   454
                                      postlogin_path=target)
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
   455
        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
   456
8310
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   457
class LogForm(BaseLogForm):
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   458
    """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
   459
    """
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   460
    __regid__ = 'logform'
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   461
    domid = 'loginForm'
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   462
    needs_css = ('cubicweb.login.css',)
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   463
    # 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
   464
    __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
   465
    __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
   466
                                widget=fw.PasswordSingleInput({'class': 'data'}))
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   467
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   468
    onclick_args =  ('popupLoginBox', '__login')
87f2f18a77ef [LoginForm] refactor to ease other implementation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8307
diff changeset
   469
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
   470
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   471
class LogFormView(View):
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   472
    # 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
   473
    #     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
   474
    __regid__ = 'logform'
826
51cb3d85c059 fix LogFormTemplate selector
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 823
diff changeset
   475
    __select__ = match_kwargs('id', 'klass')
1421
77ee26df178f doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents: 1149
diff changeset
   476
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   477
    title = 'log in'
1421
77ee26df178f doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents: 1149
diff changeset
   478
4594
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   479
    def 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
   480
        w = self.w
6429
72669e7950c1 [login] fix some previously introduced login box css breakage
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6428
diff changeset
   481
        w(u'<div id="%s" class="%s">' % (id, klass))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
        if title:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   483
            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
   484
            if stitle:
2413e5291e8d properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3053
diff changeset
   485
                stitle = xml_escape(stitle)
2413e5291e8d properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3053
diff changeset
   486
            else:
2413e5291e8d properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3053
diff changeset
   487
                stitle = u'&#160;'
6389
72ba82a26e05 refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6225
diff changeset
   488
            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
   489
        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
   490
        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
   491
            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
   492
        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
   493
        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
   494
            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
   495
        w(u'</div>')
6005
0300fae1f7cb [views] link to public url when trying https without an account
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5988
diff changeset
   496
        if self._cw.https and config.anonymous_user()[0]:
6091
560df423149a [login template] missing xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6005
diff changeset
   497
            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
   498
            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
   499
              % (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
   500
        w(u'</div>\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   501
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
   502
    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
   503
        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
   504
        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
   505
        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
   506
            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
   507
        else:
5838
68187d50968e [login form] fix bad login field label by using pgettext
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5588
diff changeset
   508
            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
   509
        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
   510
        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
   511
        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
   512
4599
dafa39be525d bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4596
diff changeset
   513
LogFormTemplate = class_renamed('LogFormTemplate', LogFormView)