web/views/schema.py
changeset 3230 1d25e928c299
parent 2789 39712da6f397
parent 3220 11b6016e3970
child 3293 69c0ba095536
equal deleted inserted replaced
3199:fc63b80ec979 3230:1d25e928c299
    10 from itertools import cycle
    10 from itertools import cycle
    11 
    11 
    12 from logilab.mtconverter import xml_escape
    12 from logilab.mtconverter import xml_escape
    13 from yams import BASE_TYPES, schema2dot as s2d
    13 from yams import BASE_TYPES, schema2dot as s2d
    14 
    14 
    15 from cubicweb.selectors import implements, yes, match_user_groups
    15 from cubicweb.selectors import (implements, yes, match_user_groups,
       
    16                                 has_related_entities)
    16 from cubicweb.schema import META_RTYPES, SCHEMA_TYPES
    17 from cubicweb.schema import META_RTYPES, SCHEMA_TYPES
    17 from cubicweb.schemaviewer import SchemaViewer
    18 from cubicweb.schemaviewer import SchemaViewer
    18 from cubicweb.view import EntityView, StartupView
    19 from cubicweb.view import EntityView, StartupView
    19 from cubicweb.common import tags, uilib
    20 from cubicweb.common import tags, uilib
    20 from cubicweb.web import action, facet
    21 from cubicweb.web import action, facet
   267         url = entity.absolute_url(vid='schemagraph')
   268         url = entity.absolute_url(vid='schemagraph')
   268         self.w(u'<img src="%s" alt="%s"/>' % (
   269         self.w(u'<img src="%s" alt="%s"/>' % (
   269             xml_escape(url),
   270             xml_escape(url),
   270             xml_escape(self.req._('graphical schema for %s') % entity.name)))
   271             xml_escape(self.req._('graphical schema for %s') % entity.name)))
   271 
   272 
       
   273 
   272 class CWETypeSPermView(EntityView):
   274 class CWETypeSPermView(EntityView):
   273     id = 'cwetype-schema-permissions'
   275     id = 'cwetype-schema-permissions'
   274     __select__ = EntityView.__select__ & implements('CWEType')
   276     __select__ = EntityView.__select__ & implements('CWEType')
   275 
   277 
   276     def cell_call(self, row, col):
   278     def cell_call(self, row, col):
   294         rset = self.req.execute('Any P WHERE X delete_permission P, '
   296         rset = self.req.execute('Any P WHERE X delete_permission P, '
   295                                 'X eid %(x)s',
   297                                 'X eid %(x)s',
   296                                 {'x': entity.eid})
   298                                 {'x': entity.eid})
   297         self.wview('outofcontext', rset, 'null')
   299         self.wview('outofcontext', rset, 'null')
   298 
   300 
       
   301 
   299 class CWETypeSWorkflowView(EntityView):
   302 class CWETypeSWorkflowView(EntityView):
   300     id = 'cwetype-workflow'
   303     id = 'cwetype-workflow'
   301     __select__ = EntityView.__select__ & implements('CWEType')
   304     __select__ = (EntityView.__select__ & implements('CWEType') &
       
   305                   has_related_entities('workflow_of', 'object'))
   302 
   306 
   303     def cell_call(self, row, col):
   307     def cell_call(self, row, col):
   304         entity = self.rset.get_entity(row, col)
   308         entity = self.rset.get_entity(row, col)
   305         if entity.reverse_state_of:
   309         if entity.default_workflow:
   306             self.w(u'<img src="%s" alt="%s"/>' % (
   310             wf = entity.default_workflow[0]
   307                     xml_escape(entity.absolute_url(vid='ewfgraph')),
   311             self.w(u'<h1>%s (%s)</h1>' % (wf.name, self.req._('default')))
   308                     xml_escape(self.req._('graphical workflow for %s') % entity.name)))
   312             self.wf_image(wf)
   309         else:
   313         for altwf in entity.reverse_workflow_of:
   310             self.w(u'<p>%s</p>' % _('There is no workflow defined for this entity.'))
   314             if altwf.eid == wf.eid:
       
   315                 continue
       
   316             self.w(u'<h1>%s</h1>' % altwf.name)
       
   317             self.wf_image(altwf)
       
   318 
       
   319     def wf_image(self, wf):
       
   320         self.w(u'<img src="%s" alt="%s"/>' % (
       
   321             xml_escape(wf.absolute_url(vid='wfgraph')),
       
   322             xml_escape(self.req._('graphical representation of %s') % wf.name)))
       
   323 
   311 
   324 
   312 # CWRType ######################################################################
   325 # CWRType ######################################################################
   313 
   326 
   314 class CWRTypeSchemaView(primary.PrimaryView):
   327 class CWRTypeSchemaView(primary.PrimaryView):
   315     __select__ = implements('CWRType')
   328     __select__ = implements('CWRType')