def installVocabularies(context):
    """ Creates/imports the atvm vocabs.
    """
    # only run this step if we are in eea.dataservice profile
    if context.readDataFile('land.copernicus.content.txt') is None:
        return

    site = context.getSite()
    atvm = getToolByName(site, ATVOCABULARYTOOL)

    # Create countries vocabulary
    if COUNTRIES_DICTIONARY_ID not in atvm.contentIds():
        hierarchicalVocab = {}
        hierarchicalVocab[(COUNTRIES_DICTIONARY_ID, 'European Countries')] = {}
        createHierarchicalVocabs(atvm, hierarchicalVocab)

        countries = getCountriesDictionary()
        for term in countries.keys():
            vocab = atvm[COUNTRIES_DICTIONARY_ID]
            vocab.invokeFactory('TreeVocabularyTerm', term[0], title=term[1])
            for subterm in countries[term].keys():
                subvocab = vocab[term[0]]
                subvocab.invokeFactory('TreeVocabularyTerm',
                                       subterm[0], title=subterm[1])
                subvocab.reindexObject()
            vocab.reindexObject()
    else:
        logger.warn('eea.dataservice countries vocabulary already exist.')
Example #2
0
    def setUpATVM(self):
        #FIXME: raise Unauthorize on invokeFactory done by the create
        atvm = self.portal.portal_vocabularies
        vkey = 'collective_categories'
        vocab = atvm.getVocabularyByName(vkey)

        if not vocab:
            vdict = {(vkey, 'collective.categories'): {}}
            createHierarchicalVocabs(atvm, vdict)
            vocab = atvm.getVocabularyByName(vkey)
    def setupExampleTreeVocabulary(self):
        hierarchicalVocabs = {}

        hierarchicalVocabs[('regions', 'Some regions in europe')] = {
            ('aut', 'Austria'): {
                ('tyr', 'Tyrol'): {
                    ('auss', 'Ausserfern'): {},
                }
            },
            ('ger', 'Germany'): {
                ('bav', 'Bavaria'): {}
            },
        }

        createHierarchicalVocabs(self.atvm, hierarchicalVocabs)
    def afterSetUp(self):
        setHooks()
        setSite(self.portal)
        self.setRoles(('Manager',))

        self.atvm = getToolByName(self.portal, 'portal_vocabularies')
        hierarchicalVocabs = {}

        hierarchicalVocabs[('regions', 'Some regions in europe')] = {
            ('aut', 'Austria'): {
                ('tyr', 'Tyrol'): {
                    ('auss', 'Ausserfern'): {},
                }
            },
            ('ger', 'Germany'): {
                ('bav', 'Bavaria'):{}
            },
        }

        createHierarchicalVocabs(self.atvm, hierarchicalVocabs)
    def afterSetUp(self):
        setHooks()
        setSite(self.portal)
        self.setRoles(('Manager',))
        self.atvm = getToolByName(self.portal, 'portal_vocabularies')
        hierarchicalVocabs = {}

        hierarchicalVocabs[('exampletags', 'Just a bunch of tags')] = {
            ('aut', 'Austria'): {
                ('tyr', 'Tyrol'): {
                    ('auss', 'Ausserfern'): {},
                }
            },
            ('ger', 'Germany'): {
                ('bav', 'Bavaria'):{}
            },
        }

        createHierarchicalVocabs(self.atvm, hierarchicalVocabs)
        self.city = self.portal.get(self.portal.invokeFactory('City', 'test1',
                                              title='test_title',
                                              description='test_description'))
        display_helper = self.city.getField('tags').vocabulary.getDisplayList(self.portal)
        self.city.tags = [display_helper.getKey(x) for x in ('Austria - Tyrol', 'Germany')]