web/uicfg.py
changeset 2381 caad2367d940
parent 2234 1fbcf202882d
parent 2369 5a2b8ed266ca
child 2465 cc18a700a2be
equal deleted inserted replaced
2374:ea1a44e4ad62 2381:caad2367d940
    66 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
    66 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
    67 """
    67 """
    68 __docformat__ = "restructuredtext en"
    68 __docformat__ = "restructuredtext en"
    69 
    69 
    70 from cubicweb import neg_role
    70 from cubicweb import neg_role
    71 from cubicweb.rtags import RelationTags, RelationTagsBool, RelationTagsSet
    71 from cubicweb.rtags import (RelationTags, RelationTagsBool,
       
    72                             RelationTagsSet, RelationTagsDict)
    72 from cubicweb.web import formwidgets
    73 from cubicweb.web import formwidgets
    73 
    74 
    74 
    75 
    75 def card_from_role(card, role):
    76 def card_from_role(card, role):
    76     if role == 'subject':
    77     if role == 'subject':
   116     primaryview_section.tag_attribute(('CWEType', attr), 'hidden')
   117     primaryview_section.tag_attribute(('CWEType', attr), 'hidden')
   117 for attr in ('name', 'meta', 'final', 'symetric', 'inlined'):
   118 for attr in ('name', 'meta', 'final', 'symetric', 'inlined'):
   118     primaryview_section.tag_attribute(('CWRType', attr), 'hidden')
   119     primaryview_section.tag_attribute(('CWRType', attr), 'hidden')
   119 
   120 
   120 
   121 
   121 class DisplayCtrlRelationTags(RelationTags):
   122 class DisplayCtrlRelationTags(RelationTagsDict):
   122     def __init__(self, *args, **kwargs):
   123     def __init__(self, *args, **kwargs):
   123         super(DisplayCtrlRelationTags, self).__init__(*args, **kwargs)
   124         super(DisplayCtrlRelationTags, self).__init__(*args, **kwargs)
   124         self._counter = 0
   125         self._counter = 0
   125 
   126 
   126     def tag_relation(self, key, tag):
   127     def tag_relation(self, key, tag):
   127         assert isinstance(tag, dict)
   128         tag = super(DisplayCtrlRelationTags, self).tag_relation(key, tag)
   128         super(DisplayCtrlRelationTags, self).tag_relation(key, tag)
       
   129         self._counter += 1
   129         self._counter += 1
   130         tag.setdefault('order', self._counter)
   130         tag.setdefault('order', self._counter)
   131 
   131 
   132     def tag_subject_of(self, key, tag):
   132     def tag_subject_of(self, key, tag):
   133         subj, rtype, obj = key
   133         subj, rtype, obj = key
   150         oschema = '*'
   150         oschema = '*'
   151         label = rschema.type
   151         label = rschema.type
   152     else:
   152     else:
   153         sschema = '*'
   153         sschema = '*'
   154         label = '%s_%s' % (rschema, role)
   154         label = '%s_%s' % (rschema, role)
   155     displayinfo = rtag.get(sschema, rschema, oschema, role)
   155     rtag.setdefault((sschema, rschema, oschema, role), 'label', label)
   156     if displayinfo is None:
   156     rtag.setdefault((sschema, rschema, oschema, role), 'order', rtag._counter)
   157         displayinfo = {}
       
   158         rtag.tag_relation((sschema, rschema, oschema, role), displayinfo)
       
   159     displayinfo.setdefault('label', label)
       
   160 
   157 
   161 primaryview_display_ctrl = DisplayCtrlRelationTags('primaryview_display_ctrl',
   158 primaryview_display_ctrl = DisplayCtrlRelationTags('primaryview_display_ctrl',
   162                                                    init_primaryview_display_ctrl)
   159                                                    init_primaryview_display_ctrl)
   163 
   160 
   164 
   161 
   241 
   238 
   242 # relations'field class
   239 # relations'field class
   243 autoform_field = RelationTags('autoform_field')
   240 autoform_field = RelationTags('autoform_field')
   244 
   241 
   245 # relations'field explicit kwargs (given to field's __init__)
   242 # relations'field explicit kwargs (given to field's __init__)
   246 autoform_field_kwargs = RelationTags()
   243 autoform_field_kwargs = RelationTagsDict()
   247 autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'),
   244 autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'),
   248                                     {'widget': formwidgets.TextInput})
   245                                     {'widget': formwidgets.TextInput})
   249 autoform_field_kwargs.tag_attribute(('Bookmark', 'path'),
   246 autoform_field_kwargs.tag_attribute(('Bookmark', 'path'),
   250                                     {'widget': formwidgets.TextInput})
   247                                     {'widget': formwidgets.TextInput})
   251 
   248