def installWorkflows(self, package, out): """Install the custom workflows for this product. """ productname = 'UWOshOIE' workflowTool = getToolByName(self, 'portal_workflow') ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'OIEStudentApplicationWorkflow', 'create_OIEStudentApplicationWorkflow') workflow = ourProductWorkflow('OIEStudentApplicationWorkflow') workflowTool._setObject('OIEStudentApplicationWorkflow', workflow) workflowTool.setChainForPortalTypes(['OIEStudentApplication'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'UWOshOIEProgramWorkflow', 'create_UWOshOIEProgramWorkflow') workflow = ourProductWorkflow('UWOshOIEProgramWorkflow') workflowTool._setObject('UWOshOIEProgramWorkflow', workflow) workflowTool.setChainForPortalTypes(['UWOshOIEProgram'], workflow.getId()) workflowTool.setChainForPortalTypes(['UWOshOIEEmailTemplate'], workflow.getId()) return workflowTool
def uninstall(self): out = StringIO() # try to call a workflow uninstall method # in 'InstallWorkflows.py' method 'uninstallWorkflows' try: installWorkflows = ExternalMethod('temp','temp',PROJECTNAME+'.InstallWorkflows', 'uninstallWorkflows').__of__(self) except NotFound: installWorkflows = None if installWorkflows: print >>out,'Workflow Uninstall:' res = uninstallWorkflows(self,out) print >>out,res or 'no output' else: print >>out,'no workflow uninstall' # try to call a custom uninstall method # in 'AppInstall.py' method 'uninstall' try: uninstall = ExternalMethod('temp','temp',PROJECTNAME+'.AppInstall', 'uninstall') except: uninstall = None if uninstall: print >>out,'Custom Uninstall:' res = uninstall(self) if res: print >>out,res else: print >>out,'no output' else: print >>out,'no custom uninstall' return out.getvalue()
def testStorage(self): em1 = ExternalMethod('em', 'test method', 'Test', 'testf') self.assertEqual(em1(4), math.sqrt(4)) state = em1.__getstate__() em2 = ExternalMethod.__basicnew__() em2.__setstate__(state) self.assertEqual(em2(9), math.sqrt(9)) self.assertNotIn('__defaults__', state)
def testStorage(self): em1 = ExternalMethod('em', 'test method', 'Test', 'testf') self.assertEqual(em1(4), math.sqrt(4)) state = em1.__getstate__() em2 = ExternalMethod.__basicnew__() em2.__setstate__(state) self.assertEqual(em2(9), math.sqrt(9)) self.failIf(state.has_key('func_defaults'))
def test_mapply(self): from ZPublisher.mapply import mapply em1 = ExternalMethod('em', 'test method', 'Test', 'testf') self.assertEqual(mapply(em1, (), {'arg1': 4}), math.sqrt(4)) state = em1.__getstate__() em2 = ExternalMethod.__basicnew__() em2.__setstate__(state) self.assertEqual(mapply(em1, (), {'arg1': 9}), math.sqrt(9))
def uninstall(self, reinstall=False): out = StringIO() # try to call a custom uninstall method # in 'AppInstall.py' method 'uninstall' try: uninstall = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'uninstall') except: uninstall = None if uninstall: print >> out, 'Custom Uninstall:' try: res = uninstall(self, reinstall) except TypeError: res = uninstall(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom uninstall' return out.getvalue()
def _initDCWorkflowScripts(workflow, scripts, context): """ Initialize DCWorkflow scripts """ for s_info in scripts: id = str(s_info['script_id']) # no unicode! meta_type = s_info['meta_type'] filename = s_info['filename'] file = '' if filename: file = context.readDataFile(filename) if meta_type == PythonScript.meta_type: script = PythonScript(id) script.write(file) elif meta_type == ExternalMethod.meta_type: script = ExternalMethod(id, '', s_info['module'], s_info['function']) elif meta_type == DTMLMethod.meta_type: script = DTMLMethod(file, __name__=id) workflow.scripts._setObject(id, script)
def beforeUninstall(self, reinstall, product, cascade): """ try to call a custom beforeUninstall method in 'AppInstall.py' method 'beforeUninstall' """ out = StringIO() try: beforeuninstall = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'beforeUninstall') except: beforeuninstall = [] if beforeuninstall: print >> out, 'Custom beforeUninstall:' res = beforeuninstall(self, reinstall=reinstall, product=product, cascade=cascade) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom beforeUninstall' return (out, cascade)
def uninstall(self): out = StringIO() classes = listTypes(PROJECTNAME) #unregister folderish classes in use_folder_contents props = getToolByName(self, 'portal_properties').site_properties use_folder_tabs = list(props.use_folder_tabs) print >> out, 'removing classes from use_folder_tabs:' for cl in classes: print >> out, 'type:', cl['klass'].portal_type if cl['klass'].isPrincipiaFolderish and not cl[ 'klass'].portal_type in []: if cl['klass'].portal_type in use_folder_tabs: use_folder_tabs.remove(cl['klass'].portal_type) props.use_folder_tabs = tuple(use_folder_tabs) #autouninstall tools for t in []: # undo: tools are not content. dont list it in navtree try: self.portal_properties.navtree_properties.metaTypesNotToList = list( self.portal_properties.navtree_properties.metaTypesNotToList) self.portal_properties.navtree_properties.metaTypesNotToList.remove( t) except ValueError: pass except: raise # unregister tool in control panel try: portal_control_panel = getToolByName(self, 'portal_control_panel_actions') except AttributeError: #portal_control_panel has been renamed in RC1 (grumpf) portal_control_panel = getToolByName(self, 'portal_controlpanel', None) #auto build #try to call a custom uninstall method #in 'AppInstall.py' method 'uninstall' try: uninstall = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'uninstall') except: uninstall = None if uninstall: print >> out, 'Custom Uninstall:' res = uninstall(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom uninstall' return out.getvalue()
def install(self, reinstall=False): """ External Method to install Poi """ out = StringIO() print >> out, "Installation log of %s:" % PROJECTNAME # If the config contains a list of dependencies, try to install # them. Add a list called DEPENDENCIES to your custom # AppConfig.py (imported by config.py) to use it. try: from Products.Poi.config import DEPENDENCIES except: DEPENDENCIES = [] portal = getToolByName(self, 'portal_url').getPortalObject() quickinstaller = portal.portal_quickinstaller portal_setup = getToolByName(portal, 'portal_setup') for dependency in DEPENDENCIES: print >> out, "Installing dependency %s:" % dependency try: quickinstaller.installProduct(dependency) except AlreadyInstalled: pass else: transaction.savepoint() # try to call a custom install method # in 'AppInstall.py' method 'install' try: install = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'install') except NotFound: install = None if install: print >> out, 'Custom Install:' try: res = install(self, reinstall) except TypeError: res = install(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom install' # The following section is boilerplate code that can be reused when you # need to invoke a GenericSetup profile from Install.py. for extension_id in EXTENSION_PROFILES: portal_setup.runAllImportStepsFromProfile('profile-%s' % extension_id) transaction.savepoint() return out.getvalue()
def addWorkflow(self, out): workflowTool = getToolByName(self, 'portal_workflow') for name, types, create, default in plonebooking_workflows: if create and name not in workflowTool.objectIds(): installFunc = ExternalMethod('temp', 'temp', PROJECTNAME + '.' + name, 'create' + name.capitalize()) workflow = installFunc(name) workflowTool._setObject(name, workflow) if types: workflowTool.setChainForPortalTypes(types, name) if default: workflowTool.setDefaultChain(name) out.write("Workflow added")
def _initDCWorkflowScripts( workflow, scripts, context ): """ Initialize DCWorkflow scripts """ for s_info in scripts: id = str( s_info[ 'script_id' ] ) # no unicode! meta_type = s_info[ 'meta_type' ] filename = s_info[ 'filename' ] file = '' if filename: file = context.readDataFile( filename ) if meta_type == PythonScript.meta_type: script = PythonScript( id ) script.write( file ) elif meta_type == ExternalMethod.meta_type: script = ExternalMethod( id , '' , s_info['module'] , s_info['function'] ) elif meta_type == DTMLMethod.meta_type: script = DTMLMethod( file, __name__=id ) else: for mt in workflow.scripts.filtered_meta_types(): if mt['name']==meta_type: if hasattr(mt['instance'], 'write'): script = mt['instance'](id) script.write(file) else: script = mt['instance'](file, __name__=id) break else: raise ValueError, 'Invalid type: %s' % meta_type if workflow.scripts.has_key(id): workflow.scripts._delObject(id) workflow.scripts._setObject( id, script )
def afterInstall(self, reinstall, product): """ try to call a custom afterInstall method in 'AppInstall.py' method 'afterInstall' """ out = StringIO() try: afterinstall = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'afterInstall') except: afterinstall = None if afterinstall: print >> out, 'Custom afterInstall:' res = afterinstall(self, product=None, reinstall=None) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom afterInstall' return out
def get_method(productname, modfunc): packages = get_packages() package = packages.get(productname, None) if package is None: package = packages.get('Products.' + productname, None) if package is None: return None extensions = os.path.join(package, 'Extensions') if not os.path.isdir(extensions): return None files = os.listdir(extensions) for mod, func in modfunc: if mod + '.py' in files: try: # id, title, module, function return ExternalMethod('temp', 'temp', productname + '.' + mod, func) except (NotFound, ImportError, RuntimeError): pass return None
def install(self, reinstall=False): """ External Method to install Bungeni """ out = StringIO() print >> out, "Installation log of %s:" % PROJECTNAME # If the config contains a list of dependencies, try to install # them. Add a list called DEPENDENCIES to your custom # AppConfig.py (imported by config.py) to use it. try: from Products.Bungeni.config import DEPENDENCIES except: DEPENDENCIES = [] portal = getToolByName(self, 'portal_url').getPortalObject() quickinstaller = portal.portal_quickinstaller for dependency in DEPENDENCIES: print >> out, "Installing dependency %s:" % dependency quickinstaller.installProduct(dependency) import transaction transaction.savepoint(optimistic=True) classes = listTypes(PROJECTNAME) installTypes(self, out, classes, PROJECTNAME) install_subskin(self, out, GLOBALS) # autoinstall tools portal = getToolByName(self, 'portal_url').getPortalObject() for t in ['BungeniMembershipTool', 'RotaTool']: try: portal.manage_addProduct[PROJECTNAME].manage_addTool(t) except BadRequest: # if an instance with the same name already exists this error will # be swallowed. Zope raises in an unelegant manner a 'Bad Request' error pass except: e = sys.exc_info() if e[0] != 'Bad Request': raise # hide tools in the search form portalProperties = getToolByName(self, 'portal_properties', None) if portalProperties is not None: siteProperties = getattr(portalProperties, 'site_properties', None) if siteProperties is not None and siteProperties.hasProperty( 'types_not_searched'): for tool in ['BungeniMembershipTool', 'RotaTool']: current = list( siteProperties.getProperty('types_not_searched')) if tool not in current: current.append(tool) siteProperties.manage_changeProperties( **{'types_not_searched': current}) # remove workflow for tools portal_workflow = getToolByName(self, 'portal_workflow') for tool in ['BungeniMembershipTool', 'RotaTool']: portal_workflow.setChainForPortalTypes([tool], '') # uncatalog tools for toolname in ['portal_bungenimembershiptool', 'portal_rotatool']: try: portal[toolname].unindexObject() except: pass # hide tools in the navigation portalProperties = getToolByName(self, 'portal_properties', None) if portalProperties is not None: navtreeProperties = getattr(portalProperties, 'navtree_properties', None) if navtreeProperties is not None and navtreeProperties.hasProperty( 'idsNotToList'): for toolname in [ 'portal_bungenimembershiptool', 'portal_rotatool' ]: current = list(navtreeProperties.getProperty('idsNotToList')) if toolname not in current: current.append(toolname) navtreeProperties.manage_changeProperties( **{'idsNotToList': current}) # register tools as configlets portal_controlpanel = getToolByName(self, 'portal_controlpanel') portal_controlpanel.unregisterConfiglet('RotaTool') portal_controlpanel.registerConfiglet( 'RotaTool', #id of your Tool 'RotaTool', # Title of your Product 'string:${portal_url}/portal_rotatool/view', 'python:True', # a condition 'Manage portal', # access permission 'Products', # section to which the configlet should be added: (Plone, Products (default) or Member) 1, # visibility 'RotaToolID', 'site_icon.gif', # icon in control_panel 'Defaults for rota generation', None, ) # try to call a workflow install method # in 'InstallWorkflows.py' method 'installWorkflows' try: installWorkflows = ExternalMethod('temp', 'temp', PROJECTNAME + '.InstallWorkflows', 'installWorkflows').__of__(self) except NotFound: installWorkflows = None if installWorkflows: print >> out, 'Workflow Install:' res = installWorkflows(self, out) print >> out, res or 'no output' else: print >> out, 'no workflow install' # Adds our types to MemberDataContainer.allowed_content_types types_tool = getToolByName(self, 'portal_types') act = types_tool.MemberDataContainer.allowed_content_types types_tool.MemberDataContainer.manage_changeProperties( allowed_content_types=act + ( 'MemberOfPublic', 'MemberOfParliament', 'Staff', )) # registers with membrane tool ... membrane_tool = getToolByName(self, 'membrane_tool') membrane_tool.registerMembraneType('MemberOfPublic') # print >> out, SetupMember(self, member_type='MemberOfPublic', register=False).finish() membrane_tool.registerMembraneType('MemberOfParliament') # print >> out, SetupMember(self, member_type='MemberOfParliament', register=False).finish() membrane_tool.registerMembraneType('Staff') # print >> out, SetupMember(self, member_type='Staff', register=False).finish() #bind classes to workflows wft = getToolByName(self, 'portal_workflow') wft.setChainForPortalTypes(['Staff'], "MemberAutoWorkflow") wft.setChainForPortalTypes(['Motion'], "ParliamentaryEventWorkflow") wft.setChainForPortalTypes(['Question'], "ParliamentaryEventWorkflow") wft.setChainForPortalTypes(['LegislationFolder'], "BungeniWorkflow") wft.setChainForPortalTypes(['BillPage'], "SubWorkflow") wft.setChainForPortalTypes(['DebateRecordPage'], "SubWorkflow") wft.setChainForPortalTypes(['DebateRecordSection'], "SubWorkflow") # configuration for Relations relations_tool = getToolByName(self, 'relations_library') xmlpath = os.path.join(package_home(GLOBALS), 'relations.xml') f = open(xmlpath) xml = f.read() f.close() relations_tool.importXML(xml) # enable portal_factory for given types factory_tool = getToolByName(self, 'portal_factory') factory_types = [ "MemberOfPublic", "MemberOfParliament", "BungeniMembershipTool", "Staff", "LongDocument", "LongDocumentSection", "LongDocumentPage", "HelpFolder", "MinistryFolder", "Motion", "Question", "Response", "OrderOfBusiness", "AgendaItem", "Sitting", "Session", "CommitteeFolder", "LegislationFolder", "Bill", "BillPage", "BillSection", "Amendment", "DebateRecord", "DebateRecordPage", "DebateRecordFolder", "DebateRecordSection", "TakeTranscription", "Minutes", "Take", "RotaFolder", "RotaItem", "RotaTool", "Committee", "PoliticalGroup", "Reporters", "Parliament", "Office", "BungeniTeamSpace", "DebateRecordOffice", "BungeniTeam", "Region", "Constituency", "Regions", "Province", "OfficeWS", "OfficeFolder", "ParliamentWS", "CommitteeWS", "Ministry", "Portfolio", "Government", "Minister", "AssistantMinister", ] + factory_tool.getFactoryTypes().keys() factory_tool.manage_setPortalFactoryTypes(listOfTypeIds=factory_types) from Products.Bungeni.config import STYLESHEETS try: portal_css = getToolByName(portal, 'portal_css') for stylesheet in STYLESHEETS: try: portal_css.unregisterResource(stylesheet['id']) except: pass defaults = {'id': '', 'media': 'all', 'enabled': True} defaults.update(stylesheet) portal_css.registerStylesheet(**defaults) except: # No portal_css registry pass from Products.Bungeni.config import JAVASCRIPTS try: portal_javascripts = getToolByName(portal, 'portal_javascripts') for javascript in JAVASCRIPTS: try: portal_javascripts.unregisterResource(javascript['id']) except: pass defaults = {'id': ''} defaults.update(javascript) portal_javascripts.registerScript(**defaults) except: # No portal_javascripts registry pass # try to call a custom install method # in 'AppInstall.py' method 'install' try: install = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'install') except NotFound: install = None if install: print >> out, 'Custom Install:' try: res = install(self, reinstall) except TypeError: res = install(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom install' setup_tool = getToolByName(portal, 'portal_setup') setup_tool.setImportContext('profile-Bungeni:default') setup_tool.runAllImportSteps() setup_tool.setImportContext('profile-CMFPlone:plone') print >> out, "Ran all GS import steps." return out.getvalue()
def uninstall(self, reinstall=False): out = StringIO() # Removes our types from MemberDataContainer.allowed_content_types types_tool = getToolByName(self, 'portal_types') act = types_tool.MemberDataContainer.allowed_content_types types_tool.MemberDataContainer.manage_changeProperties( allowed_content_types=[ ct for ct in act if ct not in ( 'MemberOfPublic', 'MemberOfParliament', 'Staff', ) ]) # unregister with membrane tool ... membrane_tool = getToolByName(self, 'membrane_tool') membrane_tool.unregisterMembraneType('MemberOfPublic') # print >> out, SetupMember(self, member_type='MemberOfPublic', register=False).finish() membrane_tool.unregisterMembraneType('MemberOfParliament') # print >> out, SetupMember(self, member_type='MemberOfParliament', register=False).finish() membrane_tool.unregisterMembraneType('Staff') # print >> out, SetupMember(self, member_type='Staff', register=False).finish() # unhide tools in the search form portalProperties = getToolByName(self, 'portal_properties', None) if portalProperties is not None: siteProperties = getattr(portalProperties, 'site_properties', None) if siteProperties is not None and siteProperties.hasProperty( 'types_not_searched'): for tool in ['BungeniMembershipTool', 'RotaTool']: current = list( siteProperties.getProperty('types_not_searched')) if tool in current: current.remove(tool) siteProperties.manage_changeProperties( **{'types_not_searched': current}) # unhide tools portalProperties = getToolByName(self, 'portal_properties', None) if portalProperties is not None: navtreeProperties = getattr(portalProperties, 'navtree_properties', None) if navtreeProperties is not None and navtreeProperties.hasProperty( 'idsNotToList'): for toolname in [ 'portal_bungenimembershiptool', 'portal_rotatool' ]: current = list(navtreeProperties.getProperty('idsNotToList')) if toolname in current: current.remove(toolname) navtreeProperties.manage_changeProperties( **{'idsNotToList': current}) # try to call a workflow uninstall method # in 'InstallWorkflows.py' method 'uninstallWorkflows' try: uninstallWorkflows = ExternalMethod('temp', 'temp', PROJECTNAME + '.InstallWorkflows', 'uninstallWorkflows').__of__(self) except NotFound: uninstallWorkflows = None if uninstallWorkflows: print >> out, 'Workflow Uninstall:' res = uninstallWorkflows(self, out) print >> out, res or 'no output' else: print >> out, 'no workflow uninstall' # try to call a custom uninstall method # in 'AppInstall.py' method 'uninstall' try: uninstall = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'uninstall') except: uninstall = None if uninstall: print >> out, 'Custom Uninstall:' try: res = uninstall(self, reinstall) except TypeError: res = uninstall(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom uninstall' return out.getvalue()
<dtml-var "generator.generateModuleInfoHeader(package)"> from Products.CMFCore.utils import getToolByName from Products.ExternalMethod.ExternalMethod import ExternalMethod <dtml-var "generator.getProtectedSection(parsedModule, 'module-header', 0)"> def installWorkflows(self, package, out): """Install the custom workflows for this product.""" productname = '<dtml-var "package.getCleanName()">' workflowTool = getToolByName(self, 'portal_workflow') <dtml-in "package.getStateMachines()"> <dtml-let sm="_['sequence-item']"> ourProductWorkflow = ExternalMethod('temp', 'temp', productname+'.'+'<dtml-var "generator.cleanName(sm.getName())">', 'create<dtml-var "generator.cleanName(sm.getName())">') workflow = ourProductWorkflow(self, '<dtml-var "generator.cleanName(sm.getName())">') if '<dtml-var "generator.cleanName(sm.getName())">' in workflowTool.listWorkflows(): print >> out, '<dtml-var "generator.cleanName(sm.getName())"> already in workflows.' else: workflowTool._setObject('<dtml-var "generator.cleanName(sm.getName())">', workflow) workflowTool.setChainForPortalTypes(<dtml-var "repr(sm.getClassNames())">, workflow.getId()) </dtml-let> </dtml-in> <dtml-var "generator.getProtectedSection(parsedModule, 'after-workflow-install', 1)"> return workflowTool def uninstallWorkflows(self, package, out):
def install(self, reinstall=False): """ External Method to install gvSIGi18n """ out = StringIO() print >> out, "Installation log of %s:" % PROJECTNAME # If the config contains a list of dependencies, try to install # them. Add a list called DEPENDENCIES to your custom # AppConfig.py (imported by config.py) to use it. try: from Products.gvSIGi18n.config import DEPENDENCIES except: DEPENDENCIES = [] portal = getToolByName(self, 'portal_url').getPortalObject() quickinstaller = portal.portal_quickinstaller for dependency in DEPENDENCIES: print >> out, "Installing dependency %s:" % dependency quickinstaller.installProduct(dependency) get_transaction().commit(1) classes = listTypes(PROJECTNAME) installTypes(self, out, classes, PROJECTNAME) install_subskin(self, out, GLOBALS) # try to call a workflow install method # in 'InstallWorkflows.py' method 'installWorkflows' try: installWorkflows = ExternalMethod('temp', 'temp', PROJECTNAME + '.InstallWorkflows', 'installWorkflows').__of__(self) except NotFound: installWorkflows = None if installWorkflows: print >> out, 'Workflow Install:' res = installWorkflows(self, out) print >> out, res or 'no output' else: print >> out, 'no workflow install' # enable portal_factory for given types factory_tool = getToolByName(self, 'portal_factory') factory_types = [ "TRAColeccionInformes", "TRAModulo", "TRAColeccionCadenas", "TRAProgreso", "TRAInforme", "TRAParametrosControlProgreso", "TRAContenidoXML", "TRAColeccionImportaciones", "TRACadena", "TRAColeccionSolicitudesCadenas", "TRAConfiguracionSolicitudesCadenas", "TRAConfiguracionPaginaTraducciones", "TRASimbolosOrdenados", "TRACatalogo", "TRAColeccionIdiomas", "TRAConfiguracionInvalidacionInformes", "TRAConfiguracionVarios", "TRAContenidoIntercambio", "TRAConfiguracionImportacion", "TRAConfiguracionExportacion", "TRAImportacion", "TRAIdioma", "TRAColeccionModulos", "TRATraduccion", "TRAColeccionContribuciones", "TRAColeccionProgresos", "TRAConfiguracionPermisos", "TRAContribuciones", "TRAConfiguracionPerfilEjecucion", "TRASolicitudCadena", ] + factory_tool.getFactoryTypes().keys() factory_tool.manage_setPortalFactoryTypes(listOfTypeIds=factory_types) from Products.gvSIGi18n.config import STYLESHEETS try: portal_css = getToolByName(portal, 'portal_css') for stylesheet in STYLESHEETS: try: portal_css.unregisterResource(stylesheet['id']) except: pass defaults = {'id': '', 'media': 'all', 'enabled': True} defaults.update(stylesheet) portal_css.registerStylesheet(**defaults) except: # No portal_css registry pass from Products.gvSIGi18n.config import JAVASCRIPTS try: portal_javascripts = getToolByName(portal, 'portal_javascripts') for javascript in JAVASCRIPTS: try: portal_javascripts.unregisterResource(javascript['id']) except: pass defaults = {'id': ''} defaults.update(javascript) portal_javascripts.registerScript(**defaults) except: # No portal_javascripts registry pass # try to call a custom install method # in 'AppInstall.py' method 'install' try: install = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'install') except NotFound: install = None if install: print >> out, 'Custom Install:' try: res = install(self, reinstall) except TypeError: res = install(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom install' return out.getvalue()
def install(self, reinstall=False): """ External Method to install UWOshCommitteeOnCommittees """ out = StringIO() print >> out, "Installation log of %s:" % PROJECTNAME # If the config contains a list of dependencies, try to install # them. Add a list called DEPENDENCIES to your custom # AppConfig.py (imported by config.py) to use it. try: from Products.UWOshCommitteeOnCommittees.config import DEPENDENCIES except: DEPENDENCIES = [] portal = getToolByName(self, 'portal_url').getPortalObject() quickinstaller = portal.portal_quickinstaller for dependency in DEPENDENCIES: print >> out, "Installing dependency %s:" % dependency quickinstaller.installProduct(dependency) get_transaction().commit(1) classes = listTypes(PROJECTNAME) installTypes(self, out, classes, PROJECTNAME) install_subskin(self, out, GLOBALS) # try to call a workflow install method # in 'InstallWorkflows.py' method 'installWorkflows' try: installWorkflows = ExternalMethod('temp', 'temp', PROJECTNAME + '.InstallWorkflows', 'installWorkflows').__of__(self) except NotFound: installWorkflows = None if installWorkflows: print >> out, 'Workflow Install:' res = installWorkflows(self, out) print >> out, res or 'no output' else: print >> out, 'no workflow install' # enable portal_factory for given types factory_tool = getToolByName(self, 'portal_factory') factory_types = [ "Committee", "CommitteeMember", "College", "Division", "Department", "Constituency", "Person", ] + factory_tool.getFactoryTypes().keys() factory_tool.manage_setPortalFactoryTypes(listOfTypeIds=factory_types) from Products.UWOshCommitteeOnCommittees.config import STYLESHEETS try: portal_css = getToolByName(portal, 'portal_css') for stylesheet in STYLESHEETS: try: portal_css.unregisterResource(stylesheet['id']) except: pass defaults = {'id': '', 'media': 'all', 'enabled': True} defaults.update(stylesheet) portal_css.registerStylesheet(**defaults) except: # No portal_css registry pass from Products.UWOshCommitteeOnCommittees.config import JAVASCRIPTS try: portal_javascripts = getToolByName(portal, 'portal_javascripts') for javascript in JAVASCRIPTS: try: portal_javascripts.unregisterResource(javascript['id']) except: pass defaults = {'id': ''} defaults.update(javascript) portal_javascripts.registerScript(**defaults) except: # No portal_javascripts registry pass # try to call a custom install method # in 'AppInstall.py' method 'install' try: install = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'install') except NotFound: install = None if install: print >> out, 'Custom Install:' try: res = install(self, reinstall) except TypeError: res = install(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom install' return out.getvalue()
def installWorkflows(self, package, out): """Install the custom workflows for this product.""" productname = 'Bungeni' workflowTool = getToolByName(self, 'portal_workflow') ourProductWorkflow = ExternalMethod('temp', 'temp', productname + '.' + 'BungeniWorkflow', 'createBungeniWorkflow') workflow = ourProductWorkflow(self, 'BungeniWorkflow') if 'BungeniWorkflow' in workflowTool.listWorkflows(): print >> out, 'BungeniWorkflow already in workflows.' else: workflowTool._setObject('BungeniWorkflow', workflow) workflowTool.setChainForPortalTypes(['ATFile', 'LegislationFolder'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'MemberApprovalWorkflow', 'createMemberApprovalWorkflow') workflow = ourProductWorkflow(self, 'MemberApprovalWorkflow') if 'MemberApprovalWorkflow' in workflowTool.listWorkflows(): print >> out, 'MemberApprovalWorkflow already in workflows.' else: workflowTool._setObject('MemberApprovalWorkflow', workflow) workflowTool.setChainForPortalTypes(['MemberOfPublic'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'MemberAutoWorkflow', 'createMemberAutoWorkflow') workflow = ourProductWorkflow(self, 'MemberAutoWorkflow') if 'MemberAutoWorkflow' in workflowTool.listWorkflows(): print >> out, 'MemberAutoWorkflow already in workflows.' else: workflowTool._setObject('MemberAutoWorkflow', workflow) workflowTool.setChainForPortalTypes(['MemberOfParliament', 'Staff'], workflow.getId()) ourProductWorkflow = ExternalMethod('temp', 'temp', productname + '.' + 'MotionWorkflow', 'createMotionWorkflow') workflow = ourProductWorkflow(self, 'MotionWorkflow') if 'MotionWorkflow' in workflowTool.listWorkflows(): print >> out, 'MotionWorkflow already in workflows.' else: workflowTool._setObject('MotionWorkflow', workflow) workflowTool.setChainForPortalTypes(['Motion'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'ParliamentaryEventWorkflow', 'createParliamentaryEventWorkflow') workflow = ourProductWorkflow(self, 'ParliamentaryEventWorkflow') if 'ParliamentaryEventWorkflow' in workflowTool.listWorkflows(): print >> out, 'ParliamentaryEventWorkflow already in workflows.' else: workflowTool._setObject('ParliamentaryEventWorkflow', workflow) workflowTool.setChainForPortalTypes( ['ParliamentaryEvent', 'Motion', 'Question'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'WestminsterBillWorkflow', 'createWestminsterBillWorkflow') workflow = ourProductWorkflow(self, 'WestminsterBillWorkflow') if 'WestminsterBillWorkflow' in workflowTool.listWorkflows(): print >> out, 'WestminsterBillWorkflow already in workflows.' else: workflowTool._setObject('WestminsterBillWorkflow', workflow) workflowTool.setChainForPortalTypes(['Bill'], workflow.getId()) ourProductWorkflow = ExternalMethod('temp', 'temp', productname + '.' + 'SubWorkflow', 'createSubWorkflow') workflow = ourProductWorkflow(self, 'SubWorkflow') if 'SubWorkflow' in workflowTool.listWorkflows(): print >> out, 'SubWorkflow already in workflows.' else: workflowTool._setObject('SubWorkflow', workflow) workflowTool.setChainForPortalTypes( ['BillSection', 'BillPage', 'DebateRecordPage', 'DebateRecordSection'], workflow.getId()) ourProductWorkflow = ExternalMethod('temp', 'temp', productname + '.' + 'HansardWorkflow', 'createHansardWorkflow') workflow = ourProductWorkflow(self, 'HansardWorkflow') if 'HansardWorkflow' in workflowTool.listWorkflows(): print >> out, 'HansardWorkflow already in workflows.' else: workflowTool._setObject('HansardWorkflow', workflow) workflowTool.setChainForPortalTypes(['DebateRecord'], workflow.getId()) ourProductWorkflow = ExternalMethod('temp', 'temp', productname + '.' + 'TakeWorkflow', 'createTakeWorkflow') workflow = ourProductWorkflow(self, 'TakeWorkflow') if 'TakeWorkflow' in workflowTool.listWorkflows(): print >> out, 'TakeWorkflow already in workflows.' else: workflowTool._setObject('TakeWorkflow', workflow) workflowTool.setChainForPortalTypes(['Take'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'RotaFolderWorkflow', 'createRotaFolderWorkflow') workflow = ourProductWorkflow(self, 'RotaFolderWorkflow') if 'RotaFolderWorkflow' in workflowTool.listWorkflows(): print >> out, 'RotaFolderWorkflow already in workflows.' else: workflowTool._setObject('RotaFolderWorkflow', workflow) workflowTool.setChainForPortalTypes(['RotaFolder'], workflow.getId()) ourProductWorkflow = ExternalMethod('temp', 'temp', productname + '.' + 'RotaItemWorkflow', 'createRotaItemWorkflow') workflow = ourProductWorkflow(self, 'RotaItemWorkflow') if 'RotaItemWorkflow' in workflowTool.listWorkflows(): print >> out, 'RotaItemWorkflow already in workflows.' else: workflowTool._setObject('RotaItemWorkflow', workflow) workflowTool.setChainForPortalTypes(['RotaItem'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'CommitteeWorkflow', 'createCommitteeWorkflow') workflow = ourProductWorkflow(self, 'CommitteeWorkflow') if 'CommitteeWorkflow' in workflowTool.listWorkflows(): print >> out, 'CommitteeWorkflow already in workflows.' else: workflowTool._setObject('CommitteeWorkflow', workflow) workflowTool.setChainForPortalTypes(['Committee'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'PoliticalGroupWorkflow', 'createPoliticalGroupWorkflow') workflow = ourProductWorkflow(self, 'PoliticalGroupWorkflow') if 'PoliticalGroupWorkflow' in workflowTool.listWorkflows(): print >> out, 'PoliticalGroupWorkflow already in workflows.' else: workflowTool._setObject('PoliticalGroupWorkflow', workflow) workflowTool.setChainForPortalTypes(['PoliticalGroup'], workflow.getId()) ourProductWorkflow = ExternalMethod( 'temp', 'temp', productname + '.' + 'ParliamentWorkflow', 'createParliamentWorkflow') workflow = ourProductWorkflow(self, 'ParliamentWorkflow') if 'ParliamentWorkflow' in workflowTool.listWorkflows(): print >> out, 'ParliamentWorkflow already in workflows.' else: workflowTool._setObject('ParliamentWorkflow', workflow) workflowTool.setChainForPortalTypes(['Parliament'], workflow.getId()) ourProductWorkflow = ExternalMethod('temp', 'temp', productname + '.' + 'OfficeWorkflow', 'createOfficeWorkflow') workflow = ourProductWorkflow(self, 'OfficeWorkflow') if 'OfficeWorkflow' in workflowTool.listWorkflows(): print >> out, 'OfficeWorkflow already in workflows.' else: workflowTool._setObject('OfficeWorkflow', workflow) workflowTool.setChainForPortalTypes(['Office'], workflow.getId()) ##code-section after-workflow-install #fill in your manual code here ##/code-section after-workflow-install return workflowTool
def setupLensWorkflow(self, workflow): """Define the LensWorkflow workflow. """ workflow.setProperties(title='LensWorkflow') ##code-section create-workflow-setup-method-header #fill in your manual code here ##/code-section create-workflow-setup-method-header for s in ['private', 'private_open', 'published', 'published_open']: workflow.states.addState(s) for t in ['hide', 'expose_private', 'publish', 'expose_published']: workflow.transitions.addTransition(t) for v in ['review_history', 'comments', 'time', 'actor', 'action']: workflow.variables.addVariable(v) workflow.addManagedPermission('Access contents information') workflow.addManagedPermission('View') workflow.addManagedPermission('Modify portal content') workflow.addManagedPermission('List folder contents') workflow.addManagedPermission('Add lens selected content') for l in []: if not l in workflow.worklists.objectValues(): workflow.worklists.addWorklist(l) ## Initial State workflow.states.setInitialState('private') ## States initialization stateDef = workflow.states['private'] stateDef.setProperties( title="""Private""", description="""""", transitions=['publish', 'expose_private', 'expose_published']) stateDef.setPermission('Access contents information', 0, ['Manager', 'Owner']) stateDef.setPermission('View', 0, ['Manager', 'Owner']) stateDef.setPermission('Modify portal content', 0, ['Manager', 'Owner']) stateDef.setPermission('List folder contents', 0, ['Manager', 'Owner']) stateDef = workflow.states['private_open'] stateDef.setProperties(title="""Open""", description="""""", transitions=['publish', 'hide', 'expose_published']) stateDef.setPermission('Access contents information', 1, ['Anonymous', 'Manager']) stateDef.setPermission('View', 1, ['Anonymous', 'Manager', 'Owner']) stateDef.setPermission('Modify portal content', 0, ['Manager', 'Owner']) stateDef.setPermission('List folder contents', 1, ['Anonymous']) stateDef.setPermission('Add lens selected content', 1, ['Manager', 'Owner', 'Member']) stateDef = workflow.states['published'] stateDef.setProperties( title="""Public""", description="""""", transitions=['hide', 'expose_private', 'expose_published']) stateDef.setPermission('Access contents information', 1, ['Anonymous', 'Manager']) stateDef.setPermission('View', 1, ['Anonymous', 'Manager', 'Owner']) stateDef.setPermission('Modify portal content', 0, ['Manager', 'Owner']) stateDef.setPermission('List folder contents', 1, ['Anonymous']) stateDef = workflow.states['published_open'] stateDef.setProperties(title="""Public Open""", description="""""", transitions=['expose_private', 'publish', 'hide']) stateDef.setPermission('Access contents information', 1, ['Anonymous', 'Manager']) stateDef.setPermission('View', 1, ['Anonymous', 'Manager', 'Owner']) stateDef.setPermission('List folder contents', 1, ['Anonymous']) stateDef.setPermission('Modify portal content', 0, ['Manager', 'Owner']) stateDef.setPermission('Add lens selected content', 1, ['Manager', 'Owner', 'Member']) ## Transitions initialization ## Creation of workflow scripts for wf_scriptname in ['afterTransition']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject( wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.LensWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['hide'] transitionDef.setProperties( title="""hide""", new_state_id="""private""", trigger_type=1, script_name="""""", after_script_name="""afterTransition""", actbox_name="""hide""", actbox_url="""""", actbox_category="""workflow""", props={'guard_roles': 'Owner'}, ) ## Creation of workflow scripts for wf_scriptname in ['afterTransition']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject( wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.LensWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['expose_private'] transitionDef.setProperties( title="""expose_private""", new_state_id="""private_open""", trigger_type=1, script_name="""""", after_script_name="""afterTransition""", actbox_name="""expose_private""", actbox_url="""""", actbox_category="""workflow""", props={ 'guard_permissions': 'Modify portal content', 'guard_roles': 'Manager;Owner' }, ) ## Creation of workflow scripts for wf_scriptname in ['afterTransition']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject( wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.LensWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['publish'] transitionDef.setProperties( title="""publish""", new_state_id="""published""", trigger_type=1, script_name="""""", after_script_name="""afterTransition""", actbox_name="""publish""", actbox_url="""""", actbox_category="""workflow""", props={ 'guard_permissions': 'Modify portal content', 'guard_roles': 'Manager;Owner' }, ) ## Creation of workflow scripts for wf_scriptname in ['afterTransition']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject( wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.LensWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['expose_published'] transitionDef.setProperties( title="""expose_published""", new_state_id="""published_open""", trigger_type=1, script_name="""""", after_script_name="""afterTransition""", actbox_name="""expose_published""", actbox_url="""""", actbox_category="""workflow""", props={ 'guard_permissions': 'Modify portal content', 'guard_roles': 'Manager;Owner' }, ) ## State Variable workflow.variables.setStateVar('review_state') ## Variables initialization variableDef = workflow.variables['review_history'] variableDef.setProperties( description="""Provides access to workflow history""", default_value="""""", default_expr="""state_change/getHistory""", for_catalog=0, for_status=0, update_always=0, props={'guard_permissions': 'Request review; Review portal content'}) variableDef = workflow.variables['comments'] variableDef.setProperties( description="""Comments about the last transition""", default_value="""""", default_expr="""python:state_change.kwargs.get('comment', '')""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['time'] variableDef.setProperties(description="""Time of the last transition""", default_value="""""", default_expr="""state_change/getDateTime""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['actor'] variableDef.setProperties( description="""The ID of the user who performed the last transition""", default_value="""""", default_expr="""user/getId""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['action'] variableDef.setProperties(description="""The last transition""", default_value="""""", default_expr="""transition/getId|nothing""", for_catalog=0, for_status=1, update_always=1, props=None)
def fVerifyOrInitialize_ExternalMethod(self, theInitializationSpecification=None, theContextualElement=None, theAllowInitialization=False, thePortalRoot=None): if not theInitializationSpecification: return None if theContextualElement == None: return None if thePortalRoot == None: return None unInforme = self.fNewVoidInformeVerifyOrInitExternalMethod() aExtMethodModule = theInitializationSpecification.get( 'ext_method_module', '') aExtMethodFunction = theInitializationSpecification.get( 'ext_method_function', '') aExtMethodId = theInitializationSpecification.get('ext_method_id', '') aExtMethodTitle = theInitializationSpecification.get( 'ext_method_title', '') anInstallPath = theInitializationSpecification.get('install_path', '') aRequired = theInitializationSpecification.get('required', '') try: unInforme.update({ 'ext_method_module': aExtMethodModule, 'ext_method_function': aExtMethodFunction, 'ext_method_id': aExtMethodId, 'ext_method_title': aExtMethodTitle, 'install_path': anInstallPath, 'required': aRequired, }) if not aExtMethodModule or not aExtMethodFunction or not aExtMethodId or not aExtMethodTitle: unInforme['success'] = False unInforme['condition'] = 'MISSING_parameters' return unInforme if theAllowInitialization: if not self.fCheckInitializationPermissions_ExternalMethod( theContextualElement): unInforme['success'] = False unInforme[ 'condition'] = 'user_can_NOT_initialize ExternalMethod %s' % str( theInitializationSpecification) return unInforme unInstallContainer = thePortalRoot if anInstallPath: unInstallContainer = self.fInstallContainer_Traversal( thePortalRoot, anInstallPath) if unInstallContainer == None: unInforme.update({ 'success': False, 'condition': 'No_InstallContainer', }) return unInforme unExternalMethod = None try: unExternalMethod = aq_get(unInstallContainer, aExtMethodId, None, 1) except: None if unExternalMethod: unInforme['success'] = True unInforme['status'] = 'exists' return unInforme if not (theAllowInitialization and cLazyCreateExternalMethods): unInforme['success'] = False unInforme['status'] = 'missing' return unInforme unNewExternalMethod = None try: unNewExternalMethod = ExternalMethod( aExtMethodId, aExtMethodTitle, aExtMethodModule, aExtMethodFunction, ) except: unaExceptionInfo = sys.exc_info() unaExceptionFormattedTraceback = ''.join( traceback.format_exception(*unaExceptionInfo)) unInformeExcepcion = 'Exception during ExternalMethod compilation in operation fVerifyOrInitialize_ExternalMethod for %s\n' % str( theInitializationSpecification) unInformeExcepcion += 'exception class %s\n' % unaExceptionInfo[ 1].__class__.__name__ unInformeExcepcion += 'exception message %s\n\n' % str( unaExceptionInfo[1].args) unInformeExcepcion += unaExceptionFormattedTraceback unInforme['success'] = False unInforme['condition'] = 'exception' unInforme['exception'] = unInformeExcepcion if cLogExceptions: logging.getLogger('ModelDDvlPloneTool').error( unInformeExcepcion) return unInforme if not unNewExternalMethod: unInforme['success'] = False unInforme['status'] = 'creation_failed' return unInforme unInstallContainer._setObject(aExtMethodId, unNewExternalMethod) unExternalMethod = None try: unExternalMethod = aq_get(unInstallContainer, aExtMethodId, None, 1) except: None if not unExternalMethod: unInforme['success'] = False unInforme['status'] = 'creation_failed' return unInforme unInforme['success'] = True unInforme['status'] = 'created' transaction.commit() unInforme['committed'] = True return unInforme except: unaExceptionInfo = sys.exc_info() unaExceptionFormattedTraceback = ''.join( traceback.format_exception(*unaExceptionInfo)) unInformeExcepcion = 'Exception during Lazy Initialization operation fVerifyOrInitialize_ExternalMethod %s\n' % str( theInitializationSpecification) unInformeExcepcion += 'exception class %s\n' % unaExceptionInfo[ 1].__class__.__name__ unInformeExcepcion += 'exception message %s\n\n' % str( unaExceptionInfo[1].args) unInformeExcepcion += unaExceptionFormattedTraceback unInforme['success'] = False unInforme['condition'] = 'exception' unInforme['exception'] = unInformeExcepcion if cLogExceptions: logging.getLogger('ModelDDvlPloneTool').error( unInformeExcepcion) return unInforme
def uninstall(self, reinstall=False): out = StringIO() # Adding a new catalog index catalog = getToolByName(self, "portal_catalog") if 'getAccess' in catalog.indexes(): catalog.manage_delIndex([ 'getAccess', ]) if 'getEditType' in catalog.indexes(): catalog.manage_delIndex([ 'getEditType', ]) # unhide tools in the search form portalProperties = getToolByName(self, 'portal_properties', None) if portalProperties is not None: siteProperties = getattr(portalProperties, 'site_properties', None) if siteProperties is not None and siteProperties.hasProperty( 'types_not_searched'): for tool in ['Annotations']: current = list( siteProperties.getProperty('types_not_searched')) if tool in current: current.remove(tool) siteProperties.manage_changeProperties( **{'types_not_searched': current}) # unhide tools portalProperties = getToolByName(self, 'portal_properties', None) if portalProperties is not None: navtreeProperties = getattr(portalProperties, 'navtree_properties', None) if navtreeProperties is not None and navtreeProperties.hasProperty( 'idsNotToList'): for toolname in ['portal_annotations']: current = list(navtreeProperties.getProperty('idsNotToList')) if toolname in current: current.remove(toolname) navtreeProperties.manage_changeProperties( **{'idsNotToList': current}) # try to call a workflow uninstall method # in 'InstallWorkflows.py' method 'uninstallWorkflows' try: uninstallWorkflows = ExternalMethod('temp', 'temp', PROJECTNAME + '.InstallWorkflows', 'uninstallWorkflows').__of__(self) except NotFound: uninstallWorkflows = None if uninstallWorkflows: print >> out, 'Workflow Uninstall:' res = uninstallWorkflows(self, out) print >> out, res or 'no output' else: print >> out, 'no workflow uninstall' # try to call a custom uninstall method # in 'AppInstall.py' method 'uninstall' try: uninstall = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'uninstall') except: uninstall = None if uninstall: print >> out, 'Custom Uninstall:' try: res = uninstall(self, reinstall) except TypeError: res = uninstall(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom uninstall' return out.getvalue()
def install(self, reinstall=False): """ External Method to install Marginalia """ out = StringIO() print >> out, "Installation log of %s:" % PROJECTNAME # If the config contains a list of dependencies, try to install # them. Add a list called DEPENDENCIES to your custom # AppConfig.py (imported by config.py) to use it. try: from Products.Marginalia.config import DEPENDENCIES except: DEPENDENCIES = [] portal = getToolByName(self, 'portal_url').getPortalObject() quickinstaller = portal.portal_quickinstaller for dependency in DEPENDENCIES: print >> out, "Installing dependency %s:" % dependency quickinstaller.installProduct(dependency) import transaction transaction.savepoint(optimistic=True) classes = listTypes(PROJECTNAME) installTypes(self, out, classes, PROJECTNAME) install_subskin(self, out, GLOBALS) # autoinstall tools portal = getToolByName(self, 'portal_url').getPortalObject() for t in ['Annotations']: try: portal.manage_addProduct[PROJECTNAME].manage_addTool(t) except BadRequest: # if an instance with the same name already exists this error will # be swallowed. Zope raises in an unelegant manner a 'Bad Request' error pass except: e = sys.exc_info() if e[0] != 'Bad Request': raise # Adding a new catalog index catalog = getToolByName(portal, "portal_catalog") if 'getAccess' not in catalog.indexes(): catalog.addIndex('getAccess', 'FieldIndex') catalog.addIndex('getEditType', 'FieldIndex') # hide tools in the search form portalProperties = getToolByName(self, 'portal_properties', None) if portalProperties is not None: siteProperties = getattr(portalProperties, 'site_properties', None) if siteProperties is not None and siteProperties.hasProperty( 'types_not_searched'): for tool in ['Annotations']: current = list( siteProperties.getProperty('types_not_searched')) if tool not in current: current.append(tool) siteProperties.manage_changeProperties( **{'types_not_searched': current}) # remove workflow for tools portal_workflow = getToolByName(self, 'portal_workflow') portal_workflow.setChainForPortalTypes(['Annotations'], '') portal_workflow.setChainForPortalTypes(['Annotation'], 'annotation_workflow') # uncatalog tools for toolname in ['portal_annotations']: try: portal[toolname].unindexObject() except: pass # hide tools in the navigation portalProperties = getToolByName(self, 'portal_properties', None) if portalProperties is not None: navtreeProperties = getattr(portalProperties, 'navtree_properties', None) if navtreeProperties is not None and navtreeProperties.hasProperty( 'idsNotToList'): for toolname in ['portal_annotations']: current = list(navtreeProperties.getProperty('idsNotToList')) if toolname not in current: current.append(toolname) navtreeProperties.manage_changeProperties( **{'idsNotToList': current}) # try to call a workflow install method # in 'InstallWorkflows.py' method 'installWorkflows' try: installWorkflows = ExternalMethod('temp', 'temp', PROJECTNAME + '.InstallWorkflows', 'installWorkflows').__of__(self) except NotFound: installWorkflows = None if installWorkflows: print >> out, 'Workflow Install:' res = installWorkflows(self, out) print >> out, res or 'no output' else: print >> out, 'no workflow install' # enable portal_factory for given types factory_tool = getToolByName(self, 'portal_factory') factory_types = [ "Annotation", "AnnotatableDocument", "Annotations", ] + factory_tool.getFactoryTypes().keys() factory_tool.manage_setPortalFactoryTypes(listOfTypeIds=factory_types) portal.portal_annotations.manage_permission("Add portal content", ["Member", "Anonymous"], 1) from Products.Marginalia.config import STYLESHEETS try: portal_css = getToolByName(portal, 'portal_css') for stylesheet in STYLESHEETS: try: portal_css.unregisterResource(stylesheet['id']) except: pass defaults = {'id': '', 'media': 'all', 'enabled': True} defaults.update(stylesheet) portal_css.registerStylesheet(**defaults) except: # No portal_css registry pass from Products.Marginalia.config import JAVASCRIPTS try: portal_javascripts = getToolByName(portal, 'portal_javascripts') for javascript in JAVASCRIPTS: try: portal_javascripts.unregisterResource(javascript['id']) except: pass defaults = {'id': ''} defaults.update(javascript) portal_javascripts.registerScript(**defaults) except: # No portal_javascripts registry pass # try to call a custom install method # in 'AppInstall.py' method 'install' try: install = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'install') except NotFound: install = None if install: print >> out, 'Custom Install:' try: res = install(self, reinstall) except TypeError: res = install(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom install' return out.getvalue()
def initialize(context): from Products.ExternalMethod.ExternalMethod import ExternalMethod em = ExternalMethod('temp', 'temp', 'externalmethod.somemodule', 'someExternalMethod') return em('external method')
def setupRotaFolderWorkflow(self, workflow): """Define the RotaFolderWorkflow workflow. """ workflow.setProperties(title='RotaFolderWorkflow') ##code-section create-workflow-setup-method-header #fill in your manual code here ##/code-section create-workflow-setup-method-header for s in ['published', 'new']: workflow.states.addState(s) for t in ['retract', 'publish']: workflow.transitions.addTransition(t) for v in ['review_history', 'comments', 'time', 'actor', 'action']: workflow.variables.addVariable(v) for l in []: if not l in workflow.worklists.objectValues(): workflow.worklists.addWorklist(l) ## Initial State workflow.states.setInitialState('new') ## States initialization stateDef = workflow.states['published'] stateDef.setProperties(title="""published""", description="""""", transitions=['retract']) stateDef = workflow.states['new'] stateDef.setProperties(title="""new""", description="""""", transitions=['publish']) ## Transitions initialization ## Creation of workflow scripts for wf_scriptname in ['retractRota']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject( wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.RotaFolderWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['retract'] transitionDef.setProperties( title="""retract""", new_state_id="""new""", trigger_type=1, script_name="""""", after_script_name="""retractRota""", actbox_name="""retract""", actbox_url="""""", actbox_category="""workflow""", props={}, ) ## Creation of workflow scripts for wf_scriptname in ['publishRota']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject( wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.RotaFolderWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['publish'] transitionDef.setProperties( title="""publish""", new_state_id="""published""", trigger_type=1, script_name="""""", after_script_name="""publishRota""", actbox_name="""publish""", actbox_url="""""", actbox_category="""workflow""", props={}, ) ## State Variable workflow.variables.setStateVar('review_state') ## Variables initialization variableDef = workflow.variables['review_history'] variableDef.setProperties( description="""Provides access to workflow history""", default_value="""""", default_expr="""state_change/getHistory""", for_catalog=0, for_status=0, update_always=0, props={'guard_permissions': 'Request review; Review portal content'}) variableDef = workflow.variables['comments'] variableDef.setProperties( description="""Comments about the last transition""", default_value="""""", default_expr="""python:state_change.kwargs.get('comment', '')""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['time'] variableDef.setProperties(description="""Time of the last transition""", default_value="""""", default_expr="""state_change/getDateTime""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['actor'] variableDef.setProperties( description="""The ID of the user who performed the last transition""", default_value="""""", default_expr="""user/getId""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['action'] variableDef.setProperties(description="""The last transition""", default_value="""""", default_expr="""transition/getId|nothing""", for_catalog=0, for_status=1, update_always=1, props=None)
def install(self, reinstall=False): """ External Method to install gvSIGbpd """ out = StringIO() print >> out, "Installation log of %s:" % PROJECTNAME # If the config contains a list of dependencies, try to install # them. Add a list called DEPENDENCIES to your custom # AppConfig.py (imported by config.py) to use it. try: from Products.gvSIGbpd.config import DEPENDENCIES except: DEPENDENCIES = [] portal = getToolByName(self, 'portal_url').getPortalObject() quickinstaller = portal.portal_quickinstaller for dependency in DEPENDENCIES: print >> out, "Installing dependency %s:" % dependency quickinstaller.installProduct(dependency) get_transaction().commit(1) classes = listTypes(PROJECTNAME) installTypes(self, out, classes, PROJECTNAME) install_subskin(self, out, GLOBALS) # try to call a workflow install method # in 'InstallWorkflows.py' method 'installWorkflows' try: installWorkflows = ExternalMethod('temp', 'temp', PROJECTNAME + '.InstallWorkflows', 'installWorkflows').__of__(self) except NotFound: installWorkflows = None if installWorkflows: print >> out, 'Workflow Install:' res = installWorkflows(self, out) print >> out, res or 'no output' else: print >> out, 'no workflow install' # configuration for Relations relations_tool = getToolByName(self, 'relations_library') xmlpath = os.path.join(package_home(GLOBALS), 'relations.xml') f = open(xmlpath) xml = f.read() f.close() # ########################### """ACV 20091124 Avoid lots of log entries from catalogs complaining about not found entries for instances affected by the importXML Was: relations_tool.importXML(xml) """ try: aDisableLevel = logging.getLogger('Zope.ZCatalog').manager.disable logging.getLogger( 'Zope.ZCatalog').manager.disable = cLoggingLevel_ERROR relations_tool.importXML(xml) finally: logging.getLogger('Zope.ZCatalog').manager.disable = aDisableLevel """ACV 20091124 """ # ########################### # enable portal_factory for given types factory_tool = getToolByName(self, 'portal_factory') factory_types = [ "BPDColeccionPoliticasDeNegocio", "BPDPlazo", "BPDSalida", "BPDPoliticaDeNegocio", "BPDFracasoFinal", "BPDEnvio", "BPDEscenario", "BPDExitoFinal", "BPDColeccionHerramientas", "BPDColeccionPasos", "BPDUnidadOrganizacional", "BPDColeccionProcesosDeNegocio", "BPDProcesoDeNegocioSimple", "BPDRecepcion", "BPDListaDePruebas", "BPDCasoDePrueba", "BPDPreCondicion", "BPDPrograma", "BPDPuntoExtension", "BPDColeccionCasosDePrueba", "BPDEntrada", "BPDColeccionSalidas", "BPDHerramienta", "BPDColeccionPerfiles", "BPDDecision", "BPDPasoSimple", "BPDCaracteristica", "BPDResolucionDatos", "BPDSubProceso", "BPDUsoArtefacto", "BPDExtensionProceso", "BPDPerfil", "BPDCondicion", "BPDReglaDeNegocio", "BPDArtefacto", "BPDPostCondicion", "BPDUsoCaracteristica", "BPDColeccionReglasDeNegocio", "BPDReferenciaCualificada", "BPDPasoGestorExcepciones", "BPDColeccionListasDePruebas", "BPDColeccionArtefactos", "BPDColeccionEntradas", "BPDDatosDePrueba", "BPDColeccionUnidadesOrganizacionales", "BPDOrganizacion", ] + factory_tool.getFactoryTypes().keys() factory_tool.manage_setPortalFactoryTypes(listOfTypeIds=factory_types) from Products.gvSIGbpd.config import STYLESHEETS try: portal_css = getToolByName(portal, 'portal_css') for stylesheet in STYLESHEETS: try: portal_css.unregisterResource(stylesheet['id']) except: pass defaults = {'id': '', 'media': 'all', 'enabled': True} defaults.update(stylesheet) portal_css.registerStylesheet(**defaults) except: # No portal_css registry pass from Products.gvSIGbpd.config import JAVASCRIPTS try: portal_javascripts = getToolByName(portal, 'portal_javascripts') for javascript in JAVASCRIPTS: try: portal_javascripts.unregisterResource(javascript['id']) except: pass defaults = {'id': ''} defaults.update(javascript) portal_javascripts.registerScript(**defaults) except: # No portal_javascripts registry pass # try to call a custom install method # in 'AppInstall.py' method 'install' try: install = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'install') except NotFound: install = None if install: print >> out, 'Custom Install:' try: res = install(self, reinstall) except TypeError: res = install(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom install' return out.getvalue()
def _createZODBClone(self): em = ExternalMethod(id=self.id) em.manage_edit(self.title, self.module, self.function, REQUEST=None) return em
def setupMemberAutoWorkflow(self, workflow): """Define the MemberAutoWorkflow workflow. """ workflow.setProperties(title='MemberAutoWorkflow') ##code-section create-workflow-setup-method-header #fill in your manual code here ##/code-section create-workflow-setup-method-header for s in ['public', 'private', 'disabled', 'new']: workflow.states.addState(s) for t in ['make_private', 'trigger', 'make_public', 'auto_register', 'enable_private', 'enable_public', 'disable']: workflow.transitions.addTransition(t) for v in ['review_history', 'comments', 'time', 'actor', 'action']: workflow.variables.addVariable(v) workflow.addManagedPermission('Copy or Move') workflow.addManagedPermission('Mail forgotten password') workflow.addManagedPermission('Manage users') workflow.addManagedPermission('Modify portal content') workflow.addManagedPermission('Set own password') workflow.addManagedPermission('Set own properties') workflow.addManagedPermission('View') workflow.addManagedPermission('membrane: Edit member id') workflow.addManagedPermission('membrane: Register member') workflow.addManagedPermission('Access contents information') for l in []: if not l in workflow.worklists.objectValues(): workflow.worklists.addWorklist(l) ## Initial State workflow.states.setInitialState('new') ## States initialization stateDef = workflow.states['public'] stateDef.setProperties(title="""Registered user, public profile""", description="""""", transitions=['make_private', 'disable']) stateDef.setPermission('Copy or Move', 0, ['Manager']) stateDef.setPermission('Mail forgotten password', 0, ['Anonymous', 'Member', 'Owner']) stateDef.setPermission('Manage users', 0, ['Manager']) stateDef.setPermission('Modify portal content', 0, ['Manager', 'Owner']) stateDef.setPermission('Set own password', 0, ['Manager', 'Owner']) stateDef.setPermission('Set own properties', 0, ['Manager', 'Owner']) stateDef.setPermission('View', 0, ['Anonymous', 'Authenticated', 'Manager', 'Member', 'Owner']) stateDef.setPermission('membrane: Edit member id', 0, ['Manager']) stateDef.setPermission('membrane: Register member', 0, ['Manager']) stateDef.setPermission('Access contents information', 0, ['Anonymous', 'Authenticated', 'Manager', 'Member', 'Owner']) stateDef = workflow.states['private'] stateDef.setProperties(title="""Registered user, private profile""", description="""""", transitions=['disable', 'make_public']) stateDef.setPermission('Copy or Move', 0, ['Manager']) stateDef.setPermission('Mail forgotten password', 0, ['Anonymous', 'Manager', 'Owner']) stateDef.setPermission('Manage users', 0, ['Manager']) stateDef.setPermission('Modify portal content', 0, ['Manager', 'Owner']) stateDef.setPermission('Set own password', 0, ['Manager', 'Owner']) stateDef.setPermission('Set own properties', 0, ['Manager', 'Owner']) stateDef.setPermission('View', 0, ['Manager', 'Owner']) stateDef.setPermission('membrane: Edit member id', 0, ['Manager']) stateDef.setPermission('membrane: Register member', 0, ['Manager']) stateDef.setPermission('Access contents information', 0, ['Manager', 'Owner']) stateDef = workflow.states['disabled'] stateDef.setProperties(title="""Disabled""", description="""""", transitions=['enable_private', 'enable_public']) stateDef.setPermission('Copy or Move', 0, ['Manager']) stateDef.setPermission('Mail forgotten password', 0, ['Manager']) stateDef.setPermission('Manage users', 0, ['Manager']) stateDef.setPermission('Modify portal content', 0, ['Manager']) stateDef.setPermission('Set own password', 0, ['Manager']) stateDef.setPermission('Set own properties', 0, ['Manager']) stateDef.setPermission('View', 0, ['Manager']) stateDef.setPermission('membrane: Edit member id', 0, ['Manager']) stateDef.setPermission('membrane: Register member', 0, ['Manager']) stateDef.setPermission('Access contents information', 0, ['Manager']) stateDef = workflow.states['new'] stateDef.setProperties(title="""Newly created member""", description="""""", transitions=['auto_register', 'trigger']) stateDef.setPermission('Copy or Move', 0, ['Manager']) stateDef.setPermission('Mail forgotten password', 0, ['Manager']) stateDef.setPermission('Manage users', 0, ['Manager']) stateDef.setPermission('Modify portal content', 0, ['Anonymous', 'Manager']) stateDef.setPermission('Set own password', 0, ['Anonymous', 'Manager']) stateDef.setPermission('Set own properties', 0, ['Anonymous', 'Manager']) stateDef.setPermission('View', 0, ['Anonymous', 'Manager']) stateDef.setPermission('membrane: Edit member id', 0, ['Anonymous', 'Manager']) stateDef.setPermission('membrane: Register member', 0, ['Anonymous', 'Manager']) stateDef.setPermission('Access contents information', 0, ['Anonymous', 'Manager']) ## Transitions initialization transitionDef = workflow.transitions['make_private'] transitionDef.setProperties(title="""Make member profile private""", new_state_id="""private""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""Make member profile private""", actbox_url="""""", actbox_category="""workflow""", props={'guard_roles': 'Owner; Manager'}, ) transitionDef = workflow.transitions['trigger'] transitionDef.setProperties(title="""Trigger automatic transitions""", new_state_id="""new""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""Trigger automatic transitions""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['make_public'] transitionDef.setProperties(title="""Make member profile public""", new_state_id="""public""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""Make member profile public""", actbox_url="""""", actbox_category="""workflow""", props={'guard_roles': 'Owner; Manager'}, ) ## Creation of workflow scripts for wf_scriptname in ['register']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject(wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.MemberAutoWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['auto_register'] transitionDef.setProperties(title="""Automatically approve member""", new_state_id="""public""", trigger_type=0, script_name="""register""", after_script_name="""""", actbox_name="""Automatically approve member""", actbox_url="""""", actbox_category="""workflow""", props={'guard_expr': 'here/isValid', 'guard_permissions': 'membrane: Register member'}, ) ## Creation of workflow scripts for wf_scriptname in ['enable']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject(wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.MemberAutoWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['enable_private'] transitionDef.setProperties(title="""Re-enable member""", new_state_id="""private""", trigger_type=1, script_name="""""", after_script_name="""enable""", actbox_name="""Re-enable member""", actbox_url="""""", actbox_category="""workflow""", props={'guard_expr': "python:getattr(here,'old_state',None) == 'private'", 'guard_permissions': 'Manage users'}, ) ## Creation of workflow scripts for wf_scriptname in ['enable']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject(wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.MemberAutoWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['enable_public'] transitionDef.setProperties(title="""Re-enable member""", new_state_id="""public""", trigger_type=1, script_name="""""", after_script_name="""enable""", actbox_name="""Re-enable member""", actbox_url="""""", actbox_category="""workflow""", props={'guard_expr': "python:getattr(here,'old_state',None) == 'public'", 'guard_permissions': 'Manage users'}, ) ## Creation of workflow scripts for wf_scriptname in ['disable']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject(wf_scriptname, ExternalMethod(wf_scriptname, wf_scriptname, productname + '.MemberAutoWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['disable'] transitionDef.setProperties(title="""Disable""", new_state_id="""disabled""", trigger_type=1, script_name="""disable""", after_script_name="""""", actbox_name="""Disable""", actbox_url="""""", actbox_category="""workflow""", props={'guard_permissions': 'Manage users'}, ) ## State Variable workflow.variables.setStateVar('review_state') ## Variables initialization variableDef = workflow.variables['review_history'] variableDef.setProperties(description="""Provides access to workflow history""", default_value="""""", default_expr="""state_change/getHistory""", for_catalog=0, for_status=0, update_always=0, props={'guard_permissions': 'Request review; Review portal content'}) variableDef = workflow.variables['comments'] variableDef.setProperties(description="""Comments about the last transition""", default_value="""""", default_expr="""python:state_change.kwargs.get('comment', '')""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['time'] variableDef.setProperties(description="""Time of the last transition""", default_value="""""", default_expr="""state_change/getDateTime""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['actor'] variableDef.setProperties(description="""The ID of the user who performed the last transition""", default_value="""""", default_expr="""user/getId""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['action'] variableDef.setProperties(description="""The last transition""", default_value="""""", default_expr="""transition/getId|nothing""", for_catalog=0, for_status=1, update_always=1, props=None)
def install(self, reinstall=False): """ External Method to install BungeniSkinTZ """ out = StringIO() print >> out, "Installation log of %s:" % PROJECTNAME # If the config contains a list of dependencies, try to install # them. Add a list called DEPENDENCIES to your custom # AppConfig.py (imported by config.py) to use it. try: from Products.BungeniSkinTZ.config import DEPENDENCIES except: DEPENDENCIES = [] portal = getToolByName(self, 'portal_url').getPortalObject() quickinstaller = portal.portal_quickinstaller for dependency in DEPENDENCIES: print >> out, "Installing dependency %s:" % dependency quickinstaller.installProduct(dependency) get_transaction().commit(1) classes = listTypes(PROJECTNAME) installTypes(self, out, classes, PROJECTNAME) install_subskin(self, out, GLOBALS) portal = getToolByName(self, 'portal_url').getPortalObject() for slot in ['here/theme_portlet/macros/portlet']: if slot not in portal.left_slots: portal.left_slots = list(portal.left_slots) + [slot] for slot in ['here/sections_portlet/macros/portlet']: if slot not in portal.right_slots: portal.right_slots = list(portal.right_slots) + [slot] # try to call a workflow install method # in 'InstallWorkflows.py' method 'installWorkflows' try: installWorkflows = ExternalMethod('temp', 'temp', PROJECTNAME + '.InstallWorkflows', 'installWorkflows').__of__(self) except NotFound: installWorkflows = None if installWorkflows: print >> out, 'Workflow Install:' res = installWorkflows(self, out) print >> out, res or 'no output' else: print >> out, 'no workflow install' from Products.BungeniSkinTZ.config import STYLESHEETS try: portal_css = getToolByName(portal, 'portal_css') for stylesheet in STYLESHEETS: try: portal_css.unregisterResource(stylesheet['id']) except: pass defaults = {'id': '', 'media': 'all', 'enabled': True} defaults.update(stylesheet) portal_css.registerStylesheet(**defaults) except: # No portal_css registry pass from Products.BungeniSkinTZ.config import JAVASCRIPTS try: portal_javascripts = getToolByName(portal, 'portal_javascripts') for javascript in JAVASCRIPTS: try: portal_javascripts.unregisterResource(javascript['id']) except: pass defaults = {'id': ''} defaults.update(javascript) portal_javascripts.registerScript(**defaults) except: # No portal_javascripts registry pass # try to call a custom install method # in 'AppInstall.py' method 'install' try: install = ExternalMethod('temp', 'temp', PROJECTNAME + '.AppInstall', 'install') except NotFound: install = None if install: print >> out, 'Custom Install:' try: res = install(self, reinstall) except TypeError: res = install(self) if res: print >> out, res else: print >> out, 'no output' else: print >> out, 'no custom install' return out.getvalue()
def setupWestminsterBillWorkflow(self, workflow): """Define the WestminsterBillWorkflow workflow. """ workflow.setProperties(title='WestminsterBillWorkflow') ##code-section create-workflow-setup-method-header #fill in your manual code here ##/code-section create-workflow-setup-method-header for s in [ 'PresentedToParliament', 'CommittedToCommittee', 'DebateBillTitle', 'DebateBill', 'ReportOnBillProgress', 'ThirdReadingDone', 'Approved', 'Rejected', 'SubmittedToAttorneyGeneral', 'SignedIntoLaw', 'Withdrawn', 'presented' ]: workflow.states.addState(s) for t in [ 'withdraw', 'recommit', 'submit', 'third_reading', 'second_reading', 'request_report', 'first_reading', 'reject', 'commit', 'sign', 'approve', 'reintroduce' ]: workflow.transitions.addTransition(t) for v in ['review_history', 'comments', 'time', 'actor', 'action']: workflow.variables.addVariable(v) for l in []: if not l in workflow.worklists.objectValues(): workflow.worklists.addWorklist(l) ## Initial State workflow.states.setInitialState('presented') ## States initialization stateDef = workflow.states['PresentedToParliament'] stateDef.setProperties(title="""PresentedToParliament""", description="""""", transitions=['commit']) stateDef = workflow.states['CommittedToCommittee'] stateDef.setProperties(title="""CommittedToCommittee""", description="""""", transitions=['second_reading', 'withdraw']) stateDef = workflow.states['DebateBillTitle'] stateDef.setProperties( title="""DebateBillTitle""", description="""""", transitions=['commit', 'commit', 'reject', 'withdraw']) stateDef = workflow.states['DebateBill'] stateDef.setProperties(title="""DebateBill""", description="""""", transitions=['request_report', 'withdraw']) stateDef = workflow.states['ReportOnBillProgress'] stateDef.setProperties( title="""ReportOnBillProgress""", description="""""", transitions=['recommit', 'third_reading', 'withdraw']) stateDef = workflow.states['ThirdReadingDone'] stateDef.setProperties(title="""ThirdReadingDone""", description="""""", transitions=['approve', 'reject', 'withdraw']) stateDef = workflow.states['Approved'] stateDef.setProperties(title="""Approved""", description="""""", transitions=['submit']) stateDef = workflow.states['Rejected'] stateDef.setProperties(title="""Rejected""", description="""""", transitions=['reintroduce']) stateDef = workflow.states['SubmittedToAttorneyGeneral'] stateDef.setProperties(title="""SubmittedToAttorneyGeneral""", description="""""", transitions=['sign']) stateDef = workflow.states['SignedIntoLaw'] stateDef.setProperties(title="""SignedIntoLaw""", description="""""", transitions=[]) stateDef = workflow.states['Withdrawn'] stateDef.setProperties(title="""Withdrawn""", description="""""", transitions=[]) stateDef = workflow.states['presented'] stateDef.setProperties(title="""presented""", description="""""", transitions=['first_reading']) ## Transitions initialization transitionDef = workflow.transitions['withdraw'] transitionDef.setProperties( title="""withdraw""", new_state_id="""Withdrawn""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""withdraw""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['recommit'] transitionDef.setProperties( title="""recommit""", new_state_id="""DebateBill""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""recommit""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['submit'] transitionDef.setProperties( title="""submit""", new_state_id="""SubmittedToAttorneyGeneral""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""submit""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['third_reading'] transitionDef.setProperties( title="""third_reading""", new_state_id="""ThirdReadingDone""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""third_reading""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['second_reading'] transitionDef.setProperties( title="""second_reading""", new_state_id="""DebateBillTitle""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""second_reading""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['request_report'] transitionDef.setProperties( title="""request_report""", new_state_id="""ReportOnBillProgress""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""request_report""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['first_reading'] transitionDef.setProperties( title="""first_reading""", new_state_id="""PresentedToParliament""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""first_reading""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['reject'] transitionDef.setProperties( title="""reject""", new_state_id="""Rejected""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""reject""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['commit'] transitionDef.setProperties( title="""commit""", new_state_id="""CommittedToCommittee""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""commit""", actbox_url="""""", actbox_category="""workflow""", props={}, ) ## Creation of workflow scripts for wf_scriptname in ['publishChildren']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject( wf_scriptname, ExternalMethod( wf_scriptname, wf_scriptname, productname + '.WestminsterBillWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['sign'] transitionDef.setProperties( title="""sign""", new_state_id="""SignedIntoLaw""", trigger_type=1, script_name="""""", after_script_name="""publishChildren""", actbox_name="""sign""", actbox_url="""""", actbox_category="""workflow""", props={}, ) ## Creation of workflow scripts for wf_scriptname in ['approveChildren']: if not wf_scriptname in workflow.scripts.objectIds(): workflow.scripts._setObject( wf_scriptname, ExternalMethod( wf_scriptname, wf_scriptname, productname + '.WestminsterBillWorkflow_scripts', wf_scriptname)) transitionDef = workflow.transitions['approve'] transitionDef.setProperties( title="""approve""", new_state_id="""Approved""", trigger_type=1, script_name="""""", after_script_name="""approveChildren""", actbox_name="""approve""", actbox_url="""""", actbox_category="""workflow""", props={}, ) transitionDef = workflow.transitions['reintroduce'] transitionDef.setProperties( title="""reintroduce""", new_state_id="""presented""", trigger_type=1, script_name="""""", after_script_name="""""", actbox_name="""reintroduce""", actbox_url="""""", actbox_category="""workflow""", props={}, ) ## State Variable workflow.variables.setStateVar('review_state') ## Variables initialization variableDef = workflow.variables['review_history'] variableDef.setProperties( description="""Provides access to workflow history""", default_value="""""", default_expr="""state_change/getHistory""", for_catalog=0, for_status=0, update_always=0, props={'guard_permissions': 'Request review; Review portal content'}) variableDef = workflow.variables['comments'] variableDef.setProperties( description="""Comments about the last transition""", default_value="""""", default_expr="""python:state_change.kwargs.get('comment', '')""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['time'] variableDef.setProperties(description="""Time of the last transition""", default_value="""""", default_expr="""state_change/getDateTime""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['actor'] variableDef.setProperties( description="""The ID of the user who performed the last transition""", default_value="""""", default_expr="""user/getId""", for_catalog=0, for_status=1, update_always=1, props=None) variableDef = workflow.variables['action'] variableDef.setProperties(description="""The last transition""", default_value="""""", default_expr="""transition/getId|nothing""", for_catalog=0, for_status=1, update_always=1, props=None)