# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import BooleanField, ImageField, StringField from Products.Archetypes.public import BooleanWidget, ImageWidget, StringWidget, SelectionWidget from Products.Archetypes.public import BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME from BaseTest import BaseTask schema = BaseTask.schema.copy() + Schema(( )) schema.delField('multipleChoice') schema.delField('answerRequired') schema.delField('time') #schema.moveField('time', pos='bottom') class TMTFunctions: """ Functions that are needed to run TMT task in test view""" def getTmtElements(self): """returns all data to js as array""" return self.getCurrentSheet().getTmtElements() def saveTmtTaskAnswers(self,REQUEST): """ saving data """ raw_answer=REQUEST.get('tmt_task_answers') load_time=REQUEST.get('tmt_load_time') task_time=REQUEST.get('tmt_task_time') current = self.getCurrentSheet() current_id = current.id if raw_answer != None and raw_answer != "": answer = raw_answer.split(",") fault = 0 for ans in answer: if int(ans) == 1: fault = fault + 1 answers = {'choice':fault,'data':raw_answer,'start_time':load_time,'finish_time':task_time} print "datasse l2hevad "+str(current_id)+" ja "+str(answers) self.setDataToDatabase(current_id,answers) self.setCurrentPage() else: return self.REQUEST.RESPONSE.redirect(self.absolute_url()+'?error=true') self.submitToTheNextPage(REQUEST) class TMTTask(BaseTask): """ TMT Task""" meta_type = "TMTTask" archetype_name = "TMT Task" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/tmt_task', 'permissions': ('View',), }, { 'id':'edit', 'name':'Configuration', 'action':'string:${object_url}/base_edit', 'permissions': ('Modify portal content',), }, { 'id':'create', 'name':'Create', 'action':'string:${object_url}/tmt_task_edit', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'name':'Info', 'action':'string:${object_url}/base_metadata', 'permissions': ('Modify portal content',), } ) def __init__(self, id): self.id = id self.myTmtElements = [] def getTmtElements(self): """returns table""" if not hasattr(self, 'myTmtElements'): self.myTmtElements = [] return self.myTmtElements def getTmtElementsXML(self): """tmt elements as xml""" txml = '' for el in self.getTmtElements(): txml += '\n' txml += ''+el[0]+'\n' txml += ''+el[1]+'\n' txml += ''+el[2]+'\n' txml += ''+el[3]+'\n' txml +='\n' return txml def saveTmtElements(self, data): """save data here""" data_array = [] data_raw = data.split(",") for t in range(0,len(data_raw),4): data_array.append([data_raw[t],data_raw[t+1],data_raw[t+2],data_raw[t+3]]) self.myTmtElements = data_array #print self.myTmtElements self.p_changed = 1 def objectSpecData(self, key, val): """objects spec data""" if key == "elements": import pickle self.myTmtElements = pickle.loads(val) self.p_changed = 1 def getObjectsXML(self, files): """special xml""" import pickle els = pickle.dumps(self.getTmtElements()) xml = self.getBaseXML() xml += '\n' xml += '\n' xml += '' return [xml, files] registerType(TMTTask, PROJECT_NAME)