Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1.  
  2. Schema in ICourseFolder:
  3.  
  4. section = schema.Choice(
  5. title=_(u'Organization, unit or study-subject in Korppi'),
  6. vocabulary=u"jyu.opetusohjelma.Sections",
  7. required=False)
  8.  
  9.  
  10. # Vocabulary for the schema
  11. class SectionsVocabulary(object):
  12. grok.implements(IVocabularyFactory)
  13.  
  14. def __call__(self, context):
  15. terms = []
  16. sections = KorppiQueryUtility().getOrganizations()
  17. for section in sections:
  18. # Section[1] is orgname
  19. terms.append(SimpleVocabulary.createTerm(section[1]))
  20. return SimpleVocabulary(terms)
  21. grok.global_utility(SectionsVocabulary, name=u"jyu.opetusohjelma.Sections")
  22.  
  23.  
  24. def getOrganizations():
  25. query = urllib.urlopen(KORPPI_URL).read()
  26. import json
  27. korppiOrgs = json.loads(query)
  28. # strings in korppiOrgs are unicode
  29.  
  30. organizations = []
  31. for org in korppiOrgs['organisations']:
  32. orgid = org['id']
  33. orgname = org['name'] + ' (ID: %s)' % (orgid)
  34. organizations.append((orgid, orgname.encode('utf8')))
  35. return organizations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement