提供通用且符合人体工程学的关系小部件
cubicweb-relationwidget的Python项目详细描述
摘要
这个立方体提供了一个通用但符合人体工程学的小部件来链接 一个给定关系的多个其他实体。它提供:
- 复选框列表-(de-)可选择的相关实体
- 每种可能触发弹出窗口显示的机制 关系的目标实体类型
- 在弹出窗口中,最终用户可以:
- 搜索(使用facets)要链接到已编辑实体的实体,
- 显示(在分页表中)并选择它们(使用 每行表格)
- 创建要链接的新实体(可以取消激活)
用法
为您的关系选择“关系”小部件
您可以使用以下两种方法来配置用户界面:
要么cubicweb.web.uihelper.formconfig:
from cubicweb.web import uihelper from cubes.relationwidget.views import RelationFacetWidget class MyEntityConfig(uihelper.FormConfig): etype = 'MyEntity' # Move `my_relation` into the attribute section: rels_as_attrs = ('my_relation', ) # Edit `my_relation` using RelationFacetWidget: widgets = dict( my_relation=RelationFacetWidget, )
或者直接通过
from cubicweb.web.views import uicfg from cubes.relationwidget.views import RelationFacetWidget # edit the relation as attribute. uicfg.autoform_section.tag_subject_of( ('MyEntity', 'my_relation', '*'), formtype=('main', 'muledit'), section='attributes') # add the RelationFacetWidget for `my_relation` uicfg.autoform_field_kwargs.tag_subject_of( ('MyEntity', 'my_relation', '*'), {'widget': RelationFacetWidget})
配置它(可选)
如果要取消激活创建新实体的功能 链接到已编辑的链接,您可以这样做:
对于再次使用uicfg的单个关系:
uicfg.autoform_field_kwargs.tag_subject_of( ('MyEntity', 'my_relation', '*'), {'widget': RelationFacetWidget(no_creation_form=True)})
覆盖应用程序范围内的SearchForRelatedEntitiesView.has_creation_form 始终返回false:
from cubes.relationwidget.view import SearchForRelatedEntitiesView class MySearchForRelatedEntitiesView(SearchForRelatedEntitiesView): @property def has_creation_from(self): return False def registration_callback(vreg): vreg.register_and_register(MySearchForRelatedEntitiesView, SearchForRelatedEntitiesView)
还有一个对话框选项 配置引导模式窗口(请参见 http://getbootstrap.com/javascript/#modals-options):
uicfg.autoform_field_kwargs.tag_subject_of( ('MyEntity', 'my_relation', '*'), {'widget': RelationFacetWidget(dialog_options={'keyboard': False})})