A RelationTag object is an object which allows to link a configuration information to a relation definition. For instance, the standard primary view uses a RelationTag object (uicfg.primaryview_section) to get the section to display relations.
# display ``entry_of`` relations in the ``relations`` section in the ``BlogEntry`` primary view
uicfg.primaryview_section.tag_subject_of(('BlogEntry', 'entry_of', '*'),
'relations')
# hide every relation ``entry_of`` in the ``Blog`` primary view
uicfg.primaryview_section.tag_object_of(('*', 'entry_of', 'Blog'), 'hidden')
Note
The part of uicfg that deals with primary views is in the Primary view configuration chapter.
This module has been moved to web.views.uicfg.
This module provide highlevel helpers to avoid uicfg boilerplate for most common tasks such as fields ordering, widget customization, etc.
Here are a few helpers to customize action box rendering:
and a few other ones for form configuration:
The module also provides a FormConfig base class that lets you gather uicfg declaration in the scope of a single class, which can sometimes be clearer to read than a bunch of sequential function calls.
helper base class to define uicfg rules on a given entity type.
In all descriptions below, attributes list can either be a list of attribute names of a list of 2-tuples (relation name, role of the edited entity in the relation).
Attributes
- etype
- which entity type the form config is for. This attribute is mandatory
- formtype
- the formtype the class tries toc customize (i.e. main, inlined, or muledit), default is main.
- hidden
- the list of attributes or relations to hide.
- rels_as_attrs
- the list of attributes to edit in the attributes section.
- inlined
- the list of attributes to edit in the inlined section.
- fields_order
- the list of attributes to edit, in the desired order. Unspecified fields will be displayed after specified ones, their order being consistent with the schema definition.
- widgets
- a dictionary mapping attribute names to widget instances.
- fields
- a dictionary mapping attribute names to field instances.
- uicfg_afs
- an instance of cubicweb.web.uicfg.AutoformSectionRelationTags Default is None, meaning cubicweb.web.uicfg.autoform_section is used.
- uicfg_aff
- an instance of cubicweb.web.uicfg.AutoformFieldTags Default is None, meaning cubicweb.web.uicfg.autoform_field is used.
- uicfg_affk
- an instance of cubicweb.web.uicfg.AutoformFieldKwargsTags Default is None, meaning cubicweb.web.uicfg.autoform_field_kwargs is used.
Examples:
from cubicweb.web import uihelper, formwidgets as fwdgs
class LinkFormConfig(uihelper.FormConfig):
etype = 'Link'
hidden = ('title', 'description', 'embed')
widgets = dict(
url=fwdgs.TextInput(attrs={'size':40}),
)
class UserFormConfig(uihelper.FormConfig):
etype = 'CWUser'
hidden = ('login',)
rels_as_attrs = ('in_group',)
fields_order = ('firstname', 'surname', 'in_group', 'use_email')
inlined = ('use_email',)