web/views/schema.py
branchtls-sprint
changeset 1556 b64a0fe1fc86
parent 1554 3a3263df6cdd
child 1580 e26bbb0a6eb9
equal deleted inserted replaced
1555:86f9baff9dd6 1556:b64a0fe1fc86
    12 from yams import schema2dot as s2d
    12 from yams import schema2dot as s2d
    13 
    13 
    14 from cubicweb.selectors import implements, yes
    14 from cubicweb.selectors import implements, yes
    15 from cubicweb.schemaviewer import SchemaViewer
    15 from cubicweb.schemaviewer import SchemaViewer
    16 from cubicweb.view import EntityView, StartupView
    16 from cubicweb.view import EntityView, StartupView
    17 from cubicweb.common.uilib import ureport_as_html
    17 from cubicweb.common import tags, uilib
    18 from cubicweb.web import uicfg, action
    18 from cubicweb.web import uicfg, action
    19 from cubicweb.web.views import TmpFileViewMixin, primary, baseviews
    19 from cubicweb.web.views import TmpFileViewMixin, primary, baseviews
    20 
    20 
    21 
    21 
    22 uicfg.rcategories.tag_relation('primary', ('CWPermission', 'require_group', '*'), 'subject')
    22 uicfg.rcategories.tag_relation('primary', ('CWPermission', 'require_group', '*'), 'subject')
    83     __select__ = implements('CWEType')
    83     __select__ = implements('CWEType')
    84     title = _('in memory entity schema')
    84     title = _('in memory entity schema')
    85     main_related_section = False
    85     main_related_section = False
    86     skip_rels = SKIPPED_RELS
    86     skip_rels = SKIPPED_RELS
    87 
    87 
    88     def render_entity_attributes(self, entity, siderelations):
    88     def render_entity_attributes(self, entity):
    89         super(CWETypeSchemaView, self).render_entity_attributes(entity, siderelations)
    89         super(CWETypeSchemaView, self).render_entity_attributes(entity)
    90         eschema = self.vreg.schema.eschema(entity.name)
    90         eschema = self.vreg.schema.eschema(entity.name)
    91         viewer = SchemaViewer(self.req)
    91         viewer = SchemaViewer(self.req)
    92         layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels)
    92         layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels)
    93         self.w(ureport_as_html(layout))
    93         self.w(uilib.ureport_as_html(layout))
    94         if not eschema.is_final():
    94         if not eschema.is_final():
    95             self.w(u'<img src="%s" alt="%s"/>' % (
    95             msg = self.req._('graphical schema for %s') % entity.name
    96                 html_escape(entity.absolute_url(vid='eschemagraph')),
    96             self.w(tags.img(src=entity.absolute_url(vid='eschemagraph'),
    97                 html_escape(self.req._('graphical schema for %s') % entity.name)))
    97                             alt=msg))
    98 
    98 
    99 
    99 
   100 class CWRTypeSchemaView(primary.PrimaryView):
   100 class CWRTypeSchemaView(primary.PrimaryView):
   101     id = 'eschema'
   101     id = 'eschema'
   102     __select__ = implements('CWRType')
   102     __select__ = implements('CWRType')
   103     title = _('in memory relation schema')
   103     title = _('in memory relation schema')
   104     main_related_section = False
   104     main_related_section = False
   105 
   105 
   106     def render_entity_attributes(self, entity, siderelations):
   106     def render_entity_attributes(self, entity):
   107         super(CWRTypeSchemaView, self).render_entity_attributes(entity, siderelations)
   107         super(CWRTypeSchemaView, self).render_entity_attributes(entity)
   108         rschema = self.vreg.schema.rschema(entity.name)
   108         rschema = self.vreg.schema.rschema(entity.name)
   109         viewer = SchemaViewer(self.req)
   109         viewer = SchemaViewer(self.req)
   110         layout = viewer.visit_relationschema(rschema)
   110         layout = viewer.visit_relationschema(rschema)
   111         self.w(ureport_as_html(layout))
   111         self.w(uilib.ureport_as_html(layout))
   112         if not rschema.is_final():
   112         if not rschema.is_final():
   113             self.w(u'<img src="%s" alt="%s"/>' % (
   113             msg = self.req._('graphical schema for %s') % entity.name
   114                 html_escape(entity.absolute_url(vid='eschemagraph')),
   114             self.w(tags.img(src=entity.absolute_url(vid='eschemagraph'),
   115                 html_escape(self.req._('graphical schema for %s') % entity.name)))
   115                             alt=msg))
   116 
   116 
   117 
   117 
   118 # schema images ###############################################################
   118 # schema images ###############################################################
   119 
   119 
   120 class ImageView(EntityView):
   120 class ImageView(EntityView):