-
Notifications
You must be signed in to change notification settings - Fork 0
/
setuphandlers.py
85 lines (72 loc) · 2.9 KB
/
setuphandlers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
#
# File: setuphandlers.py
#
# Copyright (c) 2008 by (c) CENDITEL
# Generator: ArchGenXML Version 2.1
# http://plone.org/products/archgenxml
#
# GNU General Public License (GPL)
#
__author__ = """Leonardo J. Caballero G. <lcaballero@cenditel.gob.ve>, Ruben Rangel
<rubenrang@gmail.com>, Maria A. Espinoza <maespinoza@cenditel.gob.ve>"""
__docformat__ = 'plaintext'
import logging
logger = logging.getLogger('PloneRDA: setuphandlers')
from Products.PloneRDA.config import PROJECTNAME
from Products.PloneRDA.config import DEPENDENCIES
import os
from config import product_globals
from Globals import package_home
from Products.ATVocabularyManager.config import TOOL_NAME as ATVOCABULARYTOOL
from Products.CMFCore.utils import getToolByName
import transaction
##code-section HEAD
##/code-section HEAD
def isNotPloneRDAProfile(context):
return context.readDataFile("PloneRDA_marker.txt") is None
def installVocabularies(context):
"""creates/imports the atvm vocabs."""
if isNotPloneRDAProfile(context): return
site = context.getSite()
# Create vocabularies in vocabulary lib
atvm = getToolByName(site, ATVOCABULARYTOOL)
vocabmap = {'parroquia': ('SimpleVocabulary', 'SimpleVocabularyTerm'),
'tipo_establecimiento': ('SimpleVocabulary', 'SimpleVocabularyTerm'),
}
for vocabname in vocabmap.keys():
if not vocabname in atvm.contentIds():
atvm.invokeFactory(vocabmap[vocabname][0], vocabname)
if len(atvm[vocabname].contentIds()) < 1:
if vocabmap[vocabname][0] == "VdexVocabulary":
vdexpath = os.path.join(
package_home(product_globals), 'data', '%s.vdex' % vocabname)
if not (os.path.exists(vdexpath) and os.path.isfile(vdexpath)):
logger.warn('No VDEX import file provided at %s.' % vdexpath)
continue
try:
#read data
f = open(vdexpath, 'r')
data = f.read()
f.close()
except:
logger.warn("Problems while reading VDEX import file "+\
"provided at %s." % vdexpath)
continue
# this might take some time!
atvm[vocabname].importXMLBinding(data)
else:
pass
def updateRoleMappings(context):
"""after workflow changed update the roles mapping. this is like pressing
the button 'Update Security Setting' and portal_workflow"""
if isNotPloneRDAProfile(context): return
wft = getToolByName(context.getSite(), 'portal_workflow')
wft.updateRoleMappings()
def postInstall(context):
"""Called as at the end of the setup process. """
# the right place for your custom code
if isNotPloneRDAProfile(context): return
site = context.getSite()
##code-section FOOT
##/code-section FOOT