web/views/startup.py
author Julien Cristau <julien.cristau@logilab.fr>
Fri, 18 Jul 2014 12:23:01 +0200
changeset 9889 9b42e55e0686
parent 8665 e65af61bde7d
child 10007 727bbb361ed1
permissions -rw-r--r--
[web] Fix expiry of anonymous sessions (closes #4154479) Things like: try: foo except: bar else: baz doesn't work very well if you expect baz to run even in the exception case. Plus, session.cnx.check() is a dbapi remnant, so drop it and just look at session.mtime.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8169
f9fb7d903800 [manage/index view] fix sources management view appearing in index view although it should not; closes #2126335
Florent Cayré <florent.cayre@gmail.com>
parents: 7990
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
7897
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    18
"""This module contains the default index page and management view.
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    19
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    20
.. autoclass:: IndexView
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    21
.. autoclass:: ManageView
5839
53cbdc5e0426 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5530
diff changeset
    22
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
__docformat__ = "restructuredtext en"
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    25
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    27
from logilab.common.textutils import unormalize
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    28
from logilab.common.deprecation import deprecated
2387
ea1defea9636 [views] fix some crashers (schema still does not render properly, might be yams side)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2381
diff changeset
    29
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
1532
111c52e0022f duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents: 1523
diff changeset
    31
from cubicweb.view import StartupView
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8169
diff changeset
    32
from cubicweb.predicates import match_user_groups, is_instance
2436
44b2eea35efa move all schema related views where they belong (eg not startup), fix schema graph views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2387
diff changeset
    33
from cubicweb.schema import display_name
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8632
diff changeset
    34
from cubicweb.web import httpcache
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8632
diff changeset
    35
from cubicweb.web.views import uicfg
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
class ManageView(StartupView):
7897
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    38
    """:__regid__: *manage*
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    39
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    40
    The manage view, display some information about what's contained by your
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    41
    site and provides access to administration stuff such as user and groups
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    42
    management.
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    43
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    44
    Regarding the section displaying link to entity type, notice by default it
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    45
    won't display entity types which are related to another one using a
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    46
    mandatory (cardinality == 1) composite relation.
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    47
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    48
    You can still configure that behaviour manually using the
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    49
    `indexview_etype_section` as explained in :mod:`cubicweb.web.uicfg`.
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    50
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
    51
    __regid__ = 'manage'
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    52
    title = _('manage')
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    53
    http_cache_manager = httpcache.EtagHTTPCacheManager
3500
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    54
    add_etype_links = ()
8632
fa044b9157d7 Remove changelog view (closes #2423532)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8349
diff changeset
    55
    skip_startup_views = set( ('index', 'manage', 'schema', 'owl', 
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    56
                               'systempropertiesform', 'propertiesform',
8319
f6d455b9346f [manage / default index views] discard login/logout templates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8169
diff changeset
    57
                               'loggedout', 'login',
8169
f9fb7d903800 [manage/index view] fix sources management view appearing in index view although it should not; closes #2126335
Florent Cayré <florent.cayre@gmail.com>
parents: 7990
diff changeset
    58
                               'cw.users-and-groups-management', 'cw.groups-management', 
f9fb7d903800 [manage/index view] fix sources management view appearing in index view although it should not; closes #2126335
Florent Cayré <florent.cayre@gmail.com>
parents: 7990
diff changeset
    59
                               'cw.users-management', 'cw.sources-management',
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    60
                               'siteinfo', 'info', 'registry', 'gc',
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    61
                               'tree') )
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    62
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
    def call(self, **kwargs):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2436
diff changeset
    64
        """The default view representing the instance's management"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    65
        self._cw.add_css('cubicweb.manageview.css')
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    66
        self.w(u'<h1>%s</h1>' % self._cw.property_value('ui.site-title'))
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    67
        self.entities()
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    68
        self.manage_actions()
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    69
        self.startup_views()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    71
    def manage_actions(self):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    72
        allactions = self._cw.vreg['actions'].possible_actions(self._cw)
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    73
        if allactions.get('manage'):
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2780
diff changeset
    74
            self.w(u'<div class="hr">&#160;</div>')
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    75
            self.w(u'<h2>%s</h2>\n' % self._cw._('Manage'))
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    76
            self.w(u'<ul class="manageActions">')
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    77
            for action in allactions['manage']:
3500
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    78
                self.w(u'<li><a href="%s">%s</a></li>' % (
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    79
                    action.url(), self._cw._(action.title)))
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    80
            self.w(u'</ul>')
3500
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    81
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    def startup_views(self):
6966
0f45b1dad08d [manage view] filter before displaying anything avoid xhtml errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6962
diff changeset
    83
        views = [v for v in self._cw.vreg['views'].possible_views(self._cw, None)
0f45b1dad08d [manage view] filter before displaying anything avoid xhtml errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6962
diff changeset
    84
                 if v.category == 'startupview'
6971
33afb8748052 [manage view] fix skipping of startup views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6966
diff changeset
    85
                 and v.__regid__ not in self.skip_startup_views]
5479
6ba3587c5cda [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 5478
diff changeset
    86
        if not views:
6ba3587c5cda [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 5478
diff changeset
    87
            return
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    88
        self.w(u'<div class="hr">&#160;</div>')
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    89
        self.w(u'<h2>%s</h2>\n' % self._cw._('Startup views'))
5819
1017163825c7 [css] more css rework, need visual test in compat/new modes
katia
parents: 5718
diff changeset
    90
        self.w(u'<ul class="startup">')
5530
da21e3fbe240 [startup view] sort startup views by alphabetical order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    91
        for v in sorted(views, key=lambda x: self._cw._(x.title)):
5479
6ba3587c5cda [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 5478
diff changeset
    92
            self.w('<li><a href="%s">%s</a></li>' % (
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    93
                xml_escape(v.url()), xml_escape(self._cw._(v.title).capitalize())))
5479
6ba3587c5cda [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 5478
diff changeset
    94
        self.w(u'</ul>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    95
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
    def entities(self):
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 3890
diff changeset
    97
        schema = self._cw.vreg.schema
6973
d2cd38749c17 [manage view] get etypes first to avoid xhtml validation error if no one found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6971
diff changeset
    98
        eschemas = [eschema for eschema in schema.entities()
d2cd38749c17 [manage view] get etypes first to avoid xhtml validation error if no one found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6971
diff changeset
    99
                    if uicfg.indexview_etype_section.get(eschema) == 'application']
d2cd38749c17 [manage view] get etypes first to avoid xhtml validation error if no one found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6971
diff changeset
   100
        if eschemas:
d2cd38749c17 [manage view] get etypes first to avoid xhtml validation error if no one found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6971
diff changeset
   101
            self.w(u'<div class="hr">&#160;</div>')
d2cd38749c17 [manage view] get etypes first to avoid xhtml validation error if no one found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6971
diff changeset
   102
            self.w(u'<h2>%s</h2>\n' % self._cw._('Browse by entity type'))
d2cd38749c17 [manage view] get etypes first to avoid xhtml validation error if no one found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6971
diff changeset
   103
            self.w(u'<table class="startup">')
d2cd38749c17 [manage view] get etypes first to avoid xhtml validation error if no one found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6971
diff changeset
   104
            self.entity_types_table(eschemas)
d2cd38749c17 [manage view] get etypes first to avoid xhtml validation error if no one found
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6971
diff changeset
   105
            self.w(u'</table>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   106
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    def entity_types_table(self, eschemas):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        infos = sorted(self.entity_types(eschemas),
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   109
                       key=lambda (l,a,e): unormalize(l))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        q, r = divmod(len(infos), 2)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        if r:
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2780
diff changeset
   112
            infos.append( (None, '&#160;', '&#160;') )
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
        infos = zip(infos[:q+r], infos[q+r:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
        for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
            self.w(u'<tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
            self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink,  etypelink))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
            self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink2, etypelink2))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
            self.w(u'</tr>\n')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   119
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
    def entity_types(self, eschemas):
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   121
        """return an iterator on formatted links to get a list of entities of
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   122
        each entity types
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   124
        req = self._cw
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
        for eschema in eschemas:
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   126
            if eschema.final or not eschema.may_have_permission('read', req):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
            etype = eschema.type
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
            nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0]
4144
a85db6fa9814 [mq]: plural_display_name_fix
Charles Hébert
parents: 4045
diff changeset
   130
            if nb > 1:
a85db6fa9814 [mq]: plural_display_name_fix
Charles Hébert
parents: 4045
diff changeset
   131
                label = display_name(req, etype, 'plural')
a85db6fa9814 [mq]: plural_display_name_fix
Charles Hébert
parents: 4045
diff changeset
   132
            else:
a85db6fa9814 [mq]: plural_display_name_fix
Charles Hébert
parents: 4045
diff changeset
   133
                label = display_name(req, etype)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
            nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0]
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3457
diff changeset
   135
            url = self._cw.build_url(etype)
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2780
diff changeset
   136
            etypelink = u'&#160;<a href="%s">%s</a> (%d)' % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2265
diff changeset
   137
                xml_escape(url), label, nb)
6041
31776723c0c5 [index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   138
            if eschema.has_perm(req, 'add'):
31776723c0c5 [index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   139
                yield (label, etypelink, self.add_entity_link(etype))
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   140
            else:
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   141
                yield (label, etypelink, u'')
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   142
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   143
    def create_links(self):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   144
        self.w(u'<ul class="createLink">')
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   145
        for etype in self.add_etype_links:
7265
8eedf71f280e [deprecation] kill a remaining 3.6 warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6973
diff changeset
   146
            eschema = self._cw.vreg.schema.eschema(etype)
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   147
            if eschema.has_perm(self._cw, 'add'):
7681
32c4c9bab046 [index page] use 'New xxx' generated labels, 'add a xxx' labels are only generated according to inlined form configuration and with an associated context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7265
diff changeset
   148
                url = self._cw.vreg["etypes"].etype_class(etype).cw_create_url(self._cw)
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   149
                self.w(u'<li><a href="%s">%s</a></li>' % (
7681
32c4c9bab046 [index page] use 'New xxx' generated labels, 'add a xxx' labels are only generated according to inlined form configuration and with an associated context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7265
diff changeset
   150
                        url, self._cw.__('New %s' % eschema).capitalize()))
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   151
        self.w(u'</ul>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   152
6041
31776723c0c5 [index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   153
    def add_entity_link(self, etype):
31776723c0c5 [index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   154
        """creates a [+] link for adding an entity"""
31776723c0c5 [index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   155
        url = self._cw.vreg["etypes"].etype_class(etype).cw_create_url(self._cw)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        return u'[<a href="%s" title="%s">+</a>]' % (
7681
32c4c9bab046 [index page] use 'New xxx' generated labels, 'add a xxx' labels are only generated according to inlined form configuration and with an associated context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7265
diff changeset
   157
            xml_escape(url), self._cw.__('New %s' % etype))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   159
    @deprecated('[3.11] display_folders method is deprecated, backport it if needed')
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   160
    def display_folders(self):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   161
        return False
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   162
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   163
    @deprecated('[3.11] folders method is deprecated, backport it if needed')
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   164
    def folders(self):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   165
        self.w(u'<h2>%s</h2>\n' % self._cw._('Browse by category'))
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   166
        self._cw.vreg['views'].select('tree', self._cw).render(w=self.w, maxlevel=1)
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   167
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   168
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
class IndexView(ManageView):
7897
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   170
    """:__regid__: *index*
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   171
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   172
    The default index view, that you'll get when accessing your site's root url.
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   173
    It's by default indentical to the
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   174
    :class:`~cubicweb.web.views.startup.ManageView`, but you'll usually want to
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   175
    customize this one.
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   176
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   177
    __regid__ = 'index'
2368
b41aef0e63a7 use msgid, update i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   178
    title = _('view_index')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   179
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   180
    @deprecated('[3.11] display_folders method is deprecated, backport it if needed')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
    def display_folders(self):
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 3890
diff changeset
   182
        return 'Folder' in self._cw.vreg.schema and self._cw.execute('Any COUNT(X) WHERE X is Folder')[0][0]
2748
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   183