web/views/schema.py
author Graziella Toutoungis <graziella.toutoungis@logilab.fr>
Mon, 11 May 2009 12:03:52 +0200
branchtls-sprint
changeset 1725 d15406d17803
parent 1724 8a3c3ae8c809
parent 1723 30c3a713ab61
child 1739 78b0819162a8
permissions -rw-r--r--
merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""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
787
b9eb2475b446 update imports
sylvain.thenault@logilab.fr
parents: 728
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
     9
from itertools import cycle
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    11
from logilab.mtconverter import html_escape
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    12
from yams import schema2dot as s2d
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    13
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    14
from cubicweb.selectors import implements, yes
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
from cubicweb.schemaviewer import SchemaViewer
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    16
from cubicweb.view import EntityView, StartupView
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    17
from cubicweb.common import tags, uilib
1580
e26bbb0a6eb9 use tag_attribute, rwidgets should contain widget instance, not name
sylvain.thenault@logilab.fr
parents: 1556
diff changeset
    18
from cubicweb.web import uicfg, formwidgets, action
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    19
from cubicweb.web.views import TmpFileViewMixin, primary, baseviews
1151
b20677336ee6 turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    20
b20677336ee6 turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    21
1721
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    22
uicfg.rcategories.tag_relation('!CWPermission', 'require_group', '*', 'primary')
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    23
uicfg.rcategories.tag_attribute('EEtype', 'final', 'generated')
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    24
uicfg.rcategories.tag_attribute('ERtype', 'final', 'generated')
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    25
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    26
uicfg.rinlined.tag_relation('!CWRelation', 'relation_type', '*', True)
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    27
uicfg.rinlined.tag_relation('!CWRelation', 'from_entity', '*', True)
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    28
uicfg.rinlined.tag_relation('!CWRelation', 'to_entity', '*', True)
1151
b20677336ee6 turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    29
1721
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    30
uicfg.rwidgets.tag_attribute('RQLExpression', 'expression', formwidgets.TextInput)
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    31
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    32
uicfg.rmode.tag_relation('*', 'state_of', '!CWEType', 'create')
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    33
uicfg.rmode.tag_relation('*', 'transition_of', '!CWEType', 'create')
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    34
uicfg.rmode.tag_relation('*', 'relation_type', '!CWRType', 'create')
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    35
uicfg.rmode.tag_relation('*', 'from_entity', '!CWEType', 'link')
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    36
uicfg.rmode.tag_relation('*', 'to_entity', '!CWEType', 'link')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    38
for attr in ('name', 'meta', 'final'):
1721
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    39
    uicfg.rdisplay.tag_attribute('CWRType', attr, {})
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    40
for attr in ('name', 'meta', 'final', 'symetric', 'inlined'):
1721
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1720
diff changeset
    41
    uicfg.rdisplay.tag_attribute('CWRType', attr, {})
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    42
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    44
class ViewSchemaAction(action.Action):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    45
    id = 'schema'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    46
    __select__ = yes()
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    47
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    48
    title = _("site schema")
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    49
    category = 'siteactions'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    50
    order = 30
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    51
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    52
    def url(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    53
        return self.build_url(self.id)
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    54
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    55
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    56
# schema entity types views ###################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    58
class CWRDEFPrimaryView(primary.PrimaryView):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    59
    __select__ = implements('CWAttribute', 'CWRelation')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    60
    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
    61
1720
14c9a0a1aca1 drop content_title
sylvain.thenault@logilab.fr
parents: 1580
diff changeset
    62
    def render_entity_title(self, entity):
14c9a0a1aca1 drop content_title
sylvain.thenault@logilab.fr
parents: 1580
diff changeset
    63
        self.w(u'<h1><span class="etype">%s</span> %s</h1>'
14c9a0a1aca1 drop content_title
sylvain.thenault@logilab.fr
parents: 1580
diff changeset
    64
               % (entity.dc_type().capitalize(),
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1721
diff changeset
    65
                  html_escape(entity.dc_long_title())))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    66
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    68
class CWETypeOneLineView(baseviews.OneLineView):
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    69
    __select__ = implements('CWEType')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    70
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    71
    def cell_call(self, row, col, **kwargs):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    72
        entity = self.entity(row, col)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    73
        final = entity.final
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    74
        if final:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    75
            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
    76
        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
    77
        if final:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    78
            self.w(u'</em>')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    79
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    80
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    81
# in memory schema views (yams class instances) ###############################
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    82
SKIPPED_RELS = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by',
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    83
                'has_text',)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
    84
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    85
class CWETypeSchemaView(primary.PrimaryView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    id = 'eschema'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    87
    __select__ = implements('CWEType')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
    title = _('in memory entity schema')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
    main_related_section = False
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    90
    skip_rels = SKIPPED_RELS
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    91
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    92
    def render_entity_attributes(self, entity):
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    93
        super(CWETypeSchemaView, self).render_entity_attributes(entity)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        eschema = self.vreg.schema.eschema(entity.name)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
        viewer = SchemaViewer(self.req)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
        layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels)
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    97
        self.w(uilib.ureport_as_html(layout))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
        if not eschema.is_final():
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    99
            msg = self.req._('graphical schema for %s') % entity.name
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   100
            self.w(tags.img(src=entity.absolute_url(vid='eschemagraph'),
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   101
                            alt=msg))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   103
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   104
class CWRTypeSchemaView(primary.PrimaryView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    id = 'eschema'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   106
    __select__ = implements('CWRType')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    title = _('in memory relation schema')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
    main_related_section = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   110
    def render_entity_attributes(self, entity):
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   111
        super(CWRTypeSchemaView, self).render_entity_attributes(entity)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
        rschema = self.vreg.schema.rschema(entity.name)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
        viewer = SchemaViewer(self.req)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
        layout = viewer.visit_relationschema(rschema)
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   115
        self.w(uilib.ureport_as_html(layout))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        if not rschema.is_final():
1556
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   117
            msg = self.req._('graphical schema for %s') % entity.name
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   118
            self.w(tags.img(src=entity.absolute_url(vid='eschemagraph'),
b64a0fe1fc86 cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   119
                            alt=msg))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   120
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   122
# schema images ###############################################################
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   123
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   124
class ImageView(EntityView):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   125
    __select__ = implements('CWEType')
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   126
    id = 'image'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   127
    title = _('image')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   128
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   129
    def cell_call(self, row, col):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        entity = self.entity(row, col)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   131
        url = entity.absolute_url(vid='eschemagraph')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
        self.w(u'<img src="%s" alt="%s"/>' % (
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   133
            html_escape(url),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   134
            html_escape(self.req._('graphical schema for %s') % entity.name)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   137
class RestrictedSchemaDotPropsHandler(s2d.SchemaDotPropsHandler):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   138
    def __init__(self, req):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   139
        # FIXME: colors are arbitrary
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   140
        self.nextcolor = cycle( ('#aa0000', '#00aa00', '#0000aa',
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   141
                                 '#000000', '#888888') ).next
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   142
        self.req = req
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   143
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   144
    def display_attr(self, rschema):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   145
        return not rschema.meta and (rschema.has_local_role('read')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   146
                                     or rschema.has_perm(self.req, 'read'))
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   147
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   148
    # XXX remove this method once yams > 0.20 is out
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   149
    def node_properties(self, eschema):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   150
        """return default DOT drawing options for an entity schema"""
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
   151
        label = ['{', eschema.type, '|']
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   152
        label.append(r'\l'.join(rel.type for rel in eschema.subject_relations()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   153
                                if rel.final and self.display_attr(rel)))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   154
        label.append(r'\l}') # trailing \l ensure alignement of the last one
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   155
        return {'label' : ''.join(label), 'shape' : "record",
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   156
                'fontname' : "Courier", 'style' : "filled"}
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   157
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   158
    def edge_properties(self, rschema, subjnode, objnode):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   159
        kwargs = super(RestrictedSchemaDotPropsHandler, self).edge_properties(rschema, subjnode, objnode)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   160
        # symetric rels are handled differently, let yams decide what's best
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   161
        if not rschema.symetric:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   162
            kwargs['color'] = self.nextcolor()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   163
        kwargs['fontcolor'] = kwargs['color']
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   164
        # dot label decoration is just awful (1 line underlining the label
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   165
        # + 1 line going to the closest edge spline point)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   166
        kwargs['decorate'] = 'false'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   167
        return kwargs
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   168
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   170
class RestrictedSchemaVisitorMiIn:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   171
    def __init__(self, req, *args, **kwargs):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   172
        # hack hack hack
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   173
        assert len(self.__class__.__bases__) == 2
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   174
        self.__parent = self.__class__.__bases__[1]
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   175
        self.__parent.__init__(self, *args, **kwargs)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   176
        self.req = req
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   177
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   178
    def nodes(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   179
        for etype, eschema in self.__parent.nodes(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   180
            if eschema.has_local_role('read') or eschema.has_perm(self.req, 'read'):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   181
                yield eschema.type, eschema
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   182
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   183
    def edges(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   184
        for setype, oetype, rschema in self.__parent.edges(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   185
            if rschema.has_local_role('read') or rschema.has_perm(self.req, 'read'):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   186
                yield setype, oetype, rschema
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   187
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   188
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   189
class FullSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.FullSchemaVisitor):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   190
    pass
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   192
class OneHopESchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopESchemaVisitor):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   193
    pass
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   194
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   195
class OneHopRSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopRSchemaVisitor):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   196
    pass
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   197
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   198
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   199
class SchemaImageView(TmpFileViewMixin, StartupView):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   200
    id = 'schemagraph'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   201
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   202
    content_type = 'image/png'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   203
    skip_rels = SKIPPED_RELS
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   204
    def _generate(self, tmpfile):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   205
        """display global schema information"""
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   206
        skipmeta = not int(self.req.form.get('withmeta', 0))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   207
        visitor = FullSchemaVisitor(self.req, self.schema, skiprels=self.skip_rels, skipmeta=skipmeta)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   208
        s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   209
                       prophdlr=RestrictedSchemaDotPropsHandler(self.req))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   210
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   211
class CWETypeSchemaImageView(TmpFileViewMixin, EntityView):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   212
    id = 'eschemagraph'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   213
    __select__ = implements('CWEType')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   214
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   215
    content_type = 'image/png'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   216
    skip_rels = SKIPPED_RELS
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   217
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   218
    def _generate(self, tmpfile):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   219
        """display schema information for an entity"""
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   220
        entity = self.entity(self.row, self.col)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   221
        eschema = self.vreg.schema.eschema(entity.name)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   222
        visitor = OneHopESchemaVisitor(self.req, eschema, skiprels=self.skip_rels)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   223
        s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   224
                       prophdlr=RestrictedSchemaDotPropsHandler(self.req))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   225
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   226
class CWRTypeSchemaImageView(CWETypeSchemaImageView):
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   227
    __select__ = implements('CWRType')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   228
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   229
    def _generate(self, tmpfile):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   230
        """display schema information for an entity"""
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   231
        entity = self.entity(self.row, self.col)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   232
        rschema = self.vreg.schema.rschema(entity.name)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   233
        visitor = OneHopRSchemaVisitor(self.req, rschema)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   234
        s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 1012
diff changeset
   235
                       prophdlr=RestrictedSchemaDotPropsHandler(self.req))