|
1 """Specific views for schema related entities |
|
2 |
|
3 :organization: Logilab |
|
4 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 """ |
|
7 __docformat__ = "restructuredtext en" |
|
8 |
|
9 from logilab.mtconverter import html_escape |
|
10 |
|
11 from cubicweb.schemaviewer import SchemaViewer |
|
12 from cubicweb.common.uilib import ureport_as_html |
|
13 from cubicweb.common.view import EntityView |
|
14 from cubicweb.web.views import baseviews |
|
15 |
|
16 |
|
17 class ImageView(EntityView): |
|
18 accepts = ('EEType',) |
|
19 id = 'image' |
|
20 title = _('image') |
|
21 |
|
22 def cell_call(self, row, col): |
|
23 entity = self.entity(row, col) |
|
24 url = entity.absolute_url(vid='eschemagraph') |
|
25 self.w(u'<img src="%s" alt="%s"/>' % ( |
|
26 html_escape(url), |
|
27 html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
28 |
|
29 |
|
30 class _SchemaEntityPrimaryView(baseviews.PrimaryView): |
|
31 show_attr_label = False |
|
32 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
|
33 |
|
34 def content_title(self, entity): |
|
35 return html_escape(entity.dc_long_title()) |
|
36 |
|
37 class EETypePrimaryView(_SchemaEntityPrimaryView): |
|
38 accepts = ('EEType',) |
|
39 skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final') |
|
40 |
|
41 class ERTypePrimaryView(_SchemaEntityPrimaryView): |
|
42 accepts = ('ERType',) |
|
43 skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final', |
|
44 'symetric', 'inlined') |
|
45 |
|
46 class ErdefPrimaryView(_SchemaEntityPrimaryView): |
|
47 accepts = ('EFRDef', 'ENFRDef') |
|
48 show_attr_label = True |
|
49 |
|
50 class EETypeSchemaView(EETypePrimaryView): |
|
51 id = 'eschema' |
|
52 title = _('in memory entity schema') |
|
53 main_related_section = False |
|
54 skip_rels = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by', |
|
55 'has_text',) |
|
56 |
|
57 def render_entity_attributes(self, entity, siderelations): |
|
58 super(EETypeSchemaView, self).render_entity_attributes(entity, siderelations) |
|
59 eschema = self.vreg.schema.eschema(entity.name) |
|
60 viewer = SchemaViewer(self.req) |
|
61 layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels) |
|
62 self.w(ureport_as_html(layout)) |
|
63 if not eschema.is_final(): |
|
64 self.w(u'<img src="%s" alt="%s"/>' % ( |
|
65 html_escape(entity.absolute_url(vid='eschemagraph')), |
|
66 html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
67 |
|
68 class ERTypeSchemaView(ERTypePrimaryView): |
|
69 id = 'eschema' |
|
70 title = _('in memory relation schema') |
|
71 main_related_section = False |
|
72 |
|
73 def render_entity_attributes(self, entity, siderelations): |
|
74 super(ERTypeSchemaView, self).render_entity_attributes(entity, siderelations) |
|
75 rschema = self.vreg.schema.rschema(entity.name) |
|
76 viewer = SchemaViewer(self.req) |
|
77 layout = viewer.visit_relationschema(rschema) |
|
78 self.w(ureport_as_html(layout)) |
|
79 if not rschema.is_final(): |
|
80 self.w(u'<img src="%s" alt="%s"/>' % ( |
|
81 html_escape(entity.absolute_url(vid='eschemagraph')), |
|
82 html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
83 |
|
84 |
|
85 class EETypeWorkflowView(EntityView): |
|
86 id = 'workflow' |
|
87 accepts = ('EEType',) |
|
88 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
|
89 |
|
90 def cell_call(self, row, col, **kwargs): |
|
91 entity = self.entity(row, col) |
|
92 self.w(u'<h1>%s</h1>' % (self.req._('workflow for %s') |
|
93 % display_name(self.req, entity.name))) |
|
94 self.w(u'<img src="%s" alt="%s"/>' % ( |
|
95 html_escape(entity.absolute_url(vid='ewfgraph')), |
|
96 html_escape(self.req._('graphical workflow for %s') % entity.name))) |
|
97 |
|
98 |
|
99 class EETypeOneLineView(baseviews.OneLineView): |
|
100 accepts = ('EEType',) |
|
101 |
|
102 def cell_call(self, row, col, **kwargs): |
|
103 entity = self.entity(row, col) |
|
104 final = entity.final |
|
105 if final: |
|
106 self.w(u'<em class="finalentity">') |
|
107 super(EETypeOneLineView, self).cell_call(row, col, **kwargs) |
|
108 if final: |
|
109 self.w(u'</em>') |
|
110 |
|
111 |
|
112 from cubicweb.web.action import EntityAction |
|
113 |
|
114 class ViewWorkflowAction(EntityAction): |
|
115 id = 'workflow' |
|
116 category = 'mainactions' |
|
117 title = _('view workflow') |
|
118 accepts = ('EEType',) |
|
119 condition = 'S state_of X' # must have at least one state associated |
|
120 def url(self): |
|
121 entity = self.rset.get_entity(self.row or 0, self.col or 0) |
|
122 return entity.absolute_url(vid='workflow') |
|
123 |