equal
deleted
inserted
replaced
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """an helper class to display CubicWeb schema using ureports |
18 """an helper class to display CubicWeb schema using ureports""" |
19 |
19 |
20 """ |
|
21 __docformat__ = "restructuredtext en" |
20 __docformat__ = "restructuredtext en" |
22 _ = unicode |
21 _ = unicode |
23 |
22 |
24 from logilab.common.ureports import Section, Title, Table, Link, Span, Text |
23 from logilab.common.ureports import Section, Title, Table, Link, Span, Text |
25 |
24 |
150 rdef = rschema.role_rdef(eschema, oeschema, role) |
149 rdef = rschema.role_rdef(eschema, oeschema, role) |
151 if not self.may_read(rdef): |
150 if not self.may_read(rdef): |
152 continue |
151 continue |
153 label = rschema.type |
152 label = rschema.type |
154 if role == 'subject': |
153 if role == 'subject': |
155 cards = rschema.rproperty(eschema, oeschema, 'cardinality') |
154 cards = rschema.rdef(eschema, oeschema).cardinality |
156 else: |
155 else: |
157 cards = rschema.rproperty(oeschema, eschema, 'cardinality') |
156 cards = rschema.rdef(oeschema, eschema).cardinality |
158 cards = cards[::-1] |
157 cards = cards[::-1] |
159 label = '%s %s %s' % (CARD_MAP[cards[1]], label, |
158 label = '%s %s %s' % (CARD_MAP[cards[1]], label, |
160 CARD_MAP[cards[0]]) |
159 CARD_MAP[cards[0]]) |
161 rlink = self.format_rschema(rschema, label) |
160 rlink = self.format_rschema(rschema, label) |
162 elink = self.format_eschema(oeschema) |
161 elink = self.format_eschema(oeschema) |
215 for prop in properties: |
214 for prop in properties: |
216 val = getattr(rdef, prop) |
215 val = getattr(rdef, prop) |
217 if val is None: |
216 if val is None: |
218 val = '' |
217 val = '' |
219 elif prop == 'constraints': |
218 elif prop == 'constraints': |
220 val = ', '.join([c.restriction for c in val]) |
219 val = ', '.join([c.expression for c in val]) |
221 elif isinstance(val, dict): |
220 elif isinstance(val, dict): |
222 for key, value in val.iteritems(): |
221 for key, value in val.iteritems(): |
223 if isinstance(value, (list, tuple)): |
222 if isinstance(value, (list, tuple)): |
224 val[key] = ', '.join(sorted( str(v) for v in value)) |
223 val[key] = ', '.join(sorted( str(v) for v in value)) |
225 val = str(val) |
224 val = str(val) |