author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Wed, 18 Feb 2009 10:06:20 +0100 | |
branch | tls-sprint |
changeset 760 | 95b3419e94c5 |
parent 728 | a95b284150d1 |
child 787 | b9eb2475b446 |
permissions | -rw-r--r-- |
0 | 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 |
||
688
cddfbdee0eb3
remove all accepts = ('Foo',) declaration and use __selectors__ = implements('Foo') instead
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
652
diff
changeset
|
11 |
from cubicweb.selectors import implements, rql_condition |
0 | 12 |
from cubicweb.schemaviewer import SchemaViewer |
13 |
from cubicweb.common.uilib import ureport_as_html |
|
14 |
from cubicweb.common.view import EntityView |
|
15 |
from cubicweb.web.views import baseviews |
|
16 |
||
17 |
||
18 |
class ImageView(EntityView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
19 |
__select__ = implements('EEType') |
0 | 20 |
id = 'image' |
21 |
title = _('image') |
|
22 |
||
23 |
def cell_call(self, row, col): |
|
24 |
entity = self.entity(row, col) |
|
25 |
url = entity.absolute_url(vid='eschemagraph') |
|
26 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
|
27 |
html_escape(url), |
|
28 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
29 |
||
30 |
||
31 |
class _SchemaEntityPrimaryView(baseviews.PrimaryView): |
|
32 |
show_attr_label = False |
|
33 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
|
34 |
||
35 |
def content_title(self, entity): |
|
36 |
return html_escape(entity.dc_long_title()) |
|
37 |
||
38 |
class EETypePrimaryView(_SchemaEntityPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
39 |
__select__ = implements('EEType') |
0 | 40 |
skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final') |
41 |
||
42 |
class ERTypePrimaryView(_SchemaEntityPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
43 |
__select__ = implements('ERType') |
0 | 44 |
skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final', |
45 |
'symetric', 'inlined') |
|
46 |
||
47 |
class ErdefPrimaryView(_SchemaEntityPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
48 |
__select__ = implements('EEType', 'ENFRDef') |
0 | 49 |
show_attr_label = True |
50 |
||
51 |
class EETypeSchemaView(EETypePrimaryView): |
|
52 |
id = 'eschema' |
|
53 |
title = _('in memory entity schema') |
|
54 |
main_related_section = False |
|
55 |
skip_rels = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by', |
|
56 |
'has_text',) |
|
57 |
||
58 |
def render_entity_attributes(self, entity, siderelations): |
|
59 |
super(EETypeSchemaView, self).render_entity_attributes(entity, siderelations) |
|
60 |
eschema = self.vreg.schema.eschema(entity.name) |
|
61 |
viewer = SchemaViewer(self.req) |
|
62 |
layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels) |
|
63 |
self.w(ureport_as_html(layout)) |
|
64 |
if not eschema.is_final(): |
|
65 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
|
66 |
html_escape(entity.absolute_url(vid='eschemagraph')), |
|
67 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
68 |
||
69 |
class ERTypeSchemaView(ERTypePrimaryView): |
|
70 |
id = 'eschema' |
|
71 |
title = _('in memory relation schema') |
|
72 |
main_related_section = False |
|
73 |
||
74 |
def render_entity_attributes(self, entity, siderelations): |
|
75 |
super(ERTypeSchemaView, self).render_entity_attributes(entity, siderelations) |
|
76 |
rschema = self.vreg.schema.rschema(entity.name) |
|
77 |
viewer = SchemaViewer(self.req) |
|
78 |
layout = viewer.visit_relationschema(rschema) |
|
79 |
self.w(ureport_as_html(layout)) |
|
80 |
if not rschema.is_final(): |
|
81 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
|
82 |
html_escape(entity.absolute_url(vid='eschemagraph')), |
|
83 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
84 |
||
85 |
||
86 |
class EETypeWorkflowView(EntityView): |
|
87 |
id = 'workflow' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
88 |
__select__ = implements('EEType') |
0 | 89 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
90 |
||
91 |
def cell_call(self, row, col, **kwargs): |
|
92 |
entity = self.entity(row, col) |
|
93 |
self.w(u'<h1>%s</h1>' % (self.req._('workflow for %s') |
|
94 |
% display_name(self.req, entity.name))) |
|
95 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
|
96 |
html_escape(entity.absolute_url(vid='ewfgraph')), |
|
97 |
html_escape(self.req._('graphical workflow for %s') % entity.name))) |
|
98 |
||
99 |
||
100 |
class EETypeOneLineView(baseviews.OneLineView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
101 |
__select__ = implements('EEType') |
0 | 102 |
|
103 |
def cell_call(self, row, col, **kwargs): |
|
104 |
entity = self.entity(row, col) |
|
105 |
final = entity.final |
|
106 |
if final: |
|
107 |
self.w(u'<em class="finalentity">') |
|
108 |
super(EETypeOneLineView, self).cell_call(row, col, **kwargs) |
|
109 |
if final: |
|
110 |
self.w(u'</em>') |
|
111 |
||
112 |
||
652
603c782dc092
various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
640
diff
changeset
|
113 |
from cubicweb.web.action import Action |
0 | 114 |
|
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
115 |
class ViewWorkflowAction(Action): |
0 | 116 |
id = 'workflow' |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
117 |
__select__ = implements('EEType') & rql_condition('S state_of X') |
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
118 |
|
0 | 119 |
category = 'mainactions' |
120 |
title = _('view workflow') |
|
121 |
def url(self): |
|
122 |
entity = self.rset.get_entity(self.row or 0, self.col or 0) |
|
123 |
return entity.absolute_url(vid='workflow') |
|
124 |