web/views/schema.py
branchtls-sprint
changeset 1398 5fe84a5f7035
parent 1263 01152fffd593
child 1498 2c6eec0b46b9
equal deleted inserted replaced
1397:6cbc7bc8ea6d 1398:5fe84a5f7035
    20 from cubicweb.web.views import TmpFileViewMixin
    20 from cubicweb.web.views import TmpFileViewMixin
    21 from cubicweb.web.views.editforms import AutomaticEntityForm
    21 from cubicweb.web.views.editforms import AutomaticEntityForm
    22 from cubicweb.web.views.boxes import EditBox
    22 from cubicweb.web.views.boxes import EditBox
    23 
    23 
    24 
    24 
    25 AutomaticEntityForm.rcategories.set_rtag('primary', 'require_group', 'subject', 'EPermission')
    25 AutomaticEntityForm.rcategories.set_rtag('primary', 'require_group', 'subject', 'CWPermission')
    26 AutomaticEntityForm.rcategories.set_rtag('generated', 'final', 'subject', 'EEtype')
    26 AutomaticEntityForm.rcategories.set_rtag('generated', 'final', 'subject', 'EEtype')
    27 AutomaticEntityForm.rcategories.set_rtag('generated', 'final', 'subject', 'ERtype')
    27 AutomaticEntityForm.rcategories.set_rtag('generated', 'final', 'subject', 'ERtype')
    28 AutomaticEntityForm.rinlined.set_rtag(True, 'relation_type', 'subject', 'ENFRDef')
    28 AutomaticEntityForm.rinlined.set_rtag(True, 'relation_type', 'subject', 'CWRelation')
    29 AutomaticEntityForm.rinlined.set_rtag(True, 'from_entity', 'subject', 'ENFRDef')
    29 AutomaticEntityForm.rinlined.set_rtag(True, 'from_entity', 'subject', 'CWRelation')
    30 AutomaticEntityForm.rinlined.set_rtag(True, 'to_entity', 'subject', 'ENFRDef')
    30 AutomaticEntityForm.rinlined.set_rtag(True, 'to_entity', 'subject', 'CWRelation')
    31 AutomaticEntityForm.rwidgets.set_rtag('StringWidget', 'expression', 'subject', 'RQLExpression')
    31 AutomaticEntityForm.rwidgets.set_rtag('StringWidget', 'expression', 'subject', 'RQLExpression')
    32 
    32 
    33 EditBox.rmode.set_rtag('create', 'state_of', 'object', 'EEType')
    33 EditBox.rmode.set_rtag('create', 'state_of', 'object', 'CWEType')
    34 EditBox.rmode.set_rtag('create', 'transition_of', 'object', 'EEType')
    34 EditBox.rmode.set_rtag('create', 'transition_of', 'object', 'CWEType')
    35 EditBox.rmode.set_rtag('create', 'relation_type', 'object', 'ERType')
    35 EditBox.rmode.set_rtag('create', 'relation_type', 'object', 'CWRType')
    36 EditBox.rmode.set_rtag('link', 'from_entity', 'object', 'EEType')
    36 EditBox.rmode.set_rtag('link', 'from_entity', 'object', 'CWEType')
    37 EditBox.rmode.set_rtag('link', 'to_entity', 'object', 'EEType')
    37 EditBox.rmode.set_rtag('link', 'to_entity', 'object', 'CWEType')
    38 
    38 
    39 
    39 
    40 class ViewSchemaAction(Action):
    40 class ViewSchemaAction(Action):
    41     id = 'schema'
    41     id = 'schema'
    42     __select__ = yes()
    42     __select__ = yes()
    56     cache_max_age = 60*60*2 # stay in http cache for 2 hours by default 
    56     cache_max_age = 60*60*2 # stay in http cache for 2 hours by default 
    57     
    57     
    58     def content_title(self, entity):
    58     def content_title(self, entity):
    59         return html_escape(entity.dc_long_title())
    59         return html_escape(entity.dc_long_title())
    60     
    60     
    61 class EETypePrimaryView(_SchemaEntityPrimaryView):
    61 class CWETypePrimaryView(_SchemaEntityPrimaryView):
    62     __select__ = implements('EEType')
    62     __select__ = implements('CWEType')
    63     skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final')
    63     skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final')
    64 
    64 
    65 class ERTypePrimaryView(_SchemaEntityPrimaryView):
    65 class CWRTypePrimaryView(_SchemaEntityPrimaryView):
    66     __select__ = implements('ERType')
    66     __select__ = implements('CWRType')
    67     skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final',
    67     skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final',
    68                                                         'symetric', 'inlined')
    68                                                         'symetric', 'inlined')
    69 
    69 
    70 class ErdefPrimaryView(_SchemaEntityPrimaryView):
    70 class ErdefPrimaryView(_SchemaEntityPrimaryView):
    71     __select__ = implements('EFRDef', 'ENFRDef')
    71     __select__ = implements('CWAttribute', 'CWRelation')
    72     show_attr_label = True
    72     show_attr_label = True
    73 
    73 
    74 class EETypeOneLineView(baseviews.OneLineView):
    74 class CWETypeOneLineView(baseviews.OneLineView):
    75     __select__ = implements('EEType')
    75     __select__ = implements('CWEType')
    76     
    76     
    77     def cell_call(self, row, col, **kwargs):
    77     def cell_call(self, row, col, **kwargs):
    78         entity = self.entity(row, col)
    78         entity = self.entity(row, col)
    79         final = entity.final
    79         final = entity.final
    80         if final:
    80         if final:
    81             self.w(u'<em class="finalentity">')
    81             self.w(u'<em class="finalentity">')
    82         super(EETypeOneLineView, self).cell_call(row, col, **kwargs)
    82         super(CWETypeOneLineView, self).cell_call(row, col, **kwargs)
    83         if final:
    83         if final:
    84             self.w(u'</em>')
    84             self.w(u'</em>')
    85 
    85 
    86 
    86 
    87 # in memory schema views (yams class instances) ###############################
    87 # in memory schema views (yams class instances) ###############################
    88 
    88 
    89 class EETypeSchemaView(EETypePrimaryView):
    89 class CWETypeSchemaView(CWETypePrimaryView):
    90     id = 'eschema'
    90     id = 'eschema'
    91     title = _('in memory entity schema')
    91     title = _('in memory entity schema')
    92     main_related_section = False
    92     main_related_section = False
    93     skip_rels = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by',
    93     skip_rels = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by',
    94                  'has_text',)
    94                  'has_text',)
    95     
    95     
    96     def render_entity_attributes(self, entity, siderelations):
    96     def render_entity_attributes(self, entity, siderelations):
    97         super(EETypeSchemaView, self).render_entity_attributes(entity, siderelations)
    97         super(CWETypeSchemaView, self).render_entity_attributes(entity, siderelations)
    98         eschema = self.vreg.schema.eschema(entity.name)
    98         eschema = self.vreg.schema.eschema(entity.name)
    99         viewer = SchemaViewer(self.req)
    99         viewer = SchemaViewer(self.req)
   100         layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels)
   100         layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels)
   101         self.w(ureport_as_html(layout))
   101         self.w(ureport_as_html(layout))
   102         if not eschema.is_final():
   102         if not eschema.is_final():
   103             self.w(u'<img src="%s" alt="%s"/>' % (
   103             self.w(u'<img src="%s" alt="%s"/>' % (
   104                 html_escape(entity.absolute_url(vid='eschemagraph')),
   104                 html_escape(entity.absolute_url(vid='eschemagraph')),
   105                 html_escape(self.req._('graphical schema for %s') % entity.name)))
   105                 html_escape(self.req._('graphical schema for %s') % entity.name)))
   106 
   106 
   107 
   107 
   108 class ERTypeSchemaView(ERTypePrimaryView):
   108 class CWRTypeSchemaView(CWRTypePrimaryView):
   109     id = 'eschema'
   109     id = 'eschema'
   110     title = _('in memory relation schema')
   110     title = _('in memory relation schema')
   111     main_related_section = False
   111     main_related_section = False
   112 
   112 
   113     def render_entity_attributes(self, entity, siderelations):
   113     def render_entity_attributes(self, entity, siderelations):
   114         super(ERTypeSchemaView, self).render_entity_attributes(entity, siderelations)
   114         super(CWRTypeSchemaView, self).render_entity_attributes(entity, siderelations)
   115         rschema = self.vreg.schema.rschema(entity.name)
   115         rschema = self.vreg.schema.rschema(entity.name)
   116         viewer = SchemaViewer(self.req)
   116         viewer = SchemaViewer(self.req)
   117         layout = viewer.visit_relationschema(rschema)
   117         layout = viewer.visit_relationschema(rschema)
   118         self.w(ureport_as_html(layout))
   118         self.w(ureport_as_html(layout))
   119         if not rschema.is_final():
   119         if not rschema.is_final():
   123         
   123         
   124 
   124 
   125 # schema images ###############################################################
   125 # schema images ###############################################################
   126 
   126 
   127 class ImageView(EntityView):
   127 class ImageView(EntityView):
   128     __select__ = implements('EEType')
   128     __select__ = implements('CWEType')
   129     id = 'image'
   129     id = 'image'
   130     title = _('image')
   130     title = _('image')
   131 
   131 
   132     def cell_call(self, row, col):
   132     def cell_call(self, row, col):
   133         entity = self.entity(row, col)
   133         entity = self.entity(row, col)
   208         skipmeta = not int(self.req.form.get('withmeta', 0))
   208         skipmeta = not int(self.req.form.get('withmeta', 0))
   209         visitor = FullSchemaVisitor(self.req, self.schema, skiprels=self.skip_rels, skipmeta=skipmeta)
   209         visitor = FullSchemaVisitor(self.req, self.schema, skiprels=self.skip_rels, skipmeta=skipmeta)
   210         s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
   210         s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
   211                        prophdlr=RestrictedSchemaDotPropsHandler(self.req))
   211                        prophdlr=RestrictedSchemaDotPropsHandler(self.req))
   212 
   212 
   213 class EETypeSchemaImageView(TmpFileViewMixin, EntityView):
   213 class CWETypeSchemaImageView(TmpFileViewMixin, EntityView):
   214     id = 'eschemagraph'
   214     id = 'eschemagraph'
   215     content_type = 'image/png'
   215     content_type = 'image/png'
   216     __select__ = implements('EEType')
   216     __select__ = implements('CWEType')
   217     skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of')
   217     skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of')
   218     
   218     
   219     def _generate(self, tmpfile):
   219     def _generate(self, tmpfile):
   220         """display schema information for an entity"""
   220         """display schema information for an entity"""
   221         entity = self.entity(self.row, self.col)
   221         entity = self.entity(self.row, self.col)
   222         eschema = self.vreg.schema.eschema(entity.name)
   222         eschema = self.vreg.schema.eschema(entity.name)
   223         visitor = OneHopESchemaVisitor(self.req, eschema, skiprels=self.skip_rels)
   223         visitor = OneHopESchemaVisitor(self.req, eschema, skiprels=self.skip_rels)
   224         s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
   224         s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
   225                        prophdlr=RestrictedSchemaDotPropsHandler(self.req))
   225                        prophdlr=RestrictedSchemaDotPropsHandler(self.req))
   226 
   226 
   227 class ERTypeSchemaImageView(EETypeSchemaImageView):
   227 class CWRTypeSchemaImageView(CWETypeSchemaImageView):
   228     __select__ = implements('ERType')
   228     __select__ = implements('CWRType')
   229     
   229     
   230     def _generate(self, tmpfile):
   230     def _generate(self, tmpfile):
   231         """display schema information for an entity"""
   231         """display schema information for an entity"""
   232         entity = self.entity(self.row, self.col)
   232         entity = self.entity(self.row, self.col)
   233         rschema = self.vreg.schema.rschema(entity.name)
   233         rschema = self.vreg.schema.rschema(entity.name)