跳转到主要内容

提供一种通用且易用的关系小部件

项目描述

摘要

此立方体提供了一个通用但易用的小部件,可以将编辑的实体链接到多个其他实体,以执行特定的关系。它提供

  • 一个可复选(取消复选)的关联实体列表

  • 触发显示弹出窗口的机制,以显示关系的每个可能的目标实体类型

  • 在弹出窗口中,最终用户可以

    • 搜索(使用属性)要链接到编辑的实体

    • 显示(在分页表中)并选择它们(使用每行表上的复选框)

    • 创建一个要链接的新实体(可以禁用)

使用方法

为您的关系选择关系小部件

您可以使用以下两种机制之一来配置用户界面

  • 要么 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,
          )
  • 或者直接通过 uicfg.autoform_field_kwarg

    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

    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)

还有一个可用的 dialog_options 字典,可用于配置bootstrap模态窗口(请参阅https://bootstrap.ac.cn/javascript/#modals-options

uicfg.autoform_field_kwargs.tag_subject_of(
('MyEntity', 'my_relation', '*'),
{'widget': RelationFacetWidget(dialog_options={'keyboard': False})})

项目详情


下载文件

下载您平台对应的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

cubicweb-relationwidget-0.10.0.tar.gz (20.5 kB 查看哈希值)

上传时间 源代码

构建分布

cubicweb_relationwidget-0.10.0-py3-none-any.whl (19.5 kB 查看哈希值)

上传时间 Python 3

由以下组织支持