"""This module regroups a set of structures that may be used to configurevarious places of the generated web interface.Primary view configuration``````````````````````````:primaryview_section: where to display a relation in primary view. Value may be one of: * 'attributes', display in the attributes section * 'relations', display in the relations section (below attributes) * 'sideboxes', display in the side boxes (beside attributes) * 'hidden', don't display:primaryview_display_ctrl: how to display a relation in primary view. Values are dict with some of the following keys: :vid: identifier of a view to use to display the result set. Defaults depends on the section: * 'attributes' section: 'reledit' view * 'relations' section: 'autolimited' view * 'sideboxes' section: 'sidebox' view :label: label for the relations section or side box :limit: boolean telling if the results should be limited according to the configuration :filter: callback taking the related result set as argument and returning it filtered :order: int used to control order within a section. When not specified, automatically set according to order in which tags are added. Notice those values are only considered if the relation is in a displayed section (controlled by :attr:`primaryview_section`)Index view configuration````````````````````````:indexview_etype_section: entity type category in the index/manage page. May be one of * 'application' * 'system' * 'schema' * 'subobject' (not displayed by default)Actions box configuration`````````````````````````:actionbox_appearsin_addmenu: simple boolean relation tags used to control the "add entity" submenu. Relations whose rtag is True will appears, other won't.Automatic form configuration````````````````````````````:organization: Logilab:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses"""__docformat__="restructuredtext en"fromcubicwebimportneg_rolefromcubicweb.rtagsimport(RelationTags,RelationTagsBool,RelationTagsSet,RelationTagsDict)fromcubicweb.webimportformwidgetsdefcard_from_role(card,role):ifrole=='subject':returncard[0]assertrolein('object','sobject'),repr(role)returncard[1]# primary view configuration ##################################################definit_primaryview_section(rtag,sschema,rschema,oschema,role):ifrtag.get(sschema,rschema,oschema,role)isNone:card=card_from_role(rschema.rproperty(sschema,oschema,'cardinality'),role)composed=rschema.rproperty(sschema,oschema,'composite')==neg_role(role)ifrschema.is_final():ifrschema.metaorsschema.is_metadata(rschema) \oroschema.typein('Password','Bytes'):section='hidden'else:section='attributes'elifcardin'1+':section='attributes'elifcomposed:section='relations'else:section='sideboxes'rtag.tag_relation((sschema,rschema,oschema,role),section)primaryview_section=RelationTags('primaryview_section',init_primaryview_section,frozenset(('attributes','relations','sideboxes','hidden')))classDisplayCtrlRelationTags(RelationTagsDict):def__init__(self,*args,**kwargs):super(DisplayCtrlRelationTags,self).__init__(*args,**kwargs)self._counter=0deftag_relation(self,key,tag):tag=super(DisplayCtrlRelationTags,self).tag_relation(key,tag)self._counter+=1tag.setdefault('order',self._counter)deftag_subject_of(self,key,tag):subj,rtype,obj=keyifobj!='*':self.warning('using explict target type in display_ctrl.tag_subject_of() ''has no effect, use (%s, %s, "*") instead of (%s, %s, %s)',subj,rtype,subj,rtype,obj)super(DisplayCtrlRelationTags,self).tag_subject_of((subj,rtype,'*'),tag)deftag_object_of(self,key,tag):subj,rtype,obj=keyifsubj!='*':self.warning('using explict subject type in display_ctrl.tag_object_of() ''has no effect, use ("*", %s, %s) instead of (%s, %s, %s)',rtype,obj,subj,rtype,obj)super(DisplayCtrlRelationTags,self).tag_object_of(('*',rtype,obj),tag)definit_primaryview_display_ctrl(rtag,sschema,rschema,oschema,role):ifrole=='subject':oschema='*'label=rschema.typeelse:sschema='*'label='%s_%s'%(rschema,role)rtag.setdefault((sschema,rschema,oschema,role),'label',label)rtag.setdefault((sschema,rschema,oschema,role),'order',rtag._counter)primaryview_display_ctrl=DisplayCtrlRelationTags('primaryview_display_ctrl',init_primaryview_display_ctrl)# index view configuration ##################################################### entity type section in the index/manage page. May be one of# * 'application'# * 'system'# * 'schema'# * 'hidden'# * 'subobject' (not displayed by default)indexview_etype_section={'EmailAddress':'subobject','CWUser':'system','CWGroup':'system','CWPermission':'system','BaseTransition':'hidden',}# autoform.AutomaticEntityForm configuration ################################### relations'section (eg primary/secondary/generic/metadata/generated)definit_autoform_section(rtag,sschema,rschema,oschema,role):ifrtag.get(sschema,rschema,oschema,role)isNone:ifautoform_is_inlined.get(sschema,rschema,oschema,role):section='generated'elifsschema.is_metadata(rschema):section='metadata'else:ifrole=='subject':card=rschema.rproperty(sschema,oschema,'cardinality')[0]composed=rschema.rproperty(sschema,oschema,'composite')=='object'else:card=rschema.rproperty(sschema,oschema,'cardinality')[1]composed=rschema.rproperty(sschema,oschema,'composite')=='subject'ifcardin'1+':ifnotrschema.is_final()andcomposed:# XXX why? probably because we want it unlined, though this# is not the case by defaultsection='generated'else:section='primary'elifrschema.is_final():section='secondary'else:section='generic'rtag.tag_relation((sschema,rschema,oschema,role),section)autoform_section=RelationTags('autoform_section',init_autoform_section,set(('primary','secondary','generic','metadata','generated')))# relations'field classautoform_field=RelationTags('autoform_field')# relations'field explicit kwargs (given to field's __init__)autoform_field_kwargs=RelationTagsDict()# inlined view flag for non final relations: when True for an entry, the# entity(ies) at the other end of the relation will be editable from the# form of the edited entityautoform_is_inlined=RelationTagsBool('autoform_is_inlined')# set of tags of the form <action>_on_new on relations. <action> is a# schema action (add/update/delete/read), and when such a tag is found# permissions checking is by-passed and supposed to be okautoform_permissions_overrides=RelationTagsSet('autoform_permissions_overrides')# boxes.EditBox configuration ################################################## 'link' / 'create' relation tags, used to control the "add entity" submenudefinit_actionbox_appearsin_addmenu(rtag,sschema,rschema,oschema,role):ifrtag.get(sschema,rschema,oschema,role)isNone:card=rschema.rproperty(sschema,oschema,'cardinality')[role=='object']ifnotcardin'?1'and \rschema.rproperty(sschema,oschema,'composite')==role:rtag.tag_relation((sschema,rschema,oschema,role),True)actionbox_appearsin_addmenu=RelationTagsBool('actionbox_appearsin_addmenu',init_actionbox_appearsin_addmenu)