web/views/schema.py
changeset 3377 dd9d292b6a6d
parent 3293 69c0ba095536
child 3451 6b46d73823f5
equal deleted inserted replaced
3376:f5c69485381f 3377:dd9d292b6a6d
    35     return ALWAYS_SKIP_TYPES
    35     return ALWAYS_SKIP_TYPES
    36 
    36 
    37 # global schema view ###########################################################
    37 # global schema view ###########################################################
    38 
    38 
    39 class SchemaView(tabs.TabsMixin, StartupView):
    39 class SchemaView(tabs.TabsMixin, StartupView):
    40     id = 'schema'
    40     __regid__ = 'schema'
    41     title = _('instance schema')
    41     title = _('instance schema')
    42     tabs = [_('schema-text'), _('schema-image')]
    42     tabs = [_('schema-text'), _('schema-image')]
    43     default_tab = 'schema-text'
    43     default_tab = 'schema-text'
    44 
    44 
    45     def call(self):
    45     def call(self):
    49         self.w(u'<h1>%s</h1>' % _('Schema of the data model'))
    49         self.w(u'<h1>%s</h1>' % _('Schema of the data model'))
    50         self.render_tabs(self.tabs, self.default_tab)
    50         self.render_tabs(self.tabs, self.default_tab)
    51 
    51 
    52 
    52 
    53 class SchemaTabImageView(StartupView):
    53 class SchemaTabImageView(StartupView):
    54     id = 'schema-image'
    54     __regid__ = 'schema-image'
    55 
    55 
    56     def call(self):
    56     def call(self):
    57         self.w(_(u'<div>This schema of the data model <em>excludes</em> the '
    57         self.w(_(u'<div>This schema of the data model <em>excludes</em> the '
    58                  u'meta-data, but you can also display a <a href="%s">complete '
    58                  u'meta-data, but you can also display a <a href="%s">complete '
    59                  u'schema with meta-data</a>.</div>')
    59                  u'schema with meta-data</a>.</div>')
    62             xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)),
    62             xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)),
    63             self.req._("graphical representation of the instance'schema")))
    63             self.req._("graphical representation of the instance'schema")))
    64 
    64 
    65 
    65 
    66 class SchemaTabTextView(StartupView):
    66 class SchemaTabTextView(StartupView):
    67     id = 'schema-text'
    67     __regid__ = 'schema-text'
    68 
    68 
    69     def call(self):
    69     def call(self):
    70         rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, '
    70         rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, '
    71                                 'X final FALSE')
    71                                 'X final FALSE')
    72         self.wview('table', rset, displayfilter=True)
    72         self.wview('table', rset, displayfilter=True)
    73 
    73 
    74 
    74 
    75 class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn):
    75 class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn):
    76     id = 'schema-security'
    76     __regid__ = 'schema-security'
    77     __select__ = StartupView.__select__ & match_user_groups('managers')
    77     __select__ = StartupView.__select__ & match_user_groups('managers')
    78 
    78 
    79     def call(self, display_relations=True):
    79     def call(self, display_relations=True):
    80         self.req.add_css('cubicweb.acl.css')
    80         self.req.add_css('cubicweb.acl.css')
    81         skiptypes = skip_types(self.req)
    81         skiptypes = skip_types(self.req)
   171             self.schema_definition(rschema, link=False)
   171             self.schema_definition(rschema, link=False)
   172             self.w(u'</div>')
   172             self.w(u'</div>')
   173 
   173 
   174 
   174 
   175 class SchemaUreportsView(StartupView):
   175 class SchemaUreportsView(StartupView):
   176     id = 'schema-block'
   176     __regid__ = 'schema-block'
   177 
   177 
   178     def call(self):
   178     def call(self):
   179         viewer = SchemaViewer(self.req)
   179         viewer = SchemaViewer(self.req)
   180         layout = viewer.visit_schema(self.schema, display_relations=True,
   180         layout = viewer.visit_schema(self.schema, display_relations=True,
   181                                      skiptypes=skip_types(self.req))
   181                                      skiptypes=skip_types(self.req))
   222         self.w(u'<div>%s</div>' % entity.description)
   222         self.w(u'<div>%s</div>' % entity.description)
   223         self.render_tabs(self.tabs, self.default_tab, entity)
   223         self.render_tabs(self.tabs, self.default_tab, entity)
   224 
   224 
   225 
   225 
   226 class CWETypeSTextView(EntityView):
   226 class CWETypeSTextView(EntityView):
   227     id = 'cwetype-schema-text'
   227     __regid__ = 'cwetype-schema-text'
   228     __select__ = EntityView.__select__ & implements('CWEType')
   228     __select__ = EntityView.__select__ & implements('CWEType')
   229 
   229 
   230     def cell_call(self, row, col):
   230     def cell_call(self, row, col):
   231         entity = self.rset.get_entity(row, col)
   231         entity = self.rset.get_entity(row, col)
   232         self.w(u'<h2>%s</h2>' % _('Attributes'))
   232         self.w(u'<h2>%s</h2>' % _('Attributes'))
   258         self.wview('editable-table', rset, 'null', displayfilter=True,
   258         self.wview('editable-table', rset, 'null', displayfilter=True,
   259                    displaycols=range(6), mainindex=5)
   259                    displaycols=range(6), mainindex=5)
   260 
   260 
   261 
   261 
   262 class CWETypeSImageView(EntityView):
   262 class CWETypeSImageView(EntityView):
   263     id = 'cwetype-schema-image'
   263     __regid__ = 'cwetype-schema-image'
   264     __select__ = EntityView.__select__ & implements('CWEType')
   264     __select__ = EntityView.__select__ & implements('CWEType')
   265 
   265 
   266     def cell_call(self, row, col):
   266     def cell_call(self, row, col):
   267         entity = self.rset.get_entity(row, col)
   267         entity = self.rset.get_entity(row, col)
   268         url = entity.absolute_url(vid='schemagraph')
   268         url = entity.absolute_url(vid='schemagraph')
   270             xml_escape(url),
   270             xml_escape(url),
   271             xml_escape(self.req._('graphical schema for %s') % entity.name)))
   271             xml_escape(self.req._('graphical schema for %s') % entity.name)))
   272 
   272 
   273 
   273 
   274 class CWETypeSPermView(EntityView):
   274 class CWETypeSPermView(EntityView):
   275     id = 'cwetype-schema-permissions'
   275     __regid__ = 'cwetype-schema-permissions'
   276     __select__ = EntityView.__select__ & implements('CWEType')
   276     __select__ = EntityView.__select__ & implements('CWEType')
   277 
   277 
   278     def cell_call(self, row, col):
   278     def cell_call(self, row, col):
   279         entity = self.rset.get_entity(row, col)
   279         entity = self.rset.get_entity(row, col)
   280         self.w(u'<h2>%s</h2>' % _('Add permissions'))
   280         self.w(u'<h2>%s</h2>' % _('Add permissions'))
   298                                 {'x': entity.eid})
   298                                 {'x': entity.eid})
   299         self.wview('outofcontext', rset, 'null')
   299         self.wview('outofcontext', rset, 'null')
   300 
   300 
   301 
   301 
   302 class CWETypeSWorkflowView(EntityView):
   302 class CWETypeSWorkflowView(EntityView):
   303     id = 'cwetype-workflow'
   303     __regid__ = 'cwetype-workflow'
   304     __select__ = (EntityView.__select__ & implements('CWEType') &
   304     __select__ = (EntityView.__select__ & implements('CWEType') &
   305                   has_related_entities('workflow_of', 'object'))
   305                   has_related_entities('workflow_of', 'object'))
   306 
   306 
   307     def cell_call(self, row, col):
   307     def cell_call(self, row, col):
   308         entity = self.rset.get_entity(row, col)
   308         entity = self.rset.get_entity(row, col)
   370                            s2d.OneHopRSchemaVisitor):
   370                            s2d.OneHopRSchemaVisitor):
   371     pass
   371     pass
   372 
   372 
   373 
   373 
   374 class SchemaImageView(TmpFileViewMixin, StartupView):
   374 class SchemaImageView(TmpFileViewMixin, StartupView):
   375     id = 'schemagraph'
   375     __regid__ = 'schemagraph'
   376     content_type = 'image/png'
   376     content_type = 'image/png'
   377 
   377 
   378     def _generate(self, tmpfile):
   378     def _generate(self, tmpfile):
   379         """display global schema information"""
   379         """display global schema information"""
   380         print 'skipedtypes', skip_types(self.req)
   380         print 'skipedtypes', skip_types(self.req)
   382                                     skiptypes=skip_types(self.req))
   382                                     skiptypes=skip_types(self.req))
   383         s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
   383         s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
   384 
   384 
   385 
   385 
   386 class CWETypeSchemaImageView(TmpFileViewMixin, EntityView):
   386 class CWETypeSchemaImageView(TmpFileViewMixin, EntityView):
   387     id = 'schemagraph'
   387     __regid__ = 'schemagraph'
   388     __select__ = implements('CWEType')
   388     __select__ = implements('CWEType')
   389     content_type = 'image/png'
   389     content_type = 'image/png'
   390 
   390 
   391     def _generate(self, tmpfile):
   391     def _generate(self, tmpfile):
   392         """display schema information for an entity"""
   392         """display schema information for an entity"""
   409 
   409 
   410 
   410 
   411 # misc: facets, actions ########################################################
   411 # misc: facets, actions ########################################################
   412 
   412 
   413 class CWFinalFacet(facet.AttributeFacet):
   413 class CWFinalFacet(facet.AttributeFacet):
   414     id = 'cwfinal-facet'
   414     __regid__ = 'cwfinal-facet'
   415     __select__ = facet.AttributeFacet.__select__ & implements('CWEType', 'CWRType')
   415     __select__ = facet.AttributeFacet.__select__ & implements('CWEType', 'CWRType')
   416     rtype = 'final'
   416     rtype = 'final'
   417 
   417 
   418 class ViewSchemaAction(action.Action):
   418 class ViewSchemaAction(action.Action):
   419     id = 'schema'
   419     __regid__ = 'schema'
   420     __select__ = yes()
   420     __select__ = yes()
   421 
   421 
   422     title = _("site schema")
   422     title = _("site schema")
   423     category = 'siteactions'
   423     category = 'siteactions'
   424     order = 30
   424     order = 30