Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support getting querystring vocabs in context #137

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/137.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a way to specific a context for getting vocabularies in the QuerystringRegistryReader. @davisagli
3 changes: 2 additions & 1 deletion plone/app/querystring/registryreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, context, request=None):
request = getRequest()

self.context = context
self.vocab_context = context
self.request = request

def parseRegistry(self):
Expand Down Expand Up @@ -87,7 +88,7 @@ def getVocabularyValues(self, values):
# Bail out if the annotation is marked not to fetch the vocabulary
# to allow the widget to query the vocabulary as needed
continue
for item in utility(self.context):
for item in utility(self.vocab_context):
if isinstance(item.title, Message):
title = translate(item.title, context=self.request)
else:
Expand Down
17 changes: 15 additions & 2 deletions plone/app/querystring/tests/testRegistryReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
@implementer(IVocabularyFactory)
class TestVocabulary:
def __call__(self, context):
return SimpleVocabulary([SimpleVocabulary.createTerm("foo", "foo", "bar")])
term = "subsite term" if getattr(context, "id", None) == "subsite" else "term"
return SimpleVocabulary([SimpleVocabulary.createTerm(term, term, term)])


class TestRegistryReader(unittest.TestCase):
Expand Down Expand Up @@ -82,7 +83,19 @@ def test_get_vocabularies(self):
result = reader.parseRegistry()
result = reader.getVocabularyValues(result)
vocabulary_result = result.get("plone.app.querystring.field.reviewState.values")
self.assertEqual(vocabulary_result, {"foo": {"title": "bar"}})
self.assertEqual(vocabulary_result, {"term": {"title": "term"}})

def test_get_vocabularies_in_context(self):
portal = self.layer["portal"]
subsite = portal[portal.invokeFactory("Document", "subsite", title="Subsite")]

registry = self.createRegistry(td.test_vocabulary_xml)
reader = IQuerystringRegistryReader(registry)
reader.vocab_context = subsite
result = reader.parseRegistry()
result = reader.getVocabularyValues(result)
vocabulary_result = result.get("plone.app.querystring.field.reviewState.values")
self.assertEqual(vocabulary_result, {"subsite term": {"title": "subsite term"}})

def test_map_operations_clean(self):
"""tests if mapOperations is getting all operators correctly"""
Expand Down