Skip to content

Commit e971270

Browse files
committed
add vocabulary for sponsor type
1 parent 383e21d commit e971270

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

backend/src/tagung/plone/de/content/sponsor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ISponsor(model.Schema):
2121
description=_(
2222
"",
2323
),
24-
vocabulary="tagung.plone.de.Levels",
24+
vocabulary="tagung.sponsor.Levels",
2525
default="Organizer",
2626
# defaultFactory=get_default_level,
2727
required=True,

backend/src/tagung/plone/de/vocabularies/configure.zcml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515
component=".talk.AudienceVocabulary"
1616
/>
1717

18+
<utility
19+
name="tagung.sponsor.Levels"
20+
component=".levels.LevelsFactory"
21+
/>
22+
1823
</configure>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# from plone import api
2+
from plone.dexterity.interfaces import IDexterityContent
3+
from tagung.plone.de import _
4+
from zope.globalrequest import getRequest
5+
from zope.interface import implementer
6+
from zope.schema.interfaces import IVocabularyFactory
7+
from zope.schema.vocabulary import SimpleTerm
8+
from zope.schema.vocabulary import SimpleVocabulary
9+
10+
11+
class VocabItem:
12+
def __init__(self, token, value):
13+
self.token = token
14+
self.value = value
15+
16+
17+
@implementer(IVocabularyFactory)
18+
class Levels:
19+
""" """
20+
21+
def __call__(self, context):
22+
# Just an example list of content for our vocabulary,
23+
# this can be any static or dynamic data, a catalog result for example.
24+
items = [
25+
VocabItem("Platinum", _("Platinum")),
26+
VocabItem("Gold", _("Gold")),
27+
VocabItem("Silver", _("Silver")),
28+
VocabItem("Bronze", _("Bronze")),
29+
VocabItem("Organizer", _("Organizer")),
30+
]
31+
32+
# Fix context if you are using the vocabulary in DataGridField.
33+
# See https://github.com/collective/collective.z3cform.datagridfield/issues/31: # NOQA: 501
34+
if not IDexterityContent.providedBy(context):
35+
req = getRequest()
36+
context = req.PARENTS[0]
37+
38+
# create a list of SimpleTerm items:
39+
terms = []
40+
for item in items:
41+
terms.append(
42+
SimpleTerm(
43+
value=item.token,
44+
token=str(item.token),
45+
title=item.value,
46+
)
47+
)
48+
# Create a SimpleVocabulary from the terms list and return it:
49+
return SimpleVocabulary(terms)
50+
51+
52+
LevelsFactory = Levels()

0 commit comments

Comments
 (0)