Skip to content

Commit 324deda

Browse files
committed
Choice conditions: Limit to current tool (survey)
1 parent f7e472c commit 324deda

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/euphorie/content/choice.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class IChoice(model.Schema, IRichDescription, IBasic):
3737
"another choice. You can pick multiple options here. If the user selects one "
3838
"or more of them, then this choice will be shown. Leave blank to always show "
3939
"this choice.",
40-
value_type=RelationChoice(
41-
vocabulary=StaticCatalogVocabulary({"portal_type": ["euphorie.option"]}),
42-
),
40+
value_type=RelationChoice(vocabulary="euphorie.choice_conditions_vocabulary"),
4341
required=False,
4442
default=[],
4543
)

src/euphorie/content/configure.zcml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@
215215
component=".utils.MeasuresTextHandlingVocabularyFactory"
216216
/>
217217

218+
<utility
219+
provides="zope.schema.interfaces.IVocabularyFactory"
220+
name="euphorie.choice_conditions_vocabulary"
221+
component=".vocabularies.ChoiceConditionsVocabulary"
222+
/>
223+
218224

219225
<browser:page
220226
name="export_users"

src/euphorie/content/vocabularies.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
from Acquisition import aq_chain
2+
from Acquisition import aq_inner
3+
from euphorie.content.survey import ISurvey
14
from plone import api
5+
from plone.app.vocabularies.catalog import StaticCatalogVocabulary
26
from plone.app.vocabularies.terms import safe_simplevocabulary_from_values
37
from zope.interface import implementer
48
from zope.schema.interfaces import IContextSourceBinder
@@ -20,3 +24,15 @@ def values(self):
2024

2125
def __call__(self, context):
2226
return safe_simplevocabulary_from_values(self.values)
27+
28+
29+
def ChoiceConditionsVocabulary(context=None):
30+
query = {
31+
"portal_type": ["euphorie.option"],
32+
"sort_on": "path",
33+
}
34+
if context is not None:
35+
for parent in aq_chain(aq_inner(context)):
36+
if ISurvey.providedBy(parent):
37+
query["path"] = "/".join(parent.getPhysicalPath())
38+
return StaticCatalogVocabulary(query)

0 commit comments

Comments
 (0)