""" Answer Container """ __version__ = "$Revision$"[11:-2] import Globals from Globals import Acquisition, Persistent from Acquisition import aq_base, aq_inner, aq_parent, Explicit from AccessControl import ClassSecurityInfo from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from zope.interface import implements from common import commons from Permissions import * from AnswerSession import AnswerSession from random import choice import string from interfaces import IAnswerContainer class AnswerContainer(BTreeFolder2, Persistent, Explicit, commons): """ answer container """ meta_type = 'Answer Container' security = ClassSecurityInfo() security.declareObjectPublic() implements(IAnswerContainer) manage_options = BTreeFolder2.manage_options def __init__(self, id, token, test_id, group_id): self.id=id self._secret_token = token self.test_id = test_id self.group_id = group_id BTreeFolder2.__init__(self, self.id) def setupSessionFolder(self, test_id): sess = None for x in self.objectValues('Answer Session'): #if x.isCompleted(): continue # having only one session sess = x if sess is None: chars = string.letters + string.digits sess_id = '' for i in range(20): sess_id += choice(chars) sess_id = 'session_' + sess_id a = AnswerSession(sess_id, test_id) t = self.getTestById(test_id) testQuestions = t.getQuestions() # ['question_123',...] a.setTestQuestions(testQuestions) self._setObject(sess_id, a) sess = getattr(self, sess_id) return sess def getSessions(self): return self.objectValues('Answer Session') def checkToken(self, REQUEST): if REQUEST.get('token') == self._secret_token: return True return False def getTestId(self): """ """ return self.test_id def getGroupId(self): """ """ return getattr(self, 'group_id', '') def getAnswerToken(self): """ """ return self._secret_token def checkDoneOrNot(self): """ """ sessions = self.getSessions() if str(sessions) == '[]': return False else: return sessions[0].getDoneOrNot() Globals.InitializeClass(AnswerContainer) #EOF