Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Schema in ICourseFolder:
- section = schema.Choice(
- title=_(u'Organization, unit or study-subject in Korppi'),
- vocabulary=u"jyu.opetusohjelma.Sections",
- required=False)
- # Vocabulary for the schema
- class SectionsVocabulary(object):
- grok.implements(IVocabularyFactory)
- def __call__(self, context):
- terms = []
- sections = KorppiQueryUtility().getOrganizations()
- for section in sections:
- # Section[1] is orgname
- terms.append(SimpleVocabulary.createTerm(section[1]))
- return SimpleVocabulary(terms)
- grok.global_utility(SectionsVocabulary, name=u"jyu.opetusohjelma.Sections")
- def getOrganizations():
- query = urllib.urlopen(KORPPI_URL).read()
- import json
- korppiOrgs = json.loads(query)
- # strings in korppiOrgs are unicode
- organizations = []
- for org in korppiOrgs['organisations']:
- orgid = org['id']
- orgname = org['name'] + ' (ID: %s)' % (orgid)
- organizations.append((orgid, orgname.encode('utf8')))
- return organizations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement