# -*- 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(( StringField('tableWidth', accessor = 'getTableWidth', vocabulary = 'getNumbers', default = '4', widget = SelectionWidget( format = 'select', label = 'Table width', label_msgid='label_table_width', description = 'How many flowers are in table by horizontally', description_msgid = 'desc_table_width', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), StringField('tableHeight', accessor = 'getTableHeight', vocabulary = 'getNumbers', default = '4', widget = SelectionWidget( format = 'select', label = 'Table height', label_msgid='label_table_height', description = 'How many flowers are in table by vertically', description_msgid = 'desc_table_height', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), )) schema.delField('multipleChoice') schema.delField('answerRequired') schema.delField('time') #schema.moveField('time', pos='bottom') class FlowerFunctions: """ Functions that are needed to run flower task in test view""" def saveFlowerTask(self,REQUEST): """ saving data """ answer=REQUEST.get('current_array') current = self.getCurrentSheet() current_id = current.id if answer != None and answer != "": answer = answer.split(",") rc = current.getRightChoice() if int(answer[0])==rc[0] and int(answer[1])==rc[1]: rca = 2 else: rca = 1 table = current.getTable() answers = {'choice':rca,'clicked':str(self.arrayCordinatesAsNr(answer, table))} 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 FlowerTask(BaseTask): """ Flower task""" meta_type = "FlowerTask" archetype_name = "Flower 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}/flower_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}/flower_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.flowerTable = [] self.rightChoice = [0,0] def createTable(self): """returns table""" table = [] rows = int(self.getTableHeight()) cols = int(self.getTableWidth()) for row in range(0,rows): table.append([]) for col in range(0,cols): table[row].append("ml") self.flowerTable = table self.rightChoice = [0,0] self.p_changed = 1 def getTable(self): """returns table""" if not hasattr(self, 'flowerTable'): self.flowerTable = [] if self.flowerTable == []: self.createTable() if int(self.getTableHeight()) != len(self.flowerTable) and len(self.flowerTable) > 0: if int(self.getTableWidth()) != len(self.flowerTable[0]): self.createTable() return self.flowerTable def getRightChoice(self): """returns r choice""" if not hasattr(self, 'rightChoice'): self.rightChoice = [0,0] self.p_changed = 1 return self.rightChoice def setRightChoice(self, row, col): """sets r choice""" self.rightChoice = [int(row),int(col)] self.p_changed = 1 def saveFlowerTable(self,row,col,data): """saves table, like they saved Rayan (not Angelos)""" self.flowerTable[int(row)][int(col)] = data self.p_changed = 1 def getNumbers(self): """return numbers for table length and width""" nrs = [] for nr in range(4,11, 1): nrs.append(nr) return nrs def objectSpecData(self, key, val): """objects spec data""" if key == "rightChoice": import pickle self.rightChoice = pickle.loads(val) self.p_changed = 1 elif key == "table": import pickle self.flowerTable = pickle.loads(val) self.p_changed = 1 def getObjectsXML(self, files): """empty data""" import pickle rc = pickle.dumps(self.getRightChoice()) gt = pickle.dumps(self.getTable()) xml = self.getBaseXML() xml += '\n' xml += '\n' xml += '\n' xml += '
\n' xml += '' return [xml, files] registerType(FlowerTask, PROJECT_NAME)