# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import TextField, ReferenceField, BooleanField from Products.Archetypes.public import TextAreaWidget, ReferenceWidget, BooleanWidget from Products.Archetypes.public import BaseContent, OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from BaseFunctions import BaseFunctions from HedgehogTask import HedgehogFunctions from FlowerTask import FlowerFunctions from TMTTask import TMTFunctions from DragTask import DragFunctions from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME from persistent.mapping import PersistentMapping schema_user_folder = BaseSchema + Schema(( )) class UserFolder(OrderedBaseFolder, BaseFunctions, HedgehogFunctions, FlowerFunctions, TMTFunctions, DragFunctions): """ Psyhvel base user data object""" meta_type = "UserFolder" archetype_name = "UserFolder" global_allow = 0 exclude_from_nav = True filter_content_types = True security = ClassSecurityInfo() def setTestData(self, test_id): val = PersistentMapping() val['database'] = {} val['currentPage'] = 0 val['locked'] = False val['isStimulus'] = True val['elementXY'] = {} setattr(self, test_id, val) def getIsStimulus(self, test_id): """set view""" if not hasattr(self, test_id): self.setTestData(test_id) return getattr(self, test_id)['isStimulus'] def stripId(self, id): """strips id""" return id.replace(".","").replace("-","") def getDataFromDatabase(self, test_id): """returns data from database""" if not hasattr(self, test_id): self.setTestData(test_id) return getattr(self, test_id)['database'] def setDataToDatabase(self, test_id, sheet, answer): """set data to database kay as member id""" if not hasattr(self, test_id): self.setTestData(test_id) getattr(self, test_id)['database'][sheet] = answer self._p_changed = 1 def getCurrentPage(self, test_id): """returns current page""" if not hasattr(self, test_id): self.setTestData(test_id) return getattr(self, test_id)['currentPage'] def setCurrentPage(self, test_id): """set data to database kay as member id""" getattr(self, test_id)['currentPage'] = getattr(self, test_id)['currentPage'] + 1 self._p_changed = 1 def isLocked(self, test_id): """returns info""" if not hasattr(self, test_id): self.setTestData(test_id) return getattr(self, test_id)['locked'] def removeLocked(self, test_id): """unlock""" if hasattr(self, test_id): getattr(self, test_id)['locked'] = False getattr(self, test_id)['currentPage'] = 0 self._p_changed = 1 return True return False def setLocked(self, test_id): """lock""" getattr(self, test_id)['locked'] = True self._p_changed = 1 def getChoiceFromDatabase(self, test_id, exercise, choice): """return choice""" data = self.getDataFromDatabase(test_id) if data.has_key(exercise): if data[exercise].has_key(choice): return data[exercise][choice] return 0 registerType(UserFolder, PROJECT_NAME)