class EditForm(base.EditForm): schema = ICollectionFilterPortlet label = _(u"Edit Collection Filter Portlet") description = _( u"This portlet shows grouped criteria of collection results and " u"allows filtering of collection results.")
class ICollectionFilterResultListSort(ICollectionFilterBaseSchema): """Schema for the result list sorting.""" sort_on = schema.Tuple( title=_("label_sort_on", u"Enabled sort indexes"), description=_("help_sort_on", u"Select the indexes which can be sorted on."), value_type=schema.Choice( title=u"Index", vocabulary="collective.collectionfilter.SortOnIndexes", ), required=True, ) # NB needed as InAndOut breaks tiles in 5.0 widget("sort_on", SelectFieldWidget, pattern_options=dict(orderable=True)) input_type = schema.Choice( title=_("label_input_type", u"Input Type"), description=_( "help_input_type", u"Select how the UI of the collection filter should be rendered. " u"Wether as links, as checkboxes and radiobuttons or checkboxes and dropdowns.", # noqa ), required=True, vocabulary="collective.collectionfilter.InputType", )
class ICollectionFilterResultListSort(ICollectionFilterBaseSchema): """Schema for the result list sorting. """ sort_on = schema.Tuple( title=_('label_sort_on', u'Enabled sort indexes'), description=_('help_sort_on', u'Select the indexes which can be sorted on.'), value_type=schema.Choice( title=u'Index', vocabulary='collective.collectionfilter.SortOnIndexes', ), required=True, ) input_type = schema.Choice( title=_('label_input_type', u'Input Type'), description=_( 'help_input_type', u'Select how the UI of the collection filter should be rendered. ' u'Wether as links, as checkboxes and radiobuttons or checkboxes and dropdowns.' # noqa ), required=True, vocabulary='collective.collectionfilter.InputType', )
def FilterTypeVocabulary(context): items = [ SimpleTerm(title=_('filtertype_single'), value='single'), SimpleTerm(title=_('filtertype_and'), value='and'), SimpleTerm(title=_('filtertype_or'), value='or') ] return SimpleVocabulary(items)
def FilterTypeVocabulary(context): items = [ SimpleTerm(title=_("filtertype_single"), value="single"), SimpleTerm(title=_("filtertype_and"), value="and"), SimpleTerm(title=_("filtertype_or"), value="or"), ] return SimpleVocabulary(items)
def InputTypeVocabulary(context): items = [ SimpleTerm(title=_('inputtype_links'), value='links'), SimpleTerm(title=_('inputtype_checkboxes_radiobuttons'), value='checkboxes_radiobuttons'), # noqa SimpleTerm(title=_('inputtype_checkboxes_dropdowns'), value='checkboxes_dropdowns') # noqa ] return SimpleVocabulary(items)
class AddForm(base.AddForm): schema = ICollectionSearchPortlet label = _(u"Add Collection Search Portlet") description = _( u"This portlet allows fulltext search in collection results.") def create(self, data): return Assignment(**data)
class AddForm(base.AddForm): schema = ICollectionMapsPortlet label = _(u"Add Collection Maps Portlet") description = _( u"This portlet allows map filtering in collection results.") def create(self, data): return Assignment(**data)
class AddForm(base.AddForm): schema = ICollectionFilterSortOnPortlet label = _(u"Add Collection Result Listing Sort Portlet") description = _( u"This portlet shows sorting options for the result listing.") def create(self, data): return Assignment(**data)
class AddForm(base.AddForm): schema = ICollectionFilterPortlet label = _(u"Add Collection Filter Portlet") description = _( u"This portlet shows grouped criteria of collection results and " u"allows filtering of collection results.") def create(self, data): return Assignment(**data)
def InputTypeVocabulary(context): items = [ SimpleTerm(title=_("inputtype_links"), value="links"), SimpleTerm( title=_("inputtype_checkboxes_radiobuttons"), value="checkboxes_radiobuttons", ), SimpleTerm(title=_("inputtype_checkboxes_dropdowns"), value="checkboxes_dropdowns"), ] return SimpleVocabulary(items)
def GroupByCriteriaVocabulary(context): """Collection filter group by criteria.""" groupby = getUtility(IGroupByCriteria).groupby items = [ SimpleTerm(value=it, token=str(it), title=_(it)) for it in groupby.keys() ] return SimpleVocabulary(items)
def SortOnIndexesVocabulary(context): # we reuse p.a.querystring registry reader for sortable_indexes registry = getUtility(IRegistry) reader = getMultiAdapter((registry, getRequest()), IQuerystringRegistryReader) sortable_indexes = reader().get('sortable_indexes') items = [ SimpleTerm(title=_(v['title']), value=k) for k, v in sortable_indexes.items() ] # noqa return SimpleVocabulary(items)
class ICollectionMapsSchema(ICollectionFilterBaseSchema): """schema for maps filtering""" narrow_down = schema.Bool( title=_(u"label_narrow_down_results", default=u"Narrow down result"), description=_( u"help_narrow_down_results", default=u"Narrow down the result after zooming/moving the map.", ), default=False, required=False, ) default_map_layer = schema.Choice( title=_(u"default_map_layer", u"Default map layer"), description=_( u"help_default_map_layer", default=u"Set the default map layer" ), required=False, defaultFactory=map_layer_default, vocabulary="plone.formwidget.geolocation.vocabularies.map_layers", ) map_layers = schema.List( title=_(u"label_map_layers", u"Map Layers"), description=_(u"help_map_layers", default=u"Set the available map layers"), required=False, defaultFactory=map_layers_default, missing_value=[], value_type=schema.Choice( vocabulary="plone.formwidget.geolocation.vocabularies.map_layers" ), ) # noqa: E501
class ICollectionMapsSchema(ICollectionFilterBaseSchema): """ schema for maps filtering """ narrow_down = schema.Bool( title=_(u'label_narrow_down_results', default=u'Narrow down result'), description=_( u'help_narrow_down_results', default=u'Narrow down the result after zooming/moving the map.' ), default=False, required=False) default_map_layer = schema.Choice( title=_(u'default_map_layer', u'Default map layer'), description=_(u'help_default_map_layer', default=u'Set the default map layer'), required=False, defaultFactory=map_layer_default, vocabulary='plone.formwidget.geolocation.vocabularies.map_layers') map_layers = schema.List( title=_(u'label_map_layers', u'Map Layers'), description=_(u'help_map_layers', default=u'Set the available map layers'), required=False, defaultFactory=map_layers_default, missing_value=[], value_type=schema.Choice( vocabulary='plone.formwidget.geolocation.vocabularies.map_layers' )) # noqa: E501
def validateFilterTileModify(tile, event): # TODO: is ok in the acquisiton path? target = tile.collection if target is not None: target = queryAdapter(target.getObject(), ICollectionish) if target is None or target.content_selector is None: api.portal.show_message( _( u"You will need to add a Content Listing tile or target a collection to make Filters work" ), request=tile.context.REQUEST, type=u"warning", ) return False return True
class ICollectionFilterBaseSchema(Interface): header = schema.TextLine( title=_("label_header", default=u"Filter title"), description=_("help_header", u"Title of the rendered filter."), required=False, ) target_collection = schema.Choice( title=_(u"label_target_collection", default=u"Alternative Target Collection"), description=_( u"help_target_collection", default=u"We use the current context as collection. As an alternative you can select a different " u"collection as source for the filter items " u"and where the filter is applied.", ), required=False, vocabulary="plone.app.vocabularies.Catalog", ) widget( "target_collection", RelatedItemsFieldWidget, pattern_options=pattern_options() ) view_name = schema.TextLine( title=_("label_view_name", default=u"Result listing view name"), description=_( "help_view_name", default=u"Optional view name, if the result listing should be" u" rendered with a special view. Can be used to direct the request" u" to a tile.", ), required=False, default=None, ) content_selector = schema.TextLine( title=_("label_content_selector", default=u"Content Selector"), description=_( "help_content_selector", default=u"If your tile or collection has a special class or id for ajax replacement use it here." u" Selector will need to work for unthemed view and current page.", ), required=False, )
class ICollectionFilterBaseSchema(Interface): header = schema.TextLine( title=_('label_header', default=u'Filter title'), description=_('help_header', u'Title of the rendered filter.'), required=False, ) target_collection = schema.Choice( title=_(u'label_target_collection', default=u'Target Collection'), description=_( u'help_target_collection', default=u'The collection, which is the source for the filter ' u'items and where the filter is applied.'), required=True, vocabulary='plone.app.vocabularies.Catalog', defaultFactory=utils.target_collection_default, ) widget('target_collection', RelatedItemsFieldWidget, pattern_options=pattern_options()) view_name = schema.TextLine( title=_('label_view_name', default=u'Result listing view name'), description=_( 'help_view_name', default=u'Optional view name, if the result listing should be' u' rendered with a special view. Can be used to direct the request' u' to a tile.'), required=False, default=None) content_selector = schema.TextLine( title=_('label_content_selector', default=u'Content Selector'), description=_( 'help_content_selector', default=u'Selector which is used to choose a DOM node from the' u' source into the target. For source and target the same' u' selectors are used.'), required=True, default=u'#content-core', )
def validate(self, value): super(TargetCollectionValidator, self).validate(value) portlet = False if value: obj = aq_inner(uuidToCatalogBrain(value)).getObject() else: for obj in aq_chain(self.context): if IPortletAssignmentMapping.providedBy(obj): portlet = True if IDexterityContent.providedBy(obj): break collection = queryAdapter(obj, ICollectionish) # if it's a tile we will use a warning instead since we can't tell if a listing tile # has been added to the layout yet as it's not saved. if portlet and (collection is None or collection.content_selector is None): raise Invalid( _(u"Context is not a collection or has a contentlisting tile, please set a target." )) return True
class EditForm(base.EditForm): schema = ICollectionMapsPortlet label = _(u"Edit Collection Maps Portlet") description = _( u"This portlet allows map filtering in collection results.")
def title(self): if self.header: return self.header else: return _(u'Collection Search')
def title(self): if self.header: return self.header else: return _(u'Collection Maps')
def yes_no(value): """Return i18n message for a value.""" if value: return _(u'Yes') else: return _(u'No')
def translate_value(value): return translate(_(value), context=getRequest())
class EditForm(base.EditForm): schema = ICollectionSearchPortlet label = _(u"Edit Collection Search Portlet") description = _( u"This portlet allows fulltext search in collection results.")
def ListScalingVocabulary(context): items = [SimpleTerm(title=_(it), value=it) for it in LIST_SCALING] return SimpleVocabulary(items)
class ICollectionFilterSchema(ICollectionFilterBaseSchema): """Schema for the filter. """ group_by = schema.Choice( title=_('label_groupby', u'Group by'), description=_( 'help_groupby', u'Select the criteria to group the collection results by.'), required=True, vocabulary='collective.collectionfilter.GroupByCriteria', ) show_count = schema.Bool( title=_(u'label_show_count', default=u'Show count'), description=_(u'help_show_count', default=u'Show the result count for each filter group.'), default=False, required=False) cache_enabled = schema.Bool( title=_(u"label_cache_enabled", default=u"Enable Cache"), description=_( u'help_cache_enabled', default=u"Enable caching of filter items. The cache is cleared as" u" soon as the database has any changes."), default=True, required=False, ) filter_type = schema.Choice( title=_('label_filter_type', u'Filter Type'), description=_( 'help_filter_type', u'Select if single or multiple criterias can be selected and if all (and) or any (or) of the selected criterias must be met.' # noqa u'Some index types like ``FieldIndex`` (e.g. Type index) only support the any (or) criteria when set to multiple criterias and ignore, if all (and) is set.' # noqa ), required=True, vocabulary='collective.collectionfilter.FilterType', ) input_type = schema.Choice( title=_('label_input_type', u'Input Type'), description=_( 'help_input_type', u'Select how the UI of the collection filter should be rendered. ' u'Wether as links, as checkboxes and radiobuttons or checkboxes and dropdowns.' # noqa ), required=True, vocabulary='collective.collectionfilter.InputType', ) narrow_down = schema.Bool( title=_(u'label_narrow_down', default=u'Narrow down filter options'), # noqa description=_( u'help_narrow_down', default= u'Narrow down the filter options when a filter of this group is applied.' # noqa u' Only options, which are available in the result set will then be displayed.' # noqa u' Other filter groups can still narrow down this one, though.' ), # noqa default=False, required=False) hide_if_empty = schema.Bool( title=_(u'label_hide_if_empty', default=u'Hide if empty'), # noqa description=_( u'help_hide_if_empty', default= u'Don\'t display if there is 1 or no options without selecting a filter yet.' ), default=False, required=False)
def yes_no(value): """Return i18n message for a value.""" if value: return _(u"Yes") return _(u"No")
def translate_value(value, *args, **kwargs): return translate(_(value), context=getRequest())
def title(self): if self.header: return self.header else: return _(u'Collection Filter')