diff --git a/themis/fields/vocabs.py b/themis/fields/vocabs.py index 0527521..91e3a18 100644 --- a/themis/fields/vocabs.py +++ b/themis/fields/vocabs.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from zope import component from zope.browser.interfaces import ITerms from zope.interface import implements, classProvides from zope.schema.interfaces import ISource, IContextSourceBinder @@ -11,6 +12,14 @@ from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from Products.CMFCore.utils import getToolByName +from plone.registry.interfaces import IRegistry + +try: + from tabellio.config.interfaces import ITabellioSettings +except ImportError: + ITabellioSettings = None + + class CommissionsSource(object): implements(IContextSourceBinder) @@ -207,7 +216,20 @@ class LegislativeSessionsSource(object): # Legislative sessions implements(IContextSourceBinder) def __init__(self): - # XXX get this list from somewhere editable + self.terms = None + + def _setup(self): + if self.terms: + return + + if ITabellioSettings: + settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False) + sessions = settings.sessions + if sessions: + self.terms = [x.split(':')[1].strip() for x in sessions.splitlines() if x] + return + + # fallback to an hardcoded list self.terms = [ u"2010 - 2011", u"2009 - 2010", @@ -237,6 +259,7 @@ class LegislativeSessionsSource(object): # Legislative sessions ] def __call__(self, context): + self._setup() terms = [SimpleVocabulary.createTerm(x, x.encode('ascii', 'replace'), x) for x in self.terms] return SimpleVocabulary(terms)