Warning
Starting from CubicWeb version 4.0 all code related to generating html views has been moved to the Cube cubicweb_web.
If you want to migrate a project from 3.38 to 4.* while still using all the
html views you need to both install the cubicweb_web cube AND add it to
your dependencies and run add_cube('web')
.
cubicweb_web can be installed from pypi this way:
pip install cubicweb_web
We donât plan to maintain the features in cubicweb_web in the long run; we are moving to a full javascript frontend using both cubicweb_api (which exposes a HTTP API) and @cubicweb/client as a frontend javascript toolkit.
In the long run cubicweb_api will be merged inside of CubicWeb.
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:
application
system
schema
subobject
(not displayed by default)
By default only entities on the
application
category 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
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, meaningcubicweb_web.uicfg.autoform_section
is used.uicfg_aff
an instance of
cubicweb_web.uicfg.AutoformFieldTags
Default is None, meaningcubicweb_web.uicfg.autoform_field
is used.uicfg_affk
an instance of
cubicweb_web.uicfg.AutoformFieldKwargsTags
Default is None, meaningcubicweb_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',)