# -*- coding: utf-8 # Copyright 2005 by Vahur Rebas from Products.Archetypes.public import BaseFolderSchema, Schema from Products.Archetypes.public import BaseFolder from Products.Archetypes.public import registerType from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo from config import PROJECT_NAME schema = BaseFolderSchema rome_to_arab = ["","I","II","III","IV","V","VI"] class ProgressUserFolder(BaseFolder): """ This folder holds all progress interviews. """ meta_type = "ProgressUserFolder" archetype_name = "ProgressUserFolder" allowed_content_types = ("PhaseI", "PhaseII", "PhaseIII", "PhaseIV", "PhaseV", "PhaseVI") filter_content_types = 1 global_allow = 0 exclude_from_nav = True security = ClassSecurityInfo() schema = schema actions = ( { 'id': 'view', 'name': 'View', 'action': 'string:${object_url}/prog_class_view', 'permissions': ('Edit phase content',), }, { 'id': 'folderlisting', 'name': 'Folder Listing', 'action': 'string:${object_url}/prog_class_view', 'permissions': ('Edit phase content',), }, ) def checkPhaseObjects(self): """ checks if phase objects are created else they are created """ for x in ("PhaseI", "PhaseII", "PhaseIII", "PhaseIV", "PhaseV", "PhaseVI"): y = getattr(self, x, None) if not y: typestool = getToolByName(self, 'portal_types') puf_type = getattr(typestool, x, None) if not puf_type: continue puf_type.allowed_content_types = (x,) id = self.invokeFactory(x, x, title=x) puf_type.allowed_content_types = [] return 1 def getNextStep(self, uname): """ returns next unfilled phase object for user. First if all phases are complete. self if objects are not found """ self.checkPhaseObjects() for x in range(1,7): p = self.getPhase(x) if not p.getPhaseStatus(): return p return self def getPhase(self, phase): """ returns phase object for student. if errors occur, self is returned """ # get phase object. obj_name = "Phase"+rome_to_arab[phase] obj = getattr(self, obj_name, self) return obj registerType(ProgressUserFolder, PROJECT_NAME)