web/views/startup.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 07 Oct 2009 11:45:54 +0200
branchstable
changeset 3588 b7a125f0059c
parent 3500 ab10d1cb53ff
child 3503 06bced8edddf
child 3689 deb13e88e037
permissions -rw-r--r--
merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""Set of HTML startup views. A startup view is global, e.g. doesn't
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
apply to a result set.
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
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1739
diff changeset
     5
:copyright: 2001-2009 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: 1739
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"
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    10
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    12
from logilab.common.textutils import unormalize
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
    13
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
1532
111c52e0022f duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents: 1523
diff changeset
    15
from cubicweb.view import StartupView
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    16
from cubicweb.selectors import match_user_groups, implements
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
    17
from cubicweb.schema import display_name
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1631
diff changeset
    18
from cubicweb.web import ajax_replace_url, uicfg, httpcache
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
class ManageView(StartupView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
    id = 'manage'
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    22
    title = _('manage')
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    23
    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
    24
    add_etype_links = ()
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    25
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    26
    @classmethod
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    27
    def vreg_initialization_completed(cls):
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    28
        for eschema in cls.schema.entities():
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    29
            if eschema.schema_entity():
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1723
diff changeset
    30
                uicfg.indexview_etype_section.setdefault(eschema, 'schema')
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    31
            elif eschema.is_subobject(strict=True):
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1723
diff changeset
    32
                uicfg.indexview_etype_section.setdefault(eschema, 'subobject')
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
    33
            else:
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1723
diff changeset
    34
                uicfg.indexview_etype_section.setdefault(eschema, 'application')
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
    def display_folders(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        return False
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    38
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    def call(self, **kwargs):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2436
diff changeset
    40
        """The default view representing the instance's management"""
853
4f6cd02bd71f Use specific css files directly in views code
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 513
diff changeset
    41
        self.req.add_css('cubicweb.manageview.css')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
        self.w(u'<div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
        if not self.display_folders():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
            self._main_index()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
            self.w(u'<table><tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
            self.w(u'<td style="width:40%">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
            self._main_index()
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    49
            self.w(u'</td><td style="width:60%">')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
            self.folders()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
            self.w(u'</td>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
            self.w(u'</tr></table>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
        self.w(u'</div>\n')
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
    def _main_index(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        req = self.req
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
        manager = req.user.matching_groups('managers')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
        if not manager and 'Card' in self.schema:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
            rset = self.req.execute('Card X WHERE X wikiid "index"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
            rset = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        if rset:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
            self.wview('inlined', rset, row=0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
            self.entities()
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2780
diff changeset
    66
            self.w(u'<div class="hr">&#160;</div>')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
            self.startup_views()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        if manager and 'Card' in self.schema:
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2780
diff changeset
    69
            self.w(u'<div class="hr">&#160;</div>')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
            if rset:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
                href = rset.get_entity(0, 0).absolute_url(vid='edition')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
                label = self.req._('edit the index page')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
                href = req.build_url('view', vid='creation', etype='Card', wikiid='index')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
                label = self.req._('create an index page')
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2265
diff changeset
    76
            self.w(u'<br/><a href="%s">%s</a>\n' % (xml_escape(href), label))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    77
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    def folders(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        self.w(u'<h4>%s</h4>\n' % self.req._('Browse by category'))
2687
6220500bada7 [startup] vreg api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    80
        self.vreg['views'].select('tree', self.req).render(w=self.w)
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    81
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
    82
    def create_links(self):
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    83
        self.w(u'<ul class="createLink">')
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    84
        for etype in self.add_etype_links:
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    85
            eschema = self.schema.eschema(etype)
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    86
            if eschema.has_perm(self.req, 'add'):
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    87
                self.w(u'<li><a href="%s">%s</a></li>' % (
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    88
                        self.req.build_url('add/%s' % eschema),
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    89
                        self.req.__('add a %s' % eschema).capitalize()))
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    90
        self.w(u'</ul>')
ab10d1cb53ff [ui api] backport create_links from forge so it may be reused
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    91
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
    def startup_views(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        self.w(u'<h4>%s</h4>\n' % self.req._('Startup views'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        self.startupviews_table()
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 startupviews_table(self):
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2488
diff changeset
    97
        for v in self.vreg['views'].possible_views(self.req, None):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
            if v.category != 'startupview' or v.id in ('index', 'tree', 'manage'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
            self.w('<p><a href="%s">%s</a></p>' % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2265
diff changeset
   101
                xml_escape(v.url()), xml_escape(self.req._(v.title).capitalize())))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   102
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
    def entities(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        schema = self.schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
        self.w(u'<h4>%s</h4>\n' % self.req._('The repository holds the following entities'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        manager = self.req.user.matching_groups('managers')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        self.w(u'<table class="startup">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        if manager:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
            self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('application entities'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        self.entity_types_table(eschema for eschema in schema.entities()
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1723
diff changeset
   111
                                if uicfg.indexview_etype_section.get(eschema) == 'application')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   112
        if manager:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
            self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('system entities'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
            self.entity_types_table(eschema for eschema in schema.entities()
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1723
diff changeset
   115
                                if uicfg.indexview_etype_section.get(eschema) == 'system')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
   116
            if 'CWAttribute' in schema: # check schema support
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
                self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('schema entities'))
1631
8370be19afd7 configurable entity types tables
sylvain.thenault@logilab.fr
parents: 1544
diff changeset
   118
                self.entity_types_table(eschema for eschema in schema.entities()
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1723
diff changeset
   119
                                        if uicfg.indexview_etype_section.get(eschema) == 'schema')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
        self.w(u'</table>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   121
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
    def entity_types_table(self, eschemas):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        newline = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
        infos = sorted(self.entity_types(eschemas),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
                       key=lambda (l,a,e):unormalize(l))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        q, r = divmod(len(infos), 2)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        if r:
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2780
diff changeset
   128
            infos.append( (None, '&#160;', '&#160;') )
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
        infos = zip(infos[:q+r], infos[q+r:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
            self.w(u'<tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
            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
   133
            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
   134
            self.w(u'</tr>\n')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   135
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   136
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
    def entity_types(self, eschemas):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
        """return a list of formatted links to get a list of entities of
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        a each entity's types
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
        req = self.req
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
        for eschema in eschemas:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
            if eschema.is_final() or (not eschema.has_perm(req, 'read') and
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
                                      not eschema.has_local_role('read')):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
            etype = eschema.type
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
            label = display_name(req, etype, 'plural')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
            nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0]
2488
cd007fc4f2ea should be enough. Nicer isn't it?
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2476
diff changeset
   149
            url = self.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
   150
            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
   151
                xml_escape(url), label, nb)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
            yield (label, etypelink, self.add_entity_link(eschema, req))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   153
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
    def add_entity_link(self, eschema, req):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
        """creates a [+] link for adding an entity if user has permission to do so"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        if not eschema.has_perm(req, 'add'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
            return u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
        return u'[<a href="%s" title="%s">+</a>]' % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2265
diff changeset
   159
            xml_escape(self.create_url(eschema.type)),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
            self.req.__('add a %s' % eschema))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   162
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
class IndexView(ManageView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
    id = 'index'
2368
b41aef0e63a7 use msgid, update i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   165
    title = _('view_index')
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
    def display_folders(self):
329
903eb8c4ebd6 don't show folder section on index page when there is now folder yet
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 178
diff changeset
   168
        return 'Folder' in self.schema and self.req.execute('Any COUNT(X) WHERE X is Folder')[0][0]
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   169
2748
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   170
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   171
class RegistryView(StartupView):
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   172
    id = 'registry'
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   173
    title = _('registry')
2780
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   174
    __select__ = StartupView.__select__ & match_user_groups('managers')
2748
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   175
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   176
    def call(self, **kwargs):
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   177
        """The default view representing the instance's management"""
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   178
        self.w(u'<h1>%s</h1>' % _("Registry's content"))
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   179
        keys = sorted(self.vreg)
2780
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   180
        self.w(u'<p>%s</p>\n' % ' - '.join('<a href="/_registry#%s">%s</a>' % (key, key) for key in keys))
2748
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   181
        for key in keys:
2780
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   182
            self.w(u'<h2><a name="%s">%s</a></h2>' % (key,key))
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   183
            items = self.vreg[key].items()
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   184
            if items:
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   185
                self.w(u'<table><tbody>')
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   186
                for key, value in sorted(items):
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   187
                    self.w(u'<tr><td>%s</td><td>%s</td></tr>' % (key, xml_escape(repr(value))))
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   188
                self.w(u'</tbody></table>\n')
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   189
            else:
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2775
diff changeset
   190
                self.w(u'<p>Empty</p>\n')
2748
d2fcf19bfb34 F [registry views] add _registry startup view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2687
diff changeset
   191