# -*- coding: utf-8 # Copyright 2005 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget, RichWidget from AccessControl import ClassSecurityInfo from Products.Archetypes.public import registerType from Products.Krihvel.BaseTask import BaseTask, BaseAnswer from Products.Krihvel.config import PROJECT_NAME schema = BaseSchema + BaseTask.schema + Schema(( LinesField('ExerciseType', accessor="getExerciseType", isMetadata=1, vocabulary=['No','Yes'], widget=SelectionWidget( format="radio", label="I want to mark it", label_msgid='label_extype', description="NO if it is just for exerciseing, YES when you want mark it", description_msgid='desc_extype', i18n_domain="krihvel"), ), )) class Pairs(BaseTask): """ Pairs module. """ meta_type = "Pairs" archetype_name = "Pairs" allowed_content_types = ('Image',) global_allow = 0 security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/pairs_view', 'permissions': ('View',), }, ) def _renameAfterCreation(self, check_auto_id=False): pass def __init__(self, id): self.id = id self.images = [] self.gameRows = 5 #default game has 5 rows of pictures def addRow(self, REQUEST): """ add image row to game """ image_1_text = REQUEST.get('picture_1_text') image_2_text = REQUEST.get('picture_2_text') image_1_url = REQUEST.get('picture_1_url') image_2_url = REQUEST.get('picture_2_url') user = str(REQUEST.AUTHENTICATED_USER) homefolder = self.portal_membership.getHomeFolder(user) if image_1_url != '0': col1 = {'type':'image','value':image_1_url} elif image_1_text != '': col1 = {'type':'text','value':image_1_text} else: col1 = 'None' if image_2_url != '0': col2 = {'type':'image','value':image_2_url} elif image_2_text != '': col2 = {'type':'text','value':image_2_text} else: col2 = 'None' self.images.append({'col1':col1,'col2':col2}) self._p_changed = 1 def delRow(self,REQUEST): """ delete image row from game """ counter = 1 newImages = [] for image in self.images: if REQUEST.get('picture_row_'+str(counter)) != 'on': newImages.append(image) counter = counter + 1 self.images = newImages self._p_changed = 1 def getMaxGameRows(self): """gets rows""" return len(self.images) def getGameRows(self): """gets rows""" return self.gameRows def setGameRows(self,REQUEST): """sets rows""" self.gameRows = REQUEST.get("set_game_rows") self._p_changed = 1 def getGameData(self): """aaa""" return self.images def getPicArrayForGame(self, col): """aaa""" array = "" for item in self.images: array=array+"#"+item[col]['value'] return array[1:] def getTypeArrayForGame(self, col): """aaa""" array = "" for item in self.images: array=array+"#"+item[col]['type'] return array[1:] registerType(Pairs, PROJECT_NAME)