Skip to content

Commit

Permalink
Merge pull request #137 from plone/contextual-vocabs
Browse files Browse the repository at this point in the history
Support getting querystring vocabs in context
  • Loading branch information
davisagli authored Sep 21, 2023
2 parents b711758 + 118ad82 commit c2e7f3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
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

0 comments on commit c2e7f3a

Please sign in to comment.