A reference browser widget (Maintainer Mathias Leimgruber)


Keywords
webcloud7, widget, reference, browser
License
GPL-2.0
Install
pip install ftw.referencewidget==2.1.0

Documentation

ftw.referencewidget

This Widget provides a Referencebrowser and a searchfield, which allows users to select references.

The basequery is all types which are not in the types_not_searched property all modification to the allowed types are relative to this query.

Traversal or Selectability can be changed for all widgets with the IReferenceSettings registry interface or per widget with the widget parameters.

The widget takes the following parameters:
  • allow_traversal: List of Types which are added as traversable. Will act as complete configuration if override is set to True.
  • block_traversal: List of Types which are added as not traversable. Will be ignored if override is set to True.
  • selectable: List of Types which are added to the as selectable. Will act as complete configuration if override is set to True
  • nonselectable: List of Types which are added as not selectable. Will be ignored if override is set to True.
  • start: The path first opened. Can either be a callable or a path. Additionaly the strings "parent", "navroot", "ploneroot" can be used.
  • allow_nonsearched_types: If this is set to true all the types will be traversable and selectable.
  • override: Drops all global config and the base query if a list is passed to the widget. If this is set to true, selectable & allow_traversal are not additive but act as the complete configuration instead. nonselectable & block_traversal will be ignored.
  • traversal_query: Updates the query used vor traversing by the given dict. The dict passed will be updated after everything is allready done. So make sure not to override sort_on/sort_order attributes.

Usage

  • Add ftw.referencewidget to your buildout configuration or as dependency to your package:
[instance]
eggs +=
    ftw.referencewidget
  • Install the default generic import profile.

Installation / Development

Option 1 - Using buildout

$ ./bootstrap.sh development.cfg
$ ./bin/instance fg

Option 2 - Using Makefile

$ make install
$ make run

We support both option since the makefile approach does not support yet all the features from the zope2instance recipe. For example control scripts are not yet supported But it's faster and more convenient to setup a docker test image

Javascript development

From version 4 the widget is based upon boorstrap 5.2 and Vuejs 3. It's not yet a pattern, but it might be possible to wrap it in a pattern.

$ npm install

Develop JS

$ npm run dev

Build for production:

$ npm run build

Javascript public API:

You can run "window.initReferenceWidget" in your code. It will scan for all referencebrowser widgets an if not yet initialized it will initialized the JS widget.

Upgrading from 1.x to 2.x

There was no version number set for the ftw.referencewidget package. As a result of this upgradesteps wont be shown in ../@@manage-upgrades from ftw.upgrade. So the first upgradesetp Upgrade ftw.referencewidget:default to 20181112105705: Fix registry field frontend edit must be installed via the ZMI under ../portal_setup/manage_fullImport. This sets the version for the package and so further upgrades can be installed via ../@@manage-upgrades.

Version 4.x

Version 4.x of ftw.referencewidget is only compatible with Plone 6 and Python 3.9 (maybe 3.7 and 3.8 as well). It uses the module federation feature and boostrap 5 from Plone 6.

ContextSourceBinder

With a RelationeChoice or RelationList of RelationChoice a source can be configured along with the field. The ContextSourceBinder makes sure that only valid content can be selected.

By default, the source binder only checks for a valid portal_type when selecting content.

The default_filter implementation therefore looks like this:

def default_filter(source, value):
    """"
    Return ``True`` when the object is selectable, ``False``
    when it is not selectable.

    """"
    return value.portal_type in get_selectable_types_by_source(source)

Feel free to add your own filter method as source parameter in your field. Example:

from ftw.referencewidget.filter import DefaultSelectable

class CustomClass(DefaultSelectable):
    def is_selectable(self):
        return bool(..)
...

directives.widget(realtionchoice_restricted_title=ReferenceWidgetFactory)
realtionchoice_restricted_title = RelationChoice(
    title=_(u'Related Choice Restricted Title'),
    source=ReferenceObjSourceBinder(
        selectable_class=CustomClass),
    default=None,
    required=False,
)

The filter takes two parameter the actual source object and a value, which is the content object.

Only ReferenceObjSourceBinder are supported. The SourceBinder takes the following parameters:

  • selectable: Adds these types as selectable. Will act as complete configuration if override is set to True
  • nonselectable: Adds these Types are not selectable. Will be ignored if override is set to True.
  • allow_nonsearched_types: If this is set to true all the types will be traversable and selectable.
  • override: Drops all global config and the base query if a list is passed to the widget. If this is set to true, selectable is not additive but acts as the complete configuration instead. nonselectable will be ignored.
  • selectable_class: Custom ISelectable Class to determine if a content is selectable or not.

The parameters are same as for the widget (Backwards compatibility with 1.x releases).

Fields combinations (Registered converter)

The following combinations are supported:

  • RelationList with value_type Relation --> Stores a List of RelationValues
  • RelationList with value_type RelationChoice --> Stores a List of RelationValues
  • Relation --> Stores a RelationValue
  • List of RelationChoice --> Stores a list of absolute paths, without the portal root part
  • TextLine --> Stores a absolute path as string, without the portal root part

TinyMCE Plone 5 - Internal Link widget replacement

With the version 3 of ftw.referencewidget within Plone 5.x the select2 internal link widget automatically gets replaced by the ftw.referencewidget interna link browser. Featering search and browsing within the referencebrowser popup.

Links

Copyright

This package is copyright by 4teamwork.

ftw.referencewidget is licensed under GNU General Public License, version 2.