web/views/startup.py
author Julien Cristau <julien.cristau@logilab.fr>
Thu, 22 Mar 2012 11:50:34 +0100
changeset 8328 c53bbeea7870
parent 8190 2a3c1b787688
child 8349 fdb796435d7b
permissions -rw-r--r--
Add missing with_statement import for python2.5 compat
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
7990
a673d1d9a738 [diet] drop pre 3.6 API compatibility (but attempt to keep data cmopatibility). Closes #2017916
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7897
diff changeset
    34
from cubicweb.web import uicfg, httpcache
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
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
    37
    """:__regid__: *manage*
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    38
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    39
    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
    40
    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
    41
    management.
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    42
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    43
    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
    44
    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
    45
    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
    46
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
    47
    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
    48
    `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
    49
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
    50
    __regid__ = 'manage'
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    51
    title = _('manage')
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    52
    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
    53
    add_etype_links = ()
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    54
    skip_startup_views = set( ('index', 'manage', 'schema', 'owl', 'changelog',
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    55
                               'systempropertiesform', 'propertiesform',
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
    56
                               '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
    57
                               '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
    58
                               'siteinfo', 'info', 'registry', 'gc',
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    59
                               'tree') )
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    60
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
    def call(self, **kwargs):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2436
diff changeset
    62
        """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
    63
        self._cw.add_css('cubicweb.manageview.css')
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    64
        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
    65
        self.entities()
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    66
        self.manage_actions()
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    67
        self.startup_views()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    69
    def manage_actions(self):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    70
        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
    71
        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
    72
            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
    73
            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
    74
            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
    75
            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
    76
                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
    77
                    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
    78
            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
    79
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    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
    81
        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
    82
                 if v.category == 'startupview'
6971
33afb8748052 [manage view] fix skipping of startup views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6966
diff changeset
    83
                 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
    84
        if not views:
6ba3587c5cda [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 5478
diff changeset
    85
            return
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
    86
        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
    87
        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
    88
        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
    89
        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
    90
            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
    91
                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
    92
        self.w(u'</ul>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    93
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
    def entities(self):
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 3890
diff changeset
    95
        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
    96
        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
    97
                    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
    98
        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
    99
            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
   100
            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
   101
            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
   102
            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
   103
            self.w(u'</table>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   104
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    def entity_types_table(self, eschemas):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        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
   107
                       key=lambda (l,a,e): unormalize(l))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        q, r = divmod(len(infos), 2)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
        if r:
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2780
diff changeset
   110
            infos.append( (None, '&#160;', '&#160;') )
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        infos = zip(infos[:q+r], infos[q+r:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
        for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
            self.w(u'<tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
            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
   115
            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
   116
            self.w(u'</tr>\n')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   117
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
    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
   119
        """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
   120
        each entity types
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   122
        req = self._cw
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        for eschema in eschemas:
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   124
            if eschema.final or not eschema.may_have_permission('read', req):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
            etype = eschema.type
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
            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
   128
            if nb > 1:
a85db6fa9814 [mq]: plural_display_name_fix
Charles Hébert
parents: 4045
diff changeset
   129
                label = display_name(req, etype, 'plural')
a85db6fa9814 [mq]: plural_display_name_fix
Charles Hébert
parents: 4045
diff changeset
   130
            else:
a85db6fa9814 [mq]: plural_display_name_fix
Charles Hébert
parents: 4045
diff changeset
   131
                label = display_name(req, etype)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
            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
   133
            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
   134
            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
   135
                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
   136
            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
   137
                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
   138
            else:
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   139
                yield (label, etypelink, u'')
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   140
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   141
    def create_links(self):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   142
        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
   143
        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
   144
            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
   145
            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
   146
                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
   147
                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
   148
                        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
   149
        self.w(u'</ul>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   150
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
   151
    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
   152
        """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
   153
        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
   154
        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
   155
            xml_escape(url), self._cw.__('New %s' % etype))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   157
    @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
   158
    def display_folders(self):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   159
        return False
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   160
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   161
    @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
   162
    def folders(self):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   163
        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
   164
        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
   165
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   166
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
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
   168
    """:__regid__: *index*
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   169
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   170
    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
   171
    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
   172
    :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
   173
    customize this one.
defac26f4151 [book] startup views: add a note about *manage* view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7681
diff changeset
   174
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   175
    __regid__ = 'index'
2368
b41aef0e63a7 use msgid, update i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   176
    title = _('view_index')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   177
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6931
diff changeset
   178
    @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
   179
    def display_folders(self):
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 3890
diff changeset
   180
        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
   181