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
- Gives us UnicodeDecodeError:
- Module zope.tal.talinterpreter, line 518, in do_optTag
- Module zope.tal.talinterpreter, line 513, in no_tag
- Module zope.tal.talinterpreter, line 343, in interpret
- Module zope.tal.talinterpreter, line 852, in do_condition
- Module zope.tal.talinterpreter, line 343, in interpret
- Module zope.tal.talinterpreter, line 405, in do_startTag
- Module zope.tal.talinterpreter, line 502, in attrAction_tal
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
- If we do not encode, the Vocabulary will crash:
- Module Products.Five.schema, line 36, in get
- Module jyu.opetusohjelma.vocabularies, line 51, in __call__
- Module zope.schema.vocabulary, line 109, in createTerm
- Module zope.schema.vocabulary, line 39, in __init__
- UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 11: ordinal not in range(128)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement