Kirtap
(Kirtap)
July 28, 2021, 5:28pm
1
I'm trying to setup a faceted navigation view with sorting as one of the fields, but it won't display the metadata fields I want to sort on.
I have a content type with an interface that has two text line fields Manufacturer and Equipment_Type
I have two Metadata columns Manufacturer and Equipment_Type.
I have a SimpleVocabulary:
@provider(IVocabularyFactory)
def EquipmentSortableColumns(context):
terms = [SimpleTerm(value='Manufacturer', token='Manufacturer', title='Manufacturer'),
SimpleTerm(value='Equipment_Type', token='Equipment_Type', title='Equipment Type'),
]
return SimpleVocabulary(terms)
which I register in configure.zcml as 'my.product.equipment_sortable_columns'
I have a container where I setup a faceted navigation view and I have a widget with the type 'Sorting'. In the 'Filter from vocabulary', I place 'my.product.equipment_sortable_columns'. When I try to view the folder, the sorting widget is blank.
Where am I going wrong?
jaroel
(Roel Bruggink)
July 28, 2021, 9:33pm
2
I think you need to do @zope.interface.provider(IVocabularyFactory)
.
1 Like
avoinea
(Alin Voinea)
July 29, 2021, 8:06am
3
def listSortFields(self):
"""Return a list of available fields for sorting."""
registry = getUtility(IRegistry)
config = IQuerystringRegistryReader(registry)()
indexes = config.get('sortable_indexes', {})
for name, index in indexes.items():
title = index.get('title', name)
description = index.get('description', title)
yield (name, title, description)
Thus, you'll have to add your fields to sortable_indexes
registry.
1 Like
The world would be a better place if there was a dedicated configlet for the querystring settings that are now stored in the registry.
1 Like
Kirtap
(Kirtap)
July 29, 2021, 10:59am
5
Sorry, I was copying my code and I forgot to include that provider bit.
Kirtap
(Kirtap)
July 29, 2021, 11:54am
6
Thank you for your help and your time!
Adding it to the registry works.
I see where I misunderstood filter from vocabulary. I apologize.
1 Like
avoinea
(Alin Voinea)
July 29, 2021, 12:14pm
7
Don't have to apologize. AFAIK there is a vocabulary setting you can use with Sorting widget:
vocabulary = schema.Choice(
title=_(u'Filter from vocabulary'),
description=_(u'Vocabulary to use to filter sorting criteria. '
u'Leave empty for default sorting criteria.'),
vocabulary=u'eea.faceted.vocabularies.PortalVocabularies',
required=False
)
In case you don't want to show all sorting options you can provide a custom vocabulary. This way, you can also customize the labels.
1 Like