Configuring the user interface#
The uicfg module#
Note
The part of uicfg that deals with primary views is in the Primary view configuration chapter.
This module (cubicweb_web.views.uicfg) regroups a set of structures that may be
used to configure various options of the generated web interface.
To configure the interface generation, we use RelationTag objects.
Index view configuration#
- indexview_etype_section
entity type category in the index/manage page. May be one of:
applicationsystemschemasubobject(not displayed by default)
By default only entities on the
applicationcategory are shown.
from cubicweb_web.views import uicfg
# force hiding
uicfg.indexview_etype_section['HideMe'] = 'subobject'
# force display
uicfg.indexview_etype_section['ShowMe'] = 'application'
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.
# Adds all subjects of the entry_of relation in the add menu of the ``Blog``
# primary view
uicfg.actionbox_appearsin_addmenu.tag_object_of(('*', 'entry_of', 'Blog'), True)
The uihelper module#
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:
- cubicweb_web.uihelper.set_fields_order(etype, attrs) Callable#
- cubicweb_web.uihelper.hide_field(etype, attr, desttype='*', formtype='main') Callable#
- cubicweb_web.uihelper.hide_fields(etype, attrs, formtype='main') Callable#
- cubicweb_web.uihelper.set_field_kwargs(etype, attr, **kwargs) Callable#
- cubicweb_web.uihelper.set_field(etype, attr, field) Callable#
- cubicweb_web.uihelper.edit_inline(etype, attr, desttype='*', formtype=('main', 'inlined')) Callable#
- cubicweb_web.uihelper.edit_as_attr(etype, attr, desttype='*', formtype=('main', 'muledit')) Callable#
- cubicweb_web.uihelper.set_muledit_editable(etype, attrs) Callable#
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.
- class cubicweb_web.uihelper.FormConfig[source]#
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
etypewhich entity type the form config is for. This attribute is mandatory
formtypethe formtype the class tries toc customize (i.e. main, inlined, or muledit), default is main.
hiddenthe list of attributes or relations to hide.
rels_as_attrsthe list of attributes to edit in the attributes section.
inlinedthe list of attributes to edit in the inlined section.
fields_orderthe 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.
widgetsa dictionary mapping attribute names to widget instances.
fieldsa dictionary mapping attribute names to field instances.
uicfg_afsan instance of
cubicweb_web.uicfg.AutoformSectionRelationTagsDefault is None, meaningcubicweb_web.uicfg.autoform_sectionis used.uicfg_affan instance of
cubicweb_web.uicfg.AutoformFieldTagsDefault is None, meaningcubicweb_web.uicfg.autoform_fieldis used.uicfg_affkan instance of
cubicweb_web.uicfg.AutoformFieldKwargsTagsDefault is None, meaningcubicweb_web.uicfg.autoform_field_kwargsis 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',)