cubicweb/web/schemaviewer.py
changeset 12639 619210ba8b5e
parent 12638 8466a6dd474e
child 12640 de1c0721656e
equal deleted inserted replaced
12638:8466a6dd474e 12639:619210ba8b5e
   119             constraints = rschema.rproperty(eschema.type, aschema.type,
   119             constraints = rschema.rproperty(eschema.type, aschema.type,
   120                                             'constraints')
   120                                             'constraints')
   121             data.append(', '.join(str(constr) for constr in constraints))
   121             data.append(', '.join(str(constr) for constr in constraints))
   122         return data
   122         return data
   123 
   123 
   124 
       
   125     def stereotype(self, name):
   124     def stereotype(self, name):
   126         return Span((' <<%s>>' % name,), klass='stereotype')
   125         return Span((' <<%s>>' % name,), klass='stereotype')
   127 
   126 
   128     def visit_entityschema(self, eschema, skiptypes=()):
   127     def visit_entityschema(self, eschema, skiptypes=()):
   129         """get a layout for an entity schema"""
   128         """get a layout for an entity schema"""
   130         etype = eschema.type
   129         etype = eschema.type
   131         layout = Section(children=' ', klass='clear')
   130         layout = Section(children=' ', klass='clear')
   132         layout.append(Link(etype,'&#160;' , id=etype)) # anchor
   131         layout.append(Link(etype, '&#160;', id=etype))  # anchor
   133         title = self.format_eschema(eschema)
   132         title = self.format_eschema(eschema)
   134         boxchild = [Section(children=(title,), klass='title')]
   133         boxchild = [Section(children=(title,), klass='title')]
   135         data = []
   134         data = []
   136         data.append(Section(children=boxchild, klass='box'))
   135         data.append(Section(children=boxchild, klass='box'))
   137         data.append(Section(children='', klass='vl'))
   136         data.append(Section(children='', klass='vl'))
   194         schema = rschema.schema
   193         schema = rschema.schema
   195         rschema_objects = rschema.objects()
   194         rschema_objects = rschema.objects()
   196         if rschema_objects:
   195         if rschema_objects:
   197             # might be empty
   196             # might be empty
   198             properties = [p for p in RelationDefinitionSchema.rproperty_defs(rschema_objects[0])
   197             properties = [p for p in RelationDefinitionSchema.rproperty_defs(rschema_objects[0])
   199                           if not p in ('cardinality', 'composite', 'eid')]
   198                           if p not in ('cardinality', 'composite', 'eid')]
   200         else:
   199         else:
   201             properties = []
   200             properties = []
   202         data += [_(prop) for prop in properties]
   201         data += [_(prop) for prop in properties]
   203         cols = len(data)
   202         cols = len(data)
   204         done = set()
   203         done = set()
   219                     elif prop == 'constraints':
   218                     elif prop == 'constraints':
   220                         val = ', '.join([c.expression 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.items():
   221                         for key, value in val.items():
   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)
   226 
   225 
   227                     elif isinstance(val, (list, tuple)):
   226                     elif isinstance(val, (list, tuple)):
   228                         val = sorted(val)
   227                         val = sorted(val)
   229                         val = ', '.join(str(v) for v in val)
   228                         val = ', '.join(str(v) for v in val)