web/uicfg.py
branchstable
changeset 2369 5a2b8ed266ca
parent 2191 1f0fde12e35b
child 2381 caad2367d940
equal deleted inserted replaced
2368:b41aef0e63a7 2369:5a2b8ed266ca
    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 
   237 
   234 
   238 # relations'field class
   235 # relations'field class
   239 autoform_field = RelationTags('autoform_field')
   236 autoform_field = RelationTags('autoform_field')
   240 
   237 
   241 # relations'field explicit kwargs (given to field's __init__)
   238 # relations'field explicit kwargs (given to field's __init__)
   242 autoform_field_kwargs = RelationTags()
   239 autoform_field_kwargs = RelationTagsDict()
   243 autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'),
   240 autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'),
   244                                     {'widget': formwidgets.TextInput})
   241                                     {'widget': formwidgets.TextInput})
   245 autoform_field_kwargs.tag_attribute(('Bookmark', 'path'),
   242 autoform_field_kwargs.tag_attribute(('Bookmark', 'path'),
   246                                     {'widget': formwidgets.TextInput})
   243                                     {'widget': formwidgets.TextInput})
   247 
   244