4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
|
9 _ = unicode |
9 |
10 |
10 from logilab.common.ureports import Section, Title, Table, Link, Span, Text |
11 from logilab.common.ureports import Section, Title, Table, Link, Span, Text |
11 from yams.schema2dot import CARD_MAP |
12 from yams.schema2dot import CARD_MAP |
12 |
13 |
13 _ = unicode |
|
14 I18NSTRINGS = [_('read'), _('add'), _('delete'), _('update'), _('order')] |
14 I18NSTRINGS = [_('read'), _('add'), _('delete'), _('update'), _('order')] |
15 |
15 |
16 class SchemaViewer(object): |
16 class SchemaViewer(object): |
17 """return an ureport layout for some part of a schema""" |
17 """return an ureport layout for some part of a schema""" |
18 def __init__(self, req=None, encoding=None): |
18 def __init__(self, req=None, encoding=None): |
36 data.append(', '.join(acls)) |
36 data.append(', '.join(acls)) |
37 return Section(children=(Table(cols=2, cheaders=1, rheaders=1, children=data),), |
37 return Section(children=(Table(cols=2, cheaders=1, rheaders=1, children=data),), |
38 klass='acl') |
38 klass='acl') |
39 |
39 |
40 |
40 |
41 def visit_schema(self, schema, display_relations=0, |
41 def visit_schema(self, schema, display_relations=0, skiptypes=()): |
42 skiprels=(), skipmeta=True): |
|
43 """get a layout for a whole schema""" |
42 """get a layout for a whole schema""" |
44 title = Title(self.req._('Schema %s') % schema.name, |
43 title = Title(self.req._('Schema %s') % schema.name, |
45 klass='titleUnderline') |
44 klass='titleUnderline') |
46 layout = Section(children=(title,)) |
45 layout = Section(children=(title,)) |
47 esection = Section(children=(Title(self.req._('Entities'), |
46 esection = Section(children=(Title(self.req._('Entities'), |
48 klass='titleUnderline'),)) |
47 klass='titleUnderline'),)) |
49 layout.append(esection) |
48 layout.append(esection) |
50 eschemas = [eschema for eschema in schema.entities() |
49 eschemas = [eschema for eschema in schema.entities() |
51 if not eschema.is_final()] |
50 if not (eschema.is_final() or eschema in skiptypes)] |
52 if skipmeta: |
|
53 eschemas = [eschema for eschema in eschemas |
|
54 if not eschema.meta] |
|
55 for eschema in sorted(eschemas): |
51 for eschema in sorted(eschemas): |
56 esection.append(self.visit_entityschema(eschema, skiprels)) |
52 esection.append(self.visit_entityschema(eschema, skiptypes)) |
57 if display_relations: |
53 if display_relations: |
58 title = Title(self.req._('Relations'), klass='titleUnderline') |
54 title = Title(self.req._('Relations'), klass='titleUnderline') |
59 rsection = Section(children=(title,)) |
55 rsection = Section(children=(title,)) |
60 layout.append(rsection) |
56 layout.append(rsection) |
61 relations = [rschema for rschema in schema.relations() |
57 relations = [rschema for rschema in schema.relations() |
62 if not (rschema.is_final() or rschema.type in skiprels)] |
58 if not (rschema.is_final() or rschema.type in skiptypes)] |
63 if skipmeta: |
|
64 relations = [rschema for rschema in relations |
|
65 if not rschema.meta] |
|
66 keys = [(rschema.type, rschema) for rschema in relations] |
59 keys = [(rschema.type, rschema) for rschema in relations] |
67 for key, rschema in sorted(keys): |
60 for key, rschema in sorted(keys): |
68 relstr = self.visit_relationschema(rschema) |
61 relstr = self.visit_relationschema(rschema) |
69 rsection.append(relstr) |
62 rsection.append(relstr) |
70 return layout |
63 return layout |
105 if v.category != 'startupview'] |
98 if v.category != 'startupview'] |
106 |
99 |
107 def stereotype(self, name): |
100 def stereotype(self, name): |
108 return Span((' <<%s>>' % name,), klass='stereotype') |
101 return Span((' <<%s>>' % name,), klass='stereotype') |
109 |
102 |
110 def visit_entityschema(self, eschema, skiprels=()): |
103 def visit_entityschema(self, eschema, skiptypes=()): |
111 """get a layout for an entity schema""" |
104 """get a layout for an entity schema""" |
112 etype = eschema.type |
105 etype = eschema.type |
113 layout = Section(children=' ', klass='clear') |
106 layout = Section(children=' ', klass='clear') |
114 layout.append(Link(etype,' ' , id=etype)) # anchor |
107 layout.append(Link(etype,' ' , id=etype)) # anchor |
115 title = Link(self.eschema_link_url(eschema), etype) |
108 title = Link(self.eschema_link_url(eschema), etype) |
116 if eschema.meta: |
109 boxchild = [Section(children=(title, ' (%s)'% eschema.display_name(self.req)), klass='title')] |
117 stereotype = self.stereotype('meta') |
|
118 boxchild = [Section(children=(title, ' (%s)'%eschema.display_name(self.req), stereotype), klass='title')] |
|
119 else: |
|
120 boxchild = [Section(children=(title, ' (%s)'%eschema.display_name(self.req)), klass='title')] |
|
121 table = Table(cols=4, rheaders=1, |
110 table = Table(cols=4, rheaders=1, |
122 children=self._entity_attributes_data(eschema)) |
111 children=self._entity_attributes_data(eschema)) |
123 boxchild.append(Section(children=(table,), klass='body')) |
112 boxchild.append(Section(children=(table,), klass='body')) |
124 data = [] |
113 data = [] |
125 data.append(Section(children=boxchild, klass='box')) |
114 data.append(Section(children=boxchild, klass='box')) |
127 data.append(Section(children='', klass='hl')) |
116 data.append(Section(children='', klass='hl')) |
128 t_vars = [] |
117 t_vars = [] |
129 rels = [] |
118 rels = [] |
130 first = True |
119 first = True |
131 for rschema, targetschemas, x in eschema.relation_definitions(): |
120 for rschema, targetschemas, x in eschema.relation_definitions(): |
132 if rschema.type in skiprels: |
121 if rschema.type in skiptypes: |
133 continue |
122 continue |
134 if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): |
123 if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): |
135 continue |
124 continue |
136 rschemaurl = self.rschema_link_url(rschema) |
125 rschemaurl = self.rschema_link_url(rschema) |
137 for oeschema in targetschemas: |
126 for oeschema in targetschemas: |