Good afternoon everyone,
I am in the process of preparing a Plone addon to work in the Volto frontend. Most of the features of the addon work except when I am using the following python code for the custom vocabulary listing:
# -*- coding: utf-8 -*-
from plone import api
from zope.interface import implementer
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary
@implementer(IVocabularyFactory)
class AvailableUnitGoals(object):
"""
"""
def __call__(self, context):
results = []
try:
get_container_unit = '/'.join(context.getPhysicalPath()[:-1])
unit = api.content.get(path=get_container_unit).define_unit
brains = api.content.find(
portal_type='unit_goal',
sort_on='sortable_title',
unit=unit
)
brains_unique = []
for brain in brains:
if brain.unit_goal not in brains_unique:
brains_unique.append(brain.unit_goal)
for brain in brains_unique:
results.append(
SimpleTerm(
value=brain,
title=brain,
)
)
except:
pass
# Create a SimpleVocabulary from the terms list and return it:
return SimpleVocabulary(results)
AvailableUnitGoalsFactory = AvailableUnitGoals()
Again, it works fine with no issues in Plone Classic, but fails in Volto and shows up empty. The same response shows in Postman. Was there something that changed in Plone 6 that was once available in Plone 5.2 or earlier regarding Plone Dynamic Vocabularies?
This is the error that is produced when I comment out the try and except:
2023-04-11 13:14:03,101 ERROR [Zope.SiteErrorLog:35][waitress-0] AttributeError: http://localhost:3000/@vocabularies/yc.assessment.AvailableUnitGoals
Traceback (innermost last):
Module ZPublisher.WSGIPublisher, line 181, in transaction_pubevents
Module ZPublisher.WSGIPublisher, line 390, in publish_module
Module ZPublisher.WSGIPublisher, line 285, in publish
Module ZPublisher.mapply, line 85, in mapply
Module ZPublisher.WSGIPublisher, line 68, in call_object
Module plone.rest.service, line 22, in __call__
Module plone.restapi.services, line 19, in render
Module plone.restapi.services.vocabularies.get, line 89, in reply
Module yc.assessment.vocabularies.available_unit_goals, line 18, in __call__
AttributeError: 'NoneType' object has no attribute 'define_unit'
Thanks in advance!
rbrown12