"""Specific views for schema related entities:organization: Logilab:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr"""__docformat__="restructuredtext en"fromlogilab.mtconverterimporthtml_escapefromcubicweb.schemaviewerimportSchemaViewerfromcubicweb.common.uilibimportureport_as_htmlfromcubicweb.common.viewimportEntityViewfromcubicweb.web.viewsimportbaseviewsclassImageView(EntityView):accepts=('EEType',)id='image'title=_('image')defcell_call(self,row,col):entity=self.entity(row,col)url=entity.absolute_url(vid='eschemagraph')self.w(u'<img src="%s" alt="%s"/>'%(html_escape(url),html_escape(self.req._('graphical schema for %s')%entity.name)))class_SchemaEntityPrimaryView(baseviews.PrimaryView):show_attr_label=Falsecache_max_age=60*60*2# stay in http cache for 2 hours by default defcontent_title(self,entity):returnhtml_escape(entity.dc_long_title())classEETypePrimaryView(_SchemaEntityPrimaryView):accepts=('EEType',)skip_attrs=_SchemaEntityPrimaryView.skip_attrs+('name','meta','final')classERTypePrimaryView(_SchemaEntityPrimaryView):accepts=('ERType',)skip_attrs=_SchemaEntityPrimaryView.skip_attrs+('name','meta','final','symetric','inlined')classErdefPrimaryView(_SchemaEntityPrimaryView):accepts=('EFRDef','ENFRDef')show_attr_label=TrueclassEETypeSchemaView(EETypePrimaryView):id='eschema'title=_('in memory entity schema')main_related_section=Falseskip_rels=('is','is_instance_of','identity','created_by','owned_by','has_text',)defrender_entity_attributes(self,entity,siderelations):super(EETypeSchemaView,self).render_entity_attributes(entity,siderelations)eschema=self.vreg.schema.eschema(entity.name)viewer=SchemaViewer(self.req)layout=viewer.visit_entityschema(eschema,skiprels=self.skip_rels)self.w(ureport_as_html(layout))ifnoteschema.is_final():self.w(u'<img src="%s" alt="%s"/>'%(html_escape(entity.absolute_url(vid='eschemagraph')),html_escape(self.req._('graphical schema for %s')%entity.name)))classERTypeSchemaView(ERTypePrimaryView):id='eschema'title=_('in memory relation schema')main_related_section=Falsedefrender_entity_attributes(self,entity,siderelations):super(ERTypeSchemaView,self).render_entity_attributes(entity,siderelations)rschema=self.vreg.schema.rschema(entity.name)viewer=SchemaViewer(self.req)layout=viewer.visit_relationschema(rschema)self.w(ureport_as_html(layout))ifnotrschema.is_final():self.w(u'<img src="%s" alt="%s"/>'%(html_escape(entity.absolute_url(vid='eschemagraph')),html_escape(self.req._('graphical schema for %s')%entity.name)))classEETypeWorkflowView(EntityView):id='workflow'accepts=('EEType',)cache_max_age=60*60*2# stay in http cache for 2 hours by default defcell_call(self,row,col,**kwargs):entity=self.entity(row,col)self.w(u'<h1>%s</h1>'%(self.req._('workflow for %s')%display_name(self.req,entity.name)))self.w(u'<img src="%s" alt="%s"/>'%(html_escape(entity.absolute_url(vid='ewfgraph')),html_escape(self.req._('graphical workflow for %s')%entity.name)))classEETypeOneLineView(baseviews.OneLineView):accepts=('EEType',)defcell_call(self,row,col,**kwargs):entity=self.entity(row,col)final=entity.finaliffinal:self.w(u'<em class="finalentity">')super(EETypeOneLineView,self).cell_call(row,col,**kwargs)iffinal:self.w(u'</em>')fromcubicweb.web.actionimportEntityActionclassViewWorkflowAction(EntityAction):id='workflow'category='mainactions'title=_('view workflow')accepts=('EEType',)condition='S state_of X'# must have at least one state associateddefurl(self):entity=self.rset.get_entity(self.rowor0,self.color0)returnentity.absolute_url(vid='workflow')