web/views/schema.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 19 Nov 2009 12:55:47 +0100
branchreldefsecurity
changeset 3877 7ca53fc72a0a
parent 3768 8c85a2f7f5ad
child 3890 d7a270f50f54
permissions -rw-r--r--
reldefsecurity branch : * follow yams default branch api changes * now consider permissions on relation definitions, not relation types. This is still experimental.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""Specific views for schema related entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1739
diff changeset
     4
: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
     5
: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
     6
: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
     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
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    10
from itertools import cycle
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2277
diff changeset
    12
from logilab.mtconverter import xml_escape
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
    13
from yams import BASE_TYPES, schema2dot as s2d
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    14
3215
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
    15
from cubicweb.selectors import (implements, yes, match_user_groups,
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
    16
                                has_related_entities)
3288
266d31e7afa0 skip SYSTEM_RTYPES by default in schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3220
diff changeset
    17
from cubicweb.schema import META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
from cubicweb.schemaviewer import SchemaViewer
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    19
from cubicweb.view import EntityView, StartupView
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    20
from cubicweb.common import tags, uilib
3768
8c85a2f7f5ad nicer relation|entity schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    21
from cubicweb.web import action, facet, uicfg
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
    22
from cubicweb.web.views import TmpFileViewMixin
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
    23
from cubicweb.web.views import primary, baseviews, tabs, management
1151
b20677336ee6 turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    24
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
    25
ALWAYS_SKIP_TYPES = BASE_TYPES | SCHEMA_TYPES
3288
266d31e7afa0 skip SYSTEM_RTYPES by default in schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3220
diff changeset
    26
SKIP_TYPES = ALWAYS_SKIP_TYPES | META_RTYPES | SYSTEM_RTYPES
3555
2689d25bb298 Hide Workflow related entities in the schema diagram
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 3288
diff changeset
    27
SKIP_TYPES.update(set(('Transition', 'State', 'TrInfo', 'Workflow',
2689d25bb298 Hide Workflow related entities in the schema diagram
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 3288
diff changeset
    28
                       'WorkflowTransition', 'BaseTransition',
2689d25bb298 Hide Workflow related entities in the schema diagram
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 3288
diff changeset
    29
                       'SubWorkflowExitPoint',
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
    30
                       'CWUser', 'CWGroup',
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
    31
                       'CWCache', 'CWProperty', 'CWPermission',
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
    32
                       'ExternalUri')))
1151
b20677336ee6 turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    33
2181
94ca417b9b07 backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2126 2172
diff changeset
    34
def skip_types(req):
94ca417b9b07 backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2126 2172
diff changeset
    35
    if int(req.form.get('skipmeta', True)):
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
    36
        return SKIP_TYPES
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
    37
    return ALWAYS_SKIP_TYPES
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
    38
3768
8c85a2f7f5ad nicer relation|entity schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    39
_pvs = uicfg.primaryview_section
8c85a2f7f5ad nicer relation|entity schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    40
for _action in ('read', 'add', 'update', 'delete'):
8c85a2f7f5ad nicer relation|entity schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    41
    _pvs.tag_subject_of(('*', '%s_permission' % _action, '*'), 'hidden')
8c85a2f7f5ad nicer relation|entity schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    42
    _pvs.tag_object_of(('*', '%s_permission' % _action, '*'), 'hidden')
8c85a2f7f5ad nicer relation|entity schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    43
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
    44
# global schema view ###########################################################
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
    45
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
    46
class SchemaView(tabs.TabsMixin, StartupView):
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
    47
    id = 'schema'
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2436
diff changeset
    48
    title = _('instance schema')
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
    49
    tabs = [_('schema-text'), _('schema-image')]
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
    50
    default_tab = 'schema-text'
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
    51
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
    52
    def call(self):
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
    53
        """display schema information"""
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
    54
        self.req.add_js('cubicweb.ajax.js')
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
    55
        self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
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
    56
        self.w(u'<h1>%s</h1>' % _('Schema of the data model'))
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
    57
        self.render_tabs(self.tabs, self.default_tab)
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
    58
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
    59
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
    60
class SchemaTabImageView(StartupView):
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
    61
    id = 'schema-image'
1151
b20677336ee6 turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    62
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
    63
    def call(self):
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
    64
        self.w(_(u'<div>This schema of the data model <em>excludes</em> the '
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
    65
                 u'meta-data, but you can also display a <a href="%s">complete '
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
    66
                 u'schema with meta-data</a>.</div>')
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
    67
               % xml_escape(self.build_url('view', vid='schemagraph', skipmeta=0)))
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
    68
        self.w(u'<img src="%s" alt="%s"/>\n' % (
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
    69
            xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)),
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2436
diff changeset
    70
            self.req._("graphical representation of the instance'schema")))
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
    71
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
    72
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
    73
class SchemaTabTextView(StartupView):
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
    74
    id = 'schema-text'
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
    75
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
    76
    def call(self):
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
    77
        rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, '
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
    78
                                'X final FALSE')
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
    79
        self.wview('table', rset, displayfilter=True)
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
    80
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
    81
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
    82
class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn):
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
    83
    id = 'schema-security'
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
    84
    __select__ = StartupView.__select__ & match_user_groups('managers')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    85
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
    86
    def call(self, display_relations=True):
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
    87
        self.req.add_css('cubicweb.acl.css')
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
    88
        skiptypes = skip_types(self.req)
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
    89
        formparams = {}
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
    90
        formparams['sec'] = self.id
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
    91
        if not skiptypes:
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
    92
            formparams['skipmeta'] = u'0'
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
    93
        schema = self.schema
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
    94
        # compute entities
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
    95
        entities = sorted(eschema for eschema in schema.entities()
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3555
diff changeset
    96
                          if not (eschema.final or eschema in skiptypes))
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
    97
        # compute relations
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
    98
        if display_relations:
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
    99
            relations = sorted(rschema for rschema in schema.relations()
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3555
diff changeset
   100
                               if not (rschema.final
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
   101
                                       or rschema in skiptypes
2617
89c62b855f2e [R schema hooks] rename META_RELATIONS_TYPES into META_RTYPES, use it and other schema consts to avoid errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2476
diff changeset
   102
                                       or rschema in META_RTYPES))
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
   103
        else:
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
   104
            relations = []
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
   105
        # index
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
   106
        _ = self.req._
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
   107
        self.w(u'<div id="schema_security"><a id="index" href="index"/>')
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
   108
        self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize())
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
   109
        self.w(u'<h4>%s</h4>' %   _('Entities').capitalize())
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
   110
        ents = []
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
   111
        for eschema in sorted(entities):
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
   112
            url = xml_escape(self.build_url('schema', **formparams))
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
   113
            ents.append(u'<a class="grey" href="%s#%s">%s</a> (%s)' % (
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
   114
                url,  eschema.type, eschema.type, _(eschema.type)))
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
   115
        self.w(u', '.join(ents))
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
   116
        self.w(u'<h4>%s</h4>' % (_('relations').capitalize()))
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
   117
        rels = []
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
   118
        for rschema in sorted(relations):
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
   119
            url = xml_escape(self.build_url('schema', **formparams))
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
   120
            rels.append(u'<a class="grey" href="%s#%s">%s</a> (%s), ' %  (
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
   121
                url , rschema.type, rschema.type, _(rschema.type)))
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
   122
        self.w(u', '.join(ents))
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
   123
        # entities
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
   124
        self.display_entities(entities, formparams)
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
   125
        # relations
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
   126
        if relations:
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
   127
            self.display_relations(relations, formparams)
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
   128
        self.w(u'</div>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   129
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
   130
    def display_entities(self, entities, formparams):
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
   131
        _ = self.req._
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
   132
        self.w(u'<a id="entities" href="entities"/>')
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
   133
        self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize())
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
   134
        for eschema in entities:
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
   135
            self.w(u'<a id="%s" href="%s"/>' %  (eschema.type, eschema.type))
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
   136
            self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type)))
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
   137
            url = xml_escape(self.build_url('schema', **formparams) + '#index')
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
   138
            self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (
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
   139
                url,  self.req.external_resource('UP_ICON'), _('up')))
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
   140
            self.w(u'</h3>')
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
   141
            self.w(u'<div style="margin: 0px 1.5em">')
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
   142
            self.schema_definition(eschema, link=False)
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
   143
            # display entity attributes only if they have some permissions modified
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
   144
            modified_attrs = []
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
   145
            for attr, etype in  eschema.attribute_definitions():
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
   146
                if self.has_schema_modified_permissions(attr, attr.ACTIONS):
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
   147
                    modified_attrs.append(attr)
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
   148
            if  modified_attrs:
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
   149
                self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize())
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
   150
                self.w(u'</div>')
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
   151
                self.w(u'<div style="margin: 0px 6em">')
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
   152
                for attr in  modified_attrs:
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
   153
                    self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type)))
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
   154
                    self.schema_definition(attr, link=False)
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
   155
            self.w(u'</div>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   156
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
   157
    def display_relations(self, relations, formparams):
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
   158
        _ = self.req._
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
   159
        self.w(u'<a id="relations" href="relations"/>')
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
   160
        self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize())
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
   161
        for rschema in relations:
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
   162
            self.w(u'<a id="%s" href="%s"/>' %  (rschema.type, rschema.type))
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
   163
            self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type)))
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
   164
            url = xml_escape(self.build_url('schema', **formparams) + '#index')
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
   165
            self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (
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
   166
                url,  self.req.external_resource('UP_ICON'), _('up')))
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
   167
            self.w(u'</h3>')
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
   168
            self.w(u'<div style="margin: 0px 1.5em">')
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
   169
            subjects = [str(subj) for subj in rschema.subjects()]
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
   170
            self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (
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
   171
                _('subject_plural:'),
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
   172
                ', '.join(str(subj) for subj in rschema.subjects()),
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
   173
                ', '.join(_(str(subj)) for subj in rschema.subjects())))
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
   174
            self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (
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
   175
                _('object_plural:'),
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
   176
                ', '.join(str(obj) for obj in rschema.objects()),
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
   177
                ', '.join(_(str(obj)) for obj in rschema.objects())))
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
   178
            self.schema_definition(rschema, link=False)
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
   179
            self.w(u'</div>')
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
   180
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
   181
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
   182
class SchemaUreportsView(StartupView):
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
   183
    id = 'schema-block'
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
   184
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
   185
    def call(self):
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
   186
        viewer = SchemaViewer(self.req)
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
   187
        layout = viewer.visit_schema(self.schema, display_relations=True,
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
   188
                                     skiptypes=skip_types(self.req))
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
   189
        self.w(uilib.ureport_as_html(layout))
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
   190
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
   191
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
   192
# CWAttribute / CWRelation #####################################################
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   193
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   194
class CWRDEFPrimaryView(primary.PrimaryView):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   195
    __select__ = implements('CWAttribute', 'CWRelation')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   196
    cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   197
1720
14c9a0a1aca1 drop content_title
sylvain.thenault@logilab.fr
parents: 1580
diff changeset
   198
    def render_entity_title(self, entity):
14c9a0a1aca1 drop content_title
sylvain.thenault@logilab.fr
parents: 1580
diff changeset
   199
        self.w(u'<h1><span class="etype">%s</span> %s</h1>'
14c9a0a1aca1 drop content_title
sylvain.thenault@logilab.fr
parents: 1580
diff changeset
   200
               % (entity.dc_type().capitalize(),
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2277
diff changeset
   201
                  xml_escape(entity.dc_long_title())))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   202
2228
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   203
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   204
# CWEType ######################################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   206
class CWETypeOneLineView(baseviews.OneLineView):
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   207
    __select__ = implements('CWEType')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   208
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   209
    def cell_call(self, row, col, **kwargs):
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   210
        entity = self.rset.get_entity(row, col)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   211
        final = entity.final
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   212
        if final:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   213
            self.w(u'<em class="finalentity">')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   214
        super(CWETypeOneLineView, self).cell_call(row, col, **kwargs)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   215
        if final:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   216
            self.w(u'</em>')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   217
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   218
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   219
class CWETypePrimaryView(tabs.TabsMixin, primary.PrimaryView):
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   220
    __select__ = implements('CWEType')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
    title = _('in memory entity schema')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
    main_related_section = False
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1998
diff changeset
   223
    tabs = [_('cwetype-schema-text'), _('cwetype-schema-image'),
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   224
            _('cwetype-schema-permissions'), _('cwetype-workflow')]
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   225
    default_tab = 'cwetype-schema-text'
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   226
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   227
    def render_entity(self, entity):
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   228
        self.render_entity_title(entity)
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   229
        self.w(u'<div>%s</div>' % entity.description)
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   230
        self.render_tabs(self.tabs, self.default_tab, entity)
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   231
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   232
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   233
class CWETypeSTextView(EntityView):
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   234
    id = 'cwetype-schema-text'
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   235
    __select__ = EntityView.__select__ & implements('CWEType')
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   236
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   237
    def cell_call(self, row, col):
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   238
        entity = self.rset.get_entity(row, col)
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   239
        self.w(u'<h2>%s</h2>' % _('Attributes'))
2231
d2052c3ccac7 won't get anything useful like this (currently, list of constraint's eids), should use a custom table view (later...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2228
diff changeset
   240
        rset = self.req.execute('Any N,F,D,I,J,DE,A '
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   241
                                'ORDERBY AA WHERE A is CWAttribute, '
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   242
                                'A ordernum AA, A defaultval D, '
2231
d2052c3ccac7 won't get anything useful like this (currently, list of constraint's eids), should use a custom table view (later...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2228
diff changeset
   243
                                'A description DE, '
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   244
                                'A fulltextindexed I, A internationalizable J, '
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   245
                                'A relation_type R, R name N, '
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   246
                                'A to_entity O, O name F, '
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   247
                                'A from_entity S, S eid %(x)s',
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   248
                                {'x': entity.eid})
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   249
        self.wview('editable-table', rset, 'null', displayfilter=True)
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   250
        self.w(u'<h2>%s</h2>' % _('Relations'))
2228
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   251
        rset = self.req.execute(
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   252
            'Any R,C,TT,K,D,A,RN,TTN ORDERBY RN '
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   253
            'WHERE A is CWRelation, A description D, A composite K?, '
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   254
            'A relation_type R, R name RN, A to_entity TT, TT name TTN, '
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   255
            'A cardinality C, A from_entity S, S eid %(x)s',
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   256
            {'x': entity.eid})
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   257
        self.wview('editable-table', rset, 'null', displayfilter=True,
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   258
                   displaycols=range(6), mainindex=5)
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   259
        rset = self.req.execute(
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   260
            'Any R,C,TT,K,D,A,RN,TTN ORDERBY RN '
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   261
            'WHERE A is CWRelation, A description D, A composite K?, '
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   262
            'A relation_type R, R name RN, A from_entity TT, TT name TTN, '
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   263
            'A cardinality C, A to_entity O, O eid %(x)s',
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   264
            {'x': entity.eid})
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   265
        self.wview('editable-table', rset, 'null', displayfilter=True,
7e85d0169911 some enhancements: link to relation/target type, remove to be deprecated meta, one table for subject relations, another for object relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   266
                   displaycols=range(6), mainindex=5)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   268
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   269
class CWETypeSImageView(EntityView):
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   270
    id = 'cwetype-schema-image'
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   271
    __select__ = EntityView.__select__ & implements('CWEType')
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   272
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   273
    def cell_call(self, row, col):
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   274
        entity = self.rset.get_entity(row, col)
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   275
        url = entity.absolute_url(vid='schemagraph')
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   276
        self.w(u'<img src="%s" alt="%s"/>' % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2277
diff changeset
   277
            xml_escape(url),
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2277
diff changeset
   278
            xml_escape(self.req._('graphical schema for %s') % entity.name)))
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   279
3215
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   280
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   281
class CWETypeSPermView(EntityView):
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   282
    id = 'cwetype-schema-permissions'
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   283
    __select__ = EntityView.__select__ & implements('CWEType')
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   284
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   285
    def cell_call(self, row, col):
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   286
        entity = self.rset.get_entity(row, col)
3768
8c85a2f7f5ad nicer relation|entity schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   287
        _ = self.req._
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   288
        self.w(u'<h2>%s</h2>' % _('Add permissions'))
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   289
        rset = self.req.execute('Any P WHERE X add_permission P, '
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1998
diff changeset
   290
                                'X eid %(x)s',
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   291
                                {'x': entity.eid})
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   292
        self.wview('outofcontext', rset, 'null')
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   293
        self.w(u'<h2>%s</h2>' % _('Read permissions'))
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   294
        rset = self.req.execute('Any P WHERE X read_permission P, '
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1998
diff changeset
   295
                                'X eid %(x)s',
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   296
                                {'x': entity.eid})
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   297
        self.wview('outofcontext', rset, 'null')
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   298
        self.w(u'<h2>%s</h2>' % _('Update permissions'))
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   299
        rset = self.req.execute('Any P WHERE X update_permission P, '
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1998
diff changeset
   300
                                'X eid %(x)s',
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   301
                                {'x': entity.eid})
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   302
        self.wview('outofcontext', rset, 'null')
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   303
        self.w(u'<h2>%s</h2>' % _('Delete permissions'))
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   304
        rset = self.req.execute('Any P WHERE X delete_permission P, '
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1998
diff changeset
   305
                                'X eid %(x)s',
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   306
                                {'x': entity.eid})
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   307
        self.wview('outofcontext', rset, 'null')
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   308
3215
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   309
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   310
class CWETypeSWorkflowView(EntityView):
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   311
    id = 'cwetype-workflow'
3215
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   312
    __select__ = (EntityView.__select__ & implements('CWEType') &
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   313
                  has_related_entities('workflow_of', 'object'))
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   314
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   315
    def cell_call(self, row, col):
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   316
        entity = self.rset.get_entity(row, col)
3215
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   317
        if entity.default_workflow:
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   318
            wf = entity.default_workflow[0]
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   319
            self.w(u'<h1>%s (%s)</h1>' % (wf.name, self.req._('default')))
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   320
            self.wf_image(wf)
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   321
        for altwf in entity.reverse_workflow_of:
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   322
            if altwf.eid == wf.eid:
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   323
                continue
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   324
            self.w(u'<h1>%s</h1>' % altwf.name)
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   325
            self.wf_image(altwf)
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   326
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   327
    def wf_image(self, wf):
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   328
        self.w(u'<img src="%s" alt="%s"/>' % (
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   329
            xml_escape(wf.absolute_url(vid='wfgraph')),
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2617
diff changeset
   330
            xml_escape(self.req._('graphical representation of %s') % wf.name)))
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   331
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   332
# CWRType ######################################################################
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   333
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   334
class CWRTypeSchemaView(primary.PrimaryView):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   335
    __select__ = implements('CWRType')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
    title = _('in memory relation schema')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
    main_related_section = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   338
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   339
    def render_entity_attributes(self, entity):
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   340
        super(CWRTypeSchemaView, self).render_entity_attributes(entity)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
        rschema = self.vreg.schema.rschema(entity.name)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
        viewer = SchemaViewer(self.req)
3768
8c85a2f7f5ad nicer relation|entity schema view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   343
        layout = viewer.visit_relationschema(rschema, title=False)
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   344
        self.w(uilib.ureport_as_html(layout))
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3555
diff changeset
   345
        if not rschema.final:
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   346
            msg = self.req._('graphical schema for %s') % entity.name
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   347
            self.w(tags.img(src=entity.absolute_url(vid='schemagraph'),
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   348
                            alt=msg))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   349
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   351
# schema images ###############################################################
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   352
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   353
class RestrictedSchemaVisitorMixIn(object):
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   354
    def __init__(self, req, *args, **kwargs):
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
   355
        self.req = req
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   356
        super(RestrictedSchemaVisitorMixIn, self).__init__(*args, **kwargs)
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   357
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
   358
    def should_display_schema(self, rschema):
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
   359
        return (super(RestrictedSchemaVisitorMixIn, self).should_display_schema(rschema)
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3768
diff changeset
   360
                and rschema.may_have_permission('read', self.req))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   361
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3768
diff changeset
   362
    def should_display_attr(self, eschema, rschema):
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
   363
        return (super(RestrictedSchemaVisitorMixIn, self).should_display_attr(rschema)
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3768
diff changeset
   364
                and eschema.rdef(rschema).may_have_permission('read'))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   365
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   367
class FullSchemaVisitor(RestrictedSchemaVisitorMixIn, s2d.FullSchemaVisitor):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   368
    pass
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   370
class OneHopESchemaVisitor(RestrictedSchemaVisitorMixIn,
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   371
                           s2d.OneHopESchemaVisitor):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   372
    pass
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   373
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   374
class OneHopRSchemaVisitor(RestrictedSchemaVisitorMixIn,
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   375
                           s2d.OneHopRSchemaVisitor):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   376
    pass
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   377
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   378
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   379
class SchemaImageView(TmpFileViewMixin, StartupView):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   380
    id = 'schemagraph'
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   381
    content_type = 'image/png'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   382
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   383
    def _generate(self, tmpfile):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   384
        """display global schema information"""
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
   385
        print 'skipedtypes', skip_types(self.req)
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   386
        visitor = FullSchemaVisitor(self.req, self.schema,
2181
94ca417b9b07 backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2126 2172
diff changeset
   387
                                    skiptypes=skip_types(self.req))
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   388
        s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   389
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
   390
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   391
class CWETypeSchemaImageView(TmpFileViewMixin, EntityView):
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   392
    id = 'schemagraph'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   393
    __select__ = implements('CWEType')
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   394
    content_type = 'image/png'
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   395
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   396
    def _generate(self, tmpfile):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   397
        """display schema information for an entity"""
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   398
        entity = self.rset.get_entity(self.row, self.col)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   399
        eschema = self.vreg.schema.eschema(entity.name)
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   400
        visitor = OneHopESchemaVisitor(self.req, eschema,
2181
94ca417b9b07 backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2126 2172
diff changeset
   401
                                       skiptypes=skip_types(self.req))
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   402
        s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   403
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
   404
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   405
class CWRTypeSchemaImageView(CWETypeSchemaImageView):
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   406
    __select__ = implements('CWRType')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   407
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   408
    def _generate(self, tmpfile):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   409
        """display schema information for an entity"""
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   410
        entity = self.rset.get_entity(self.row, self.col)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   411
        rschema = self.vreg.schema.rschema(entity.name)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   412
        visitor = OneHopRSchemaVisitor(self.req, rschema)
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1998
diff changeset
   413
        s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   414
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
   415
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
   416
# misc: facets, actions ########################################################
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
   417
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
   418
class CWFinalFacet(facet.AttributeFacet):
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
   419
    id = 'cwfinal-facet'
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
   420
    __select__ = facet.AttributeFacet.__select__ & implements('CWEType', 'CWRType')
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
   421
    rtype = 'final'
1998
12040c090aa4 [views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
   422
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
   423
class ViewSchemaAction(action.Action):
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
   424
    id = 'schema'
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
   425
    __select__ = yes()
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
   426
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
   427
    title = _("site schema")
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
   428
    category = 'siteactions'
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
   429
    order = 30
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
   430
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
   431
    def url(self):
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
   432
        return self.build_url(self.id)