cubicweb/web/views/uicfg.py
branch3.25
changeset 12213 1d7e4f98f902
parent 12210 3fa6c9ef2f51
child 12313 aa15dd521d04
equal deleted inserted replaced
12212:f2e6fb5ddf68 12213:1d7e4f98f902
    52    # Adds all subjects of the entry_of relation in the add menu of the ``Blog``
    52    # Adds all subjects of the entry_of relation in the add menu of the ``Blog``
    53    # primary view
    53    # primary view
    54    uicfg.actionbox_appearsin_addmenu.tag_object_of(('*', 'entry_of', 'Blog'), True)
    54    uicfg.actionbox_appearsin_addmenu.tag_object_of(('*', 'entry_of', 'Blog'), True)
    55 """
    55 """
    56 
    56 
       
    57 from itertools import repeat
       
    58 
    57 from six import string_types
    59 from six import string_types
    58 
    60 
    59 from cubicweb import neg_role
    61 from cubicweb import neg_role
    60 from cubicweb.rtags import (RelationTags, RelationTagsBool, RelationTagsSet,
    62 from cubicweb.rtags import (RelationTags, RelationTagsBool, RelationTagsSet,
    61                             RelationTagsDict, NoTargetRelationTagsDict,
    63                             RelationTagsDict, NoTargetRelationTagsDict,
    62                             _ensure_str_key)
    64                             rtags_chain, _ensure_str_key)
    63 from cubicweb.schema import META_RTYPES, INTERNAL_TYPES, WORKFLOW_TYPES
    65 from cubicweb.schema import META_RTYPES, INTERNAL_TYPES, WORKFLOW_TYPES
    64 
    66 
    65 
    67 
    66 # primary view configuration ##################################################
    68 # primary view configuration ##################################################
    67 
    69 
   201         composed = not rschema.final and rdef.composite == 'subject'
   203         composed = not rschema.final and rdef.composite == 'subject'
   202     return card, composed
   204     return card, composed
   203 
   205 
   204 
   206 
   205 class AutoformSectionRelationTags(RelationTagsSet):
   207 class AutoformSectionRelationTags(RelationTagsSet):
   206     """autoform relations'section"""
   208     """autoform relations'section
       
   209 
       
   210     Notice that unlike other rtags where wildcard handling is done when
       
   211     retrieving some value, all values are expanded here during initialization
       
   212     step.
       
   213 
       
   214     For derived rtags, values specified for the 'main' form type are propagated
       
   215     to the 'inlined' form type if unspecified. Others are fetched back from the
       
   216     parent.
       
   217     """
   207     __regid__ = 'autoform_section'
   218     __regid__ = 'autoform_section'
   208 
   219 
   209     _allowed_form_types = ('main', 'inlined', 'muledit')
   220     _allowed_form_types = ('main', 'inlined', 'muledit')
   210     _allowed_values = {'main': ('attributes', 'inlined', 'relations',
   221     _allowed_values = {'main': ('attributes', 'inlined', 'relations',
   211                                 'metadata', 'hidden'),
   222                                 'metadata', 'hidden'),
   213                        'muledit': ('attributes', 'hidden'),
   224                        'muledit': ('attributes', 'hidden'),
   214                        }
   225                        }
   215 
   226 
   216     def init(self, schema, check=True):
   227     def init(self, schema, check=True):
   217         super(AutoformSectionRelationTags, self).init(schema, check)
   228         super(AutoformSectionRelationTags, self).init(schema, check)
   218         self.apply(schema, self._initfunc_step2)
   229         if self._parent is None:
       
   230             self.apply(schema, self._initfunc_step2)
       
   231         else:
       
   232             # we still need to expand wildcard in defined keys
       
   233             for key in list(self._tagdefs):
       
   234                 stype, rtype, otype, role = key
       
   235                 rschema = schema.rschema(rtype)
       
   236                 if stype == '*' and stype == '*':
       
   237                     concrete_rdefs = rschema.rdefs.keys()
       
   238                 elif stype == '*':
       
   239                     concrete_rdefs = zip(rschema.subjects(otype), repeat(otype))
       
   240                 elif otype == '*':
       
   241                     concrete_rdefs = zip(repeat(stype), rschema.objects(stype))
       
   242                 else:
       
   243                     concrete_rdefs = [(stype, otype)]
       
   244                 for sschema, oschema in concrete_rdefs:
       
   245                     self._init(sschema, rschema, oschema, role)
       
   246                     # also, we have to copy values from 'main' to 'inlined' and
       
   247                     # for other undefined sections from the parent's rtag
       
   248                     formsections = self.get(sschema, rschema, oschema, role)
       
   249                     sectdict = _formsections_as_dict(formsections)
       
   250                     parent_formsections = self._parent.get(sschema, rschema, oschema, role)
       
   251                     parent_sectdict = _formsections_as_dict(parent_formsections)
       
   252                     for formtype, section in parent_sectdict.items():
       
   253                         if formtype not in sectdict:
       
   254                             if formtype == 'inlined':
       
   255                                 section = sectdict.get('main', section)
       
   256                             formsections.add('%s_%s' % (formtype, section))
   219 
   257 
   220     def _init(self, sschema, rschema, oschema, role):
   258     def _init(self, sschema, rschema, oschema, role):
   221         formsections = self.init_get(sschema, rschema, oschema, role)
   259         formsections = self.init_get(sschema, rschema, oschema, role)
   222         if formsections is None:
   260         if formsections is None:
   223             formsections = self.tag_container_cls()
   261             formsections = self.tag_container_cls()
   298                     for section, value in rtags.items())
   336                     for section, value in rtags.items())
   299         return rtags
   337         return rtags
   300 
   338 
   301     def get(self, *key):
   339     def get(self, *key):
   302         # overriden to avoid recomputing done in parent classes
   340         # overriden to avoid recomputing done in parent classes
   303         return self._tagdefs.get(key, ())
   341         for rtag in rtags_chain(self):
       
   342             try:
       
   343                 return rtag._tagdefs[key]
       
   344             except KeyError:
       
   345                 continue
       
   346         return ()
   304 
   347 
   305     def relations_by_section(self, entity, formtype, section, permission,
   348     def relations_by_section(self, entity, formtype, section, permission,
   306                              strict=False):
   349                              strict=False):
   307         """return a list of (relation schema, target schemas, role) for the
   350         """return a list of (relation schema, target schemas, role) for the
   308         given entity matching categories and permission.
   351         given entity matching categories and permission.