web/views/startup.py
author Katia Saurfelt <katia.saurfelt@logilab.fr>
Mon, 27 Apr 2009 10:02:58 +0200
changeset 1495 4d6e9fe80378
parent 1494 d68aac1cda0d
child 1496 00f7ccd9a08b
permissions -rw-r--r--
avoid displaying a section twice
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
513
907c18c01c60 while EntityView has been used here?? (changeset 501 by laure)
sylvain.thenault@logilab.fr
parents: 505
diff changeset
     5
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
from logilab.mtconverter import html_escape
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
from cubicweb.common.uilib import ureport_as_html, unormalize, ajax_replace_url
513
907c18c01c60 while EntityView has been used here?? (changeset 501 by laure)
sylvain.thenault@logilab.fr
parents: 505
diff changeset
    13
from cubicweb.common.view import StartupView
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
    14
from cubicweb.common.selectors import match_user_group
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
from cubicweb.web.httpcache import EtagHTTPCacheManager
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
    16
from cubicweb.web.views.management import SecurityViewMixIn
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
    17
from copy import deepcopy
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
_ = unicode
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
class ManageView(StartupView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
    id = 'manage'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
    title = _('manage')    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
    http_cache_manager = EtagHTTPCacheManager
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
    def display_folders(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
        return False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
        """The default view representing the application's management"""
853
4f6cd02bd71f Use specific css files directly in views code
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 513
diff changeset
    31
        self.req.add_css('cubicweb.manageview.css')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
        self.w(u'<div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
        if not self.display_folders():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
            self._main_index()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
            self.w(u'<table><tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
            self.w(u'<td style="width:40%">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
            self._main_index()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
            self.w(u'</td><td style="width:60%">')            
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
            self.folders()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
            self.w(u'</td>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
            self.w(u'</tr></table>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
        self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
    def _main_index(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        req = self.req
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
        manager = req.user.matching_groups('managers')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
        if not manager and 'Card' in self.schema:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
            rset = self.req.execute('Card X WHERE X wikiid "index"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
            rset = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        if rset:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
            self.wview('inlined', rset, row=0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
            self.entities()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
            self.w(u'<div class="hr">&nbsp;</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
            self.startup_views()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
        if manager and 'Card' in self.schema:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
            self.w(u'<div class="hr">&nbsp;</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
            if rset:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
                href = rset.get_entity(0, 0).absolute_url(vid='edition')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
                label = self.req._('edit the index page')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
                href = req.build_url('view', vid='creation', etype='Card', wikiid='index')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
                label = self.req._('create an index page')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
            self.w(u'<br/><a href="%s">%s</a>\n' % (html_escape(href), label))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
    def folders(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        self.w(u'<h4>%s</h4>\n' % self.req._('Browse by category'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        self.vreg.select_view('tree', self.req, None).dispatch(w=self.w)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
    def startup_views(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
        self.w(u'<h4>%s</h4>\n' % self.req._('Startup views'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
        self.startupviews_table()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
    def startupviews_table(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
        for v in self.vreg.possible_views(self.req, None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
            if v.category != 'startupview' or v.id in ('index', 'tree', 'manage'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
            self.w('<p><a href="%s">%s</a></p>' % (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
                html_escape(v.url()), html_escape(self.req._(v.title).capitalize())))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    def entities(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
        schema = self.schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        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
    86
        manager = self.req.user.matching_groups('managers')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
        self.w(u'<table class="startup">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
        if manager:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
            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
    90
        self.entity_types_table(eschema for eschema in schema.entities()
178
b5478a96da3d only hide strict suboject in default view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 0
diff changeset
    91
                                if not eschema.meta and not eschema.is_subobject(strict=True))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        if manager: 
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
            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
    94
            self.entity_types_table(eschema for eschema in schema.entities()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
                                    if eschema.meta and not eschema.schema_entity())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
            if 'EFRDef' in schema: # check schema support
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
                self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('schema entities'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
                self.entity_types_table(schema.eschema(etype)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
                                        for etype in schema.schema_entity_types())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
        self.w(u'</table>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    def entity_types_table(self, eschemas):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        newline = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        infos = sorted(self.entity_types(eschemas),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
                       key=lambda (l,a,e):unormalize(l))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        q, r = divmod(len(infos), 2)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        if r:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
            infos.append( (None, '&nbsp;', '&nbsp;') )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
        infos = zip(infos[:q+r], infos[q+r:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
            self.w(u'<tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
            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
   113
            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
   114
            self.w(u'</tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
    def entity_types(self, eschemas):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
        """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
   119
        a each entity's types
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
        req = self.req
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
        for eschema in eschemas:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
            if eschema.is_final() or (not eschema.has_perm(req, 'read') and
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
                                      not eschema.has_local_role('read')):
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
            label = display_name(req, etype, 'plural')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
            nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
            if nb > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
                view = self.vreg.select_view('list', req, req.etype_rset(etype))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
                url = view.url()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
                url = self.build_url('view', rql='%s X' % etype)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
            etypelink = u'&nbsp;<a href="%s">%s</a> (%d)' % (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
                html_escape(url), label, nb)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
            yield (label, etypelink, self.add_entity_link(eschema, req))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
    def add_entity_link(self, eschema, req):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        """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
   140
        if not eschema.has_perm(req, 'add'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
            return u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
        return u'[<a href="%s" title="%s">+</a>]' % (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
            html_escape(self.create_url(eschema.type)),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
            self.req.__('add a %s' % eschema))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
class IndexView(ManageView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
    id = 'index'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
    title = _('index')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
    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
   152
        return 'Folder' in self.schema and self.req.execute('Any COUNT(X) WHERE X is Folder')[0][0]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
class SchemaView(StartupView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
    id = 'schema'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
    title = _('application schema')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
        """display schema information"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
        self.req.add_js('cubicweb.ajax.js')
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   163
        self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
        withmeta = int(self.req.form.get('withmeta', 0))
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   165
        section = self.req.form.get('sec', '')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        self.w(u'<img src="%s" alt="%s"/>\n' % (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
            html_escape(self.req.build_url('view', vid='schemagraph', withmeta=withmeta)),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
            self.req._("graphical representation of the application'schema")))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
        if withmeta:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
            self.w(u'<div><a href="%s">%s</a></div>' % (
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   171
                html_escape(self.build_url('schema', withmeta=0, sec=section)),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
                self.req._('hide meta-data')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
            self.w(u'<div><a href="%s">%s</a></div>' % (
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   175
                html_escape(self.build_url('schema', withmeta=1, sec=section)),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
                self.req._('show meta-data')))
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   177
        self.w(u'<a href="%s">%s</a><br/>' %
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
               (html_escape(ajax_replace_url('detailed_schema', '', 'schematext',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
                                             skipmeta=int(not withmeta))),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
                self.req._('detailed schema view')))
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   181
        if self.req.user.matching_groups('managers'):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   182
            self.w(u'<a href="%s">%s</a>' %
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   183
                   (html_escape(ajax_replace_url('detailed_schema', '', 'schema_security',
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   184
                                                 skipmeta=int(not withmeta))),
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   185
                self.req._('security')))
1495
4d6e9fe80378 avoid displaying a section twice
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1494
diff changeset
   186
        self.w(u'<div id="detailed_schema">')
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   187
        if section:
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   188
            self.wview(section, None)
1495
4d6e9fe80378 avoid displaying a section twice
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1494
diff changeset
   189
        self.w(u'</div>')
4d6e9fe80378 avoid displaying a section twice
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1494
diff changeset
   190
    
4d6e9fe80378 avoid displaying a section twice
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1494
diff changeset
   191
class SchemaPermissionsView(SchemaPermissionsView, SecurityViewMixIn):
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   192
    id = 'schema_security'
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   193
    require_groups = ('managers',)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   194
    __selectors__ = StartupView.__selectors__ + (match_user_group,)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   195
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   196
    def call(self, display_relations=True,
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   197
             skiprels=('is', 'is_instance_of', 'identity', 'owned_by', 'created_by')):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   198
        _ = self.req._
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   199
        formparams = {}
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   200
        formparams['sec'] = self.id
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   201
        formparams['withmeta'] = int(self.req.form.get('withmeta', True))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   202
        schema = self.schema
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   203
        # compute entities
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   204
        entities = [eschema for eschema in schema.entities()
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   205
                   if not eschema.is_final()]
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   206
        if not formparams['withmeta']:
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   207
            entities = [eschema for eschema in entities
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   208
                        if not eschema.meta]
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   209
        # compute relations
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   210
        relations = []    
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   211
        if display_relations:
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   212
            relations = [rschema for rschema in schema.relations()
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   213
                         if not (rschema.is_final() or rschema.type in skiprels)]
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   214
            if not formparams['withmeta']:
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   215
                relations = [rschema for rschema in relations
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   216
                             if not rschema.meta]
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   217
        # index
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   218
        self.w(u'<div id="schema_security"><a id="index" href="index"/>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   219
        self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize())
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   220
        self.w(u'<h4>%s</h4>' %   _('Entities').capitalize())
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   221
        ents = []
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   222
        for eschema in sorted(entities):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   223
            url = html_escape(self.build_url('schema', **formparams) + '#' + eschema.type)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   224
            ents.append(u'<a class="grey" href="%s">%s</a> (%s)' % (url,  eschema.type, _(eschema.type)))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   225
        self.w('%s' %  ', '.join(ents))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   226
        self.w(u'<h4>%s</h4>' % (_('relations').capitalize()))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   227
        rels = []
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   228
        for eschema in sorted(relations):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   229
            url = html_escape(self.build_url('schema', **formparams) + '#' + eschema.type)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   230
            rels.append(u'<a class="grey" href="%s">%s</a> (%s), ' %  (url , eschema.type, _(eschema.type)))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   231
        self.w('%s' %  ', '.join(ents))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   232
        # entities
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   233
        self.display_entities(entities, formparams)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   234
        # relations
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   235
        if relations:
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   236
            self.display_relations(relations, formparams)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   237
        self.w(u'</div>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   238
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   239
    def display_entities(self, entities, formparams):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   240
        _ = self.req._
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   241
        self.w(u'<a id="entities" href="entities"/>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   242
        self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize())
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   243
        for eschema in sorted(entities):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   244
            self.w(u'<a id="%s" href="%s"/>' %  (eschema.type, eschema.type))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   245
            self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type)))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   246
            url = html_escape(self.build_url('schema', **formparams) + '#index')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   247
            self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (url,  self.req.external_resource('UP_ICON'), _('up')))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   248
            self.w(u'</h3>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   249
            self.w(u'<div style="margin: 0px 1.5em">')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   250
            self.schema_definition(eschema, link=False)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   251
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   252
            # display entity attributes only if they have some permissions modified
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   253
            modified_attrs = []
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   254
            for attr, etype in  eschema.attribute_definitions():
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   255
                if self.has_schema_modified_permissions(attr, attr.ACTIONS):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   256
                    modified_attrs.append(attr)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   257
            if  modified_attrs:
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   258
                self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize())
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   259
                self.w(u'</div>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   260
                self.w(u'<div style="margin: 0px 6em">')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   261
                for attr in  modified_attrs:
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   262
                    self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type)))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   263
                    self.schema_definition(attr, link=False)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   264
                self.w(u'</div>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   265
            else:
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   266
                self.w(u'</div>')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
1494
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   269
    def display_relations(self, relations, formparams):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   270
        _ = self.req._
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   271
        self.w(u'<a id="relations" href="relations"/>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   272
        self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize())
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   273
        for rschema in sorted(relations):
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   274
            self.w(u'<a id="%s" href="%s"/>' %  (rschema.type, rschema.type))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   275
            self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type)))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   276
            url = html_escape(self.build_url('schema', **formparams) + '#index')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   277
            self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (url,  self.req.external_resource('UP_ICON'), _('up')))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   278
            self.w(u'</h3>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   279
            self.w(u'<div style="margin: 0px 1.5em">')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   280
            subjects = [str(subj) for subj in rschema.subjects()]
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   281
            self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (_('subject_plural:'),
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   282
                                                ', '.join( [str(subj) for subj in rschema.subjects()]),
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   283
                                                ', '.join( [_(str(subj)) for subj in rschema.subjects()])))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   284
            self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (_('object_plural:'),
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   285
                                                ', '.join( [str(obj) for obj in rschema.objects()]),
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   286
                                                ', '.join( [_(str(obj)) for obj in rschema.objects()])))
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   287
            self.schema_definition(rschema, link=False)
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   288
            self.w(u'</div>')
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   289
d68aac1cda0d #342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 853
diff changeset
   290
                
513
907c18c01c60 while EntityView has been used here?? (changeset 501 by laure)
sylvain.thenault@logilab.fr
parents: 505
diff changeset
   291
class SchemaUreportsView(StartupView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   292
    id = 'schematext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   293
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
        from cubicweb.schemaviewer import SchemaViewer
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
        skipmeta = int(self.req.form.get('skipmeta', True))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
        schema = self.schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
        viewer = SchemaViewer(self.req)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
        layout = viewer.visit_schema(schema, display_relations=True,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
                                     skiprels=('is', 'is_instance_of', 'identity',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
                                               'owned_by', 'created_by'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
                                     skipmeta=skipmeta)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
        self.w(ureport_as_html(layout))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304