web/views/basetemplates.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 16 Feb 2010 09:27:15 +0100
changeset 4594 7b9824d1b734
parent 4279 e6b9fd79a247
child 4596 13fd398916c2
permissions -rw-r--r--
use an actual form for the login form ease customization from external cubes (eg rememberme)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
"""default templates for CubicWeb web client
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
:organization: Logilab
4212
ab6573088b4a update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3818
diff changeset
     5
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1851
diff changeset
     7
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
    11
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    13
from cubicweb.appobject import objectify_selector
822
e3d8db01f3f5 test_views fixes
sylvain.thenault@logilab.fr
parents: 820
diff changeset
    14
from cubicweb.selectors import match_kwargs
2061
6a5044f15cb9 [basetemplates] do not use STRICT_DOCTYPE directly, use self.doctype to deal with non xhtml browser
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    15
from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW
3816
37b376bb4088 [web] set pageid at request instanciation rather than in htmlheader template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3795
diff changeset
    16
from cubicweb.utils import UStringIO, can_do_pdf_conversion
3242
390acf7594ed missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3184
diff changeset
    17
from cubicweb.schema import display_name
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
    18
from cubicweb.web import formfields as ff, formwidgets as fw
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
    19
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
    20
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
# main templates ##############################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
    23
class LogInOutTemplate(MainTemplate):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
        self.set_request_content_type()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
        w = self.w
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
        self.write_doctype()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    29
        self.template_header('text/html', self._cw._('login_action'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
        w(u'<body>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
        self.content(w)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
        w(u'</body>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        w = self.whead
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        # 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
    37
        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
    38
        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
    39
          % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        w(NOINDEX)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
        w(NOFOLLOW)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
        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
    43
        self.wview('htmlheader', rset=self.cw_rset)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
    44
        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
    45
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
class LogInTemplate(LogInOutTemplate):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
    48
    __regid__ = 'login'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
    title = 'log in'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
    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
    52
        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
    53
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
class LoggedOutTemplate(LogInOutTemplate):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
    56
    __regid__ = 'loggedout'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
    title = 'logged out'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    def content(self, w):
852
105893288777 simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 432
diff changeset
    60
        # FIXME Deprecated code ?
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    61
        msg = self._cw._('you have been logged out')
852
105893288777 simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 432
diff changeset
    62
        w(u'<h2>%s</h2>\n' % msg)
3659
993997b4b41d 3.6 update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3655
diff changeset
    63
        if self._cw.vreg.config['anonymous-user']:
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    64
            indexurl = self._cw.build_url('view', vid='index', __message=msg)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
            w(u'<p><a href="%s">%s</a><p>' % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
    66
                xml_escape(indexurl),
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    67
                self._cw._('go back to the index page')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    69
@objectify_selector
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    70
def templatable_view(cls, req, rset, *args, **kwargs):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    71
    view = kwargs.pop('view', None)
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    72
    if view is None:
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    73
        return 1
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    74
    if view.binary:
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    75
        return 0
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    76
    if req.form.has_key('__notemplate'):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    77
        return 0
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    78
    return view.templatable
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    79
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    80
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    81
class NonTemplatableViewTemplate(MainTemplate):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    82
    """main template for any non templatable views (xml, binaries, etc.)"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
    83
    __regid__ = 'main-template'
1421
77ee26df178f doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents: 1149
diff changeset
    84
    __select__ = ~templatable_view()
77ee26df178f doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents: 1149
diff changeset
    85
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    86
    def call(self, view):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    87
        view.set_request_content_type()
1421
77ee26df178f doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents: 1149
diff changeset
    88
        view.set_stream()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    89
        if (self._cw.form.has_key('__notemplate') and view.templatable
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    90
            and view.content_type == self._cw.html_content_type()):
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    91
            view.w(self._cw.document_surrounding_div())
2555
ca7b122f34fa fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents: 2381
diff changeset
    92
            view.render()
2559
46859078c866 [R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2555
diff changeset
    93
            view.w(u'</div>')
2555
ca7b122f34fa fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents: 2381
diff changeset
    94
        else:
ca7b122f34fa fix html headers for forced html content type : main template and json controller
Fabrice <fabrice@secondweb.fr>
parents: 2381
diff changeset
    95
            view.render()
2559
46859078c866 [R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2555
diff changeset
    96
        # have to replace our stream by view's stream (which may be a binary
46859078c866 [R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2555
diff changeset
    97
        # stream)
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    98
        self._stream = view._stream
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
    99
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   100
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
class TheMainTemplate(MainTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    """default main template :
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   103
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
    - call header / footer templates
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   106
    __regid__ = 'main-template'
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   107
    __select__ = templatable_view()
1421
77ee26df178f doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents: 1149
diff changeset
   108
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   109
    def call(self, view):
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   110
        self.set_request_content_type()
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   111
        self.template_header(self.content_type, view)
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   112
        w = self.w
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   113
        w(u'<div id="pageContent">\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   114
        vtitle = self._cw.form.get('vtitle')
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   115
        if vtitle:
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
   116
            w(u'<h1 class="vtitle">%s</h1>\n' % xml_escape(vtitle))
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   117
        # display entity type restriction component
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   118
        etypefilter = self._cw.vreg['components'].select_or_none(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   119
            'etypenavigation', self._cw, rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   120
        if etypefilter and etypefilter.cw_propval('visible'):
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   121
            etypefilter.render(w=w)
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   122
        self.nav_html = UStringIO()
4244
2c3de1953d00 rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
   123
        if view:
872
78f03d6a1505 avoid deprecation warning
sylvain.thenault@logilab.fr
parents: 832
diff changeset
   124
            view.paginate(w=self.nav_html.write)
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   125
        w(_(self.nav_html.getvalue()))
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   126
        w(u'<div id="contentmain">\n')
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   127
        view.render(w=w)
823
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   128
        w(u'</div>\n') # close id=contentmain
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   129
        w(_(self.nav_html.getvalue()))
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   130
        w(u'</div>\n') # closes id=pageContent
cb8ccbef8fa5 main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 822
diff changeset
   131
        self.template_footer(view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
        page_title = page_title or view.page_title()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        additional_headers = additional_headers or view.html_headers()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
        self.template_html_header(content_type, page_title, additional_headers)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
        self.template_body_header(view)
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   138
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
    def template_html_header(self, content_type, page_title, additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        w = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   141
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
        self.write_doctype()
2580
6e9453fd11ef always explicitly close <base> tags because of an old IE6 bug
Florent <florent@secondweb.fr>
parents: 2559
diff changeset
   143
        # explictly close the <base> tag to avoid IE 6 bugs while browsing DOM
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   144
        w(u'<base href="%s"></base>' % xml_escape(self._cw.base_url()))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
        w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   146
          % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
        w(u'\n'.join(additional_headers) + u'\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   148
        self.wview('htmlheader', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
        if page_title:
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
   150
            w(u'<title>%s</title>\n' % xml_escape(page_title))
0
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_body_header(self, view):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
        w = self.w
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
        w(u'<body>\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   155
        self.wview('header', rset=self.cw_rset, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        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
   157
        self.nav_column(view, 'left')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
        w(u'<td id="contentcol">\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   159
        components = self._cw.vreg['components']
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   160
        rqlcomp = components.select_or_none('rqlinput', self._cw, rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
        if rqlcomp:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   162
            rqlcomp.render(w=self.w, view=view)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   163
        msgcomp = components.select_or_none('applmessages', self._cw, rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
        if msgcomp:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   165
            msgcomp.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        self.content_header(view)
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   167
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
    def template_footer(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
        self.content_footer(view)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
        self.w(u'</td>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
        self.nav_column(view, 'right')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        self.w(u'</tr></table></div>\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   173
        self.wview('footer', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
        self.w(u'</body>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
    def nav_column(self, view, context):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   177
        boxes = list(self._cw.vreg['boxes'].poss_visible_objects(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   178
            self._cw, rset=self.cw_rset, view=view, context=context))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
        if boxes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
            self.w(u'<td class="navcol"><div class="navboxes">\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
            for box in boxes:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   182
                box.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
            self.w(u'</div></td>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
    def content_header(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
        """by default, display informal messages in content header"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   187
        self.wview('contentheader', rset=self.cw_rset, view=view)
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   188
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
    def content_footer(self, view=None):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   190
        self.wview('contentfooter', rset=self.cw_rset, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
class ErrorTemplate(TheMainTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
    """fallback template if an internal error occured during displaying the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
    main template. This template may be called for authentication error,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
    which means that req.cnx and req.user may not be set.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   198
    __regid__ = 'error-template'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   199
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
        """display an unexpected error"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
        self.set_request_content_type()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   203
        self._cw.reset_headers()
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   204
        view = self._cw.vreg['views'].select('error', self._cw, rset=self.cw_rset)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   205
        self.template_header(self.content_type, view, self._cw._('an error occured'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
                             [NOINDEX, NOFOLLOW])
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   207
        view.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
        self.template_footer(view)
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   209
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
        w = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   212
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
        self.write_doctype()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
        w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   215
          % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
        w(u'\n'.join(additional_headers))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   217
        self.wview('htmlheader', rset=self.cw_rset)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
   218
        w(u'<title>%s</title>\n' % xml_escape(page_title))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
        self.w(u'<body>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
    def template_footer(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
        self.w(u'</body>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
class SimpleMainTemplate(TheMainTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   227
    __regid__ = 'main-no-top'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   228
163
451a3e35dbcb repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 158
diff changeset
   229
    def template_header(self, content_type, view=None, page_title='', additional_headers=()):
451a3e35dbcb repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 158
diff changeset
   230
        page_title = page_title or view.page_title()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
        additional_headers = additional_headers or view.html_headers()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
        whead = self.whead
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   233
        lang = self._cw.lang
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
        self.write_doctype()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
        whead(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   236
              % (content_type, self._cw.encoding))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
        whead(u'\n'.join(additional_headers) + u'\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   238
        self.wview('htmlheader', rset=self.cw_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
        w = self.w
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
   240
        w(u'<title>%s</title>\n' % xml_escape(page_title))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
        w(u'<body>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
        w(u'<div id="page">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
        w(u'<table width="100%" height="100%" border="0"><tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
        w(u'<td class="navcol">\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
        self.topleft_header()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   246
        boxes = list(self._cw.vreg['boxes'].poss_visible_objects(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   247
            self._cw, rset=self.cw_rset, view=view, context='left'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
        if boxes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
            w(u'<div class="navboxes">\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   250
            for box in boxes:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   251
                box.render(w=w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
        w(u'</td>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
        w(u'<td id="contentcol" rowspan="2">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
        w(u'<div id="pageContent">\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   256
        vtitle = self._cw.form.get('vtitle')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
        if vtitle:
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2119
diff changeset
   258
            w(u'<h1 class="vtitle">%s</h1>' % xml_escape(vtitle))
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   259
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
    def topleft_header(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   261
        logo = self._cw.vreg['components'].select_or_none('logo', self._cw,
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   262
                                                      rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   263
        if logo and logo.cw_propval('visible'):
2058
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   264
            self.w(u'<table id="header"><tr>\n')
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   265
            self.w(u'<td>')
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   266
            logo.render(w=self.w)
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   267
            self.w(u'</td>\n')
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   268
            self.w(u'</tr></table>\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   270
if can_do_pdf_conversion():
4254
966f62e97c72 Fix element tree import for python2.4
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4244
diff changeset
   271
    try:
966f62e97c72 Fix element tree import for python2.4
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4244
diff changeset
   272
      from xml.etree.cElementTree import ElementTree
966f62e97c72 Fix element tree import for python2.4
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4244
diff changeset
   273
    except ImportError: #python2.4
966f62e97c72 Fix element tree import for python2.4
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4244
diff changeset
   274
        from elementtree import ElementTree
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   275
    from subprocess import Popen as sub
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   276
    from StringIO import StringIO
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   277
    from tempfile import NamedTemporaryFile
3080
32c2b6a34ab2 move xhtml2fo to ext, allow to specify the section in url/get param
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3071
diff changeset
   278
    from cubicweb.ext.xhtml2fo import ReportTransformer
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   279
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   280
    class PdfMainTemplate(TheMainTemplate):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   281
        __regid__ = 'pdf-main-template'
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   282
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   283
        def call(self, view):
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   284
            """build the standard view, then when it's all done, convert xhtml to pdf
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   285
            """
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   286
            super(PdfMainTemplate, self).call(view)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   287
            section = self._cw.form.pop('section', 'contentmain')
3080
32c2b6a34ab2 move xhtml2fo to ext, allow to specify the section in url/get param
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3071
diff changeset
   288
            pdf = self.to_pdf(self._stream, section)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   289
            self._cw.set_content_type('application/pdf', filename='report.pdf')
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   290
            self.binary = True
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   291
            self.w = None
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   292
            self.set_stream()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   293
            # pylint needs help
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   294
            self.w(pdf)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   295
3080
32c2b6a34ab2 move xhtml2fo to ext, allow to specify the section in url/get param
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3071
diff changeset
   296
        def to_pdf(self, stream, section):
2935
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   297
            # XXX see ticket/345282
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   298
            stream = stream.getvalue().replace('&nbsp;', '&#160;').encode('utf-8')
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   299
            xmltree = ElementTree()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   300
            xmltree.parse(StringIO(stream))
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   301
            foptree = ReportTransformer(section).transform(xmltree)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   302
            foptmp = NamedTemporaryFile()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   303
            pdftmp = NamedTemporaryFile()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   304
            foptree.write(foptmp)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   305
            foptmp.flush()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   306
            fopproc = sub(['/usr/bin/fop', foptmp.name, pdftmp.name])
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   307
            fopproc.wait()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   308
            pdftmp.seek(0)
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   309
            pdf = pdftmp.read()
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   310
            return pdf
e06b3eadef31 [views,pdf] minimal support for xhtml->pdf conversion
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2657
diff changeset
   311
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
# page parts templates ########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   314
class HTMLHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
    """default html headers"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   316
    __regid__ = 'htmlheader'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   317
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
        self.favicon()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
        self.stylesheets()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
        self.javascripts()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
        self.alternates()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   324
    def favicon(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   325
        favicon = self._cw.external_resource('FAVICON', None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
        if favicon:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
            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
   328
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
    def stylesheets(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   330
        req = self._cw
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
        add_css = req.add_css
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
        for css in req.external_resource('STYLESHEETS'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
            add_css(css, localfile=False)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
        for css in req.external_resource('STYLESHEETS_PRINT'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   335
            add_css(css, u'print', localfile=False)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
        for css in req.external_resource('IE_STYLESHEETS'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
            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
   338
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
    def javascripts(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   340
        for jscript in self._cw.external_resource('JAVASCRIPTS'):
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   341
            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
   342
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
    def alternates(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   344
        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
   345
                                                           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
   346
        if urlgetter is not None:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
            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
   348
                       %  xml_escape(urlgetter.feed_url()))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   351
class HTMLPageHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
    """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
   353
    __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
   354
    main_cell_components = ('appliname', 'breadcrumbs')
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   355
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
    def call(self, view, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
        self.main_header(view)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
        self.w(u'''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   359
  <div id="stateheader">''')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   360
        self.state_header()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   361
        self.w(u'''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   362
  </div>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
  ''')
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   364
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
    def main_header(self, view):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
        """build the top menu with authentification info and the rql box"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
        self.w(u'<table id="header"><tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
        self.w(u'<td id="firstcolumn">')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   369
        logo = self._cw.vreg['components'].select_or_none(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   370
            'logo', self._cw, rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   371
        if logo and logo.cw_propval('visible'):
2058
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   372
            logo.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
        self.w(u'</td>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   374
        # appliname and breadcrumbs
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
        self.w(u'<td id="headtext">')
3053
51f196c212d9 provide facility to override main header components without having to override the whole methode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3020
diff changeset
   376
        for cid in self.main_cell_components:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   377
            comp = self._cw.vreg['components'].select_or_none(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   378
                cid, self._cw, rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   379
            if comp and comp.cw_propval('visible'):
2058
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   380
                comp.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
        self.w(u'</td>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   382
        # logged user and help
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   383
        self.w(u'<td>\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   384
        comp = self._cw.vreg['components'].select_or_none(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   385
            'loggeduserlink', self._cw, rset=self.cw_rset)
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2813
diff changeset
   386
        if comp and comp.cw_propval('visible'):
2058
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   387
            comp.render(w=self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   388
        self.w(u'</td>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
        # lastcolumn
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
        self.w(u'<td id="lastcolumn">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
        self.w(u'</td>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
        self.w(u'</tr></table>\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   393
        self.wview('logform', rset=self.cw_rset, id='popupLoginBox', klass='hidden',
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
   394
                   title=False, showmessage=False)
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   395
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
    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
   397
        state = self._cw.search_state
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   398
        if state[0] == 'normal':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   399
            return
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   400
        _ = self._cw._
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   401
        value = self.view('oneline', self._cw.eid_rset(state[1][1]))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   402
        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
   403
                        display_name(self._cw, state[1][3]),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
                        _("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
   405
                        _("by relation"), '"',
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   406
                        display_name(self._cw, state[1][2], state[1][0]),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
                        '"'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
        return self.w(u'<div class="stateMessage">%s</div>' % msg)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   410
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   412
class HTMLPageFooter(View):
3795
ce6381416a12 [doc] fix inaccurate docstring
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 3498
diff changeset
   413
    """default html page footer: include footer actions
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   414
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   415
    __regid__ = 'footer'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   416
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
    def call(self, **kwargs):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   418
        req = self._cw
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
        self.w(u'<div class="footer">')
3655
af86ab65a282 3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3503
diff changeset
   420
        actions = self._cw.vreg['actions'].possible_actions(self._cw,
af86ab65a282 3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3503
diff changeset
   421
                                                            rset=self.cw_rset)
3495
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   422
        footeractions = actions.get('footer', ())
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   423
        for i, action in enumerate(footeractions):
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   424
            self.w(u'<a href="%s">%s</a>' % (action.url(),
3655
af86ab65a282 3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3503
diff changeset
   425
                                             self._cw._(action.title)))
3495
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   426
            if i < (len(footeractions) - 1):
438576c5b1d1 [ui] turn footer items into actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3242
diff changeset
   427
                self.w(u' | ')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   428
        self.w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   429
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   430
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   431
class HTMLContentHeader(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   432
    """default html page content header:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   433
    * include message component if selectable for this request
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   434
    * include selectable content navigation components
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   435
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   436
    __regid__ = 'contentheader'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   437
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
    def call(self, view, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
        """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
   440
        components = self._cw.vreg['contentnavigation'].poss_visible_objects(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   441
            self._cw, rset=self.cw_rset, view=view, context='navtop')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
        if components:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   443
            self.w(u'<div id="contentheader">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   444
            for comp in components:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   445
                comp.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   446
            self.w(u'</div><div class="clear"></div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   447
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   448
816
9cd49a910fce kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   449
class HTMLContentFooter(View):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
    """default html page content footer: include selectable content navigation
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   451
    components
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   452
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   453
    __regid__ = 'contentfooter'
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   454
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   455
    def call(self, view, **kwargs):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   456
        components = self._cw.vreg['contentnavigation'].poss_visible_objects(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   457
            self._cw, rset=self.cw_rset, view=view, context='navbottom')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   458
        if components:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   459
            self.w(u'<div id="contentfooter">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   460
            for comp in components:
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1421
diff changeset
   461
                comp.render(w=self.w, view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   462
            self.w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   463
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   464
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
   465
class LogForm(forms.FieldsForm):
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   466
    __regid__ = 'logform'
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   467
    # XXX have to recall fields name since python is mangling __login/__password
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   468
    __login = ff.StringField('__login', widget=fw.TextInput({'class': 'data'}))
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   469
    __password = ff.StringField('__password', label=_('password'),
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   470
                                widget=fw.PasswordSingleInput({'class': 'data'}))
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   471
    form_buttons = [fw.SubmitButton(label=_('log in'),
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   472
                                    attrs={'class': 'loginButton right'})]
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   473
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   474
    @property
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   475
    def action(self):
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   476
        return xml_escape(login_form_url(self._cw))
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   477
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
   478
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
class LogFormView(View):
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):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   486
        self._cw.add_css('cubicweb.login.css')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   487
        self.w(u'<div id="%s" class="%s">' % (id, klass))
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;'
2413e5291e8d properly escape site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3053
diff changeset
   494
            self.w(u'<div id="loginTitle">%s</div>' % stitle)
641
ed668804af37 split main template into main template + page-content template
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 609
diff changeset
   495
        self.w(u'<div id="loginContent">\n')
4594
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   496
        if showmessage and self._cw.message:
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   497
            self.w(u'<div class="simpleMessage">%s</div>\n' % self._cw.message)
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   498
        if self._cw.vreg.config['auth-mode'] != 'http':
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   499
            # Cookie authentication
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
            self.login_form(id)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   501
        self.w(u'</div></div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   502
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
   503
    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
   504
        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
   505
        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
   506
        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
   507
            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
   508
        else:
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   509
            label = cw._('login')
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   510
        form.field_by_name('__login').label = label
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
        self.w(form.render(table_class=''))
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
        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
   513
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
   514
def login_form_url(req):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   515
    if req.https:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   516
        return req.url()
4594
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   517
    httpsurl = req.vreg.config.get('https-url')
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   518
    if httpsurl:
7b9824d1b734 use an actual form for the login form ease customization from external cubes (eg rememberme)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   519
        return req.url().replace(req.base_url(), httpsurl)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   520
    return req.url()