web/views/uicfg.py
changeset 9341 099a3a33eaaa
parent 8696 0bb18407c053
child 9892 928732ec00dd
child 9976 457efde98629
equal deleted inserted replaced
9340:b1e933b0e850 9341:099a3a33eaaa
   111             sschema = '*'
   111             sschema = '*'
   112         self.counter += 1
   112         self.counter += 1
   113         self.setdefault((sschema, rschema, oschema, role),
   113         self.setdefault((sschema, rschema, oschema, role),
   114                         'order',
   114                         'order',
   115                         self.counter)
   115                         self.counter)
       
   116 
       
   117     def set_fields_order(self, etype, relations):
       
   118         """specify the field order in `etype` primary view.
       
   119 
       
   120         :param etype: the entity type as a string
       
   121         :param attrs: the ordered list of attribute names (or relations)
       
   122 
       
   123         `attrs` can be strings or 2-tuples (relname, role_of_etype_in_the_rel)
       
   124 
       
   125         Unspecified fields will be displayed after specified ones, their
       
   126         order being consistent with the schema definition.
       
   127 
       
   128         Examples:
       
   129 
       
   130         .. sourcecode:: python
       
   131 
       
   132           from cubicweb.web.views.uicfg import primaryview_display_ctrl as pvdc
       
   133           pvdc.set_fields_order('CWUser', ('firstname', ('in_group', 'subject'),
       
   134                                            'surname', 'login'))
       
   135 
       
   136         """
       
   137         for index, relation in enumerate(relations):
       
   138             if not isinstance(relation, tuple):
       
   139                 relation = (relation, 'subject')
       
   140             rtype, role = relation
       
   141             if role == 'subject':
       
   142                 self.tag_subject_of((etype, rtype, '*'), {'order': index})
       
   143             else:
       
   144                 self.tag_object_of((etype, rtype, '*'), {'order': index})
       
   145 
   116 
   146 
   117 primaryview_display_ctrl = DisplayCtrlRelationTags()
   147 primaryview_display_ctrl = DisplayCtrlRelationTags()
   118 
   148 
   119 
   149 
   120 # index view configuration ####################################################
   150 # index view configuration ####################################################