Skip to main content

Provide a generic and ergonomic relation widget

Project description

Summary

This cube provides a generic but ergonomic widget to link an edited entity to several others for a given relation. It provides:

  • a list of checkbox-(de-)selectable related entities

  • a mecanism to trigger the display of a pop-up window for each possible target entity type of the relation

  • in the pop-up window, the end-user can:

    • search (using facets) entities to be linked to the edited entity,

    • display (in a paginated table) and select them (using a checkbox on each table line)

    • create a new entity to be linked (can be desactivated)

Usage

Select the relation widget for your relation

You can use the two following mecanisms to configure the user interface:

  • either 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,
          )
  • or directly via 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})

Configure it (optional)

If you want to desactivate the ability to create a new entity to be linked to the edited one, you can do it:

  • for a single relation using uicfg again:

    uicfg.autoform_field_kwargs.tag_subject_of(
    ('MyEntity', 'my_relation', '*'),
    {'widget': RelationFacetWidget(no_creation_form=True)})
  • application-wide by overriding SearchForRelatedEntitiesView.has_creation_form to always return 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)

There is also a dialog_options dictionary that can be used to configure the bootstrap modal window (see http://getbootstrap.com/javascript/#modals-options):

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cubicweb-relationwidget-0.10.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

cubicweb_relationwidget-0.10.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file cubicweb-relationwidget-0.10.0.tar.gz.

File metadata

File hashes

Hashes for cubicweb-relationwidget-0.10.0.tar.gz
Algorithm Hash digest
SHA256 9f30abcc42d1537eb360cbc20956d6a68b69ff82505ce0d033e0fccfd11557a7
MD5 ee26f0a50c08fb287e13391f2318128c
BLAKE2b-256 b0cec0c0476b2670e4f78018253ac87631a67729ab739d4000ef487218d22012

See more details on using hashes here.

File details

Details for the file cubicweb_relationwidget-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cubicweb_relationwidget-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a582903af208459b69355ea29750b3148a6fe62ae34ceeb5775f0363176b9776
MD5 0fcdea0f3407f7eff1984f1a3dc1cb86
BLAKE2b-256 8ede791768ede9a84daba9dd3cefcd3e1cec620b79a1a01966240abae0bcff2e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page