# -*- coding: utf-8 # $Id: Kalender.py 316 2005-09-03 10:34:35Z vahur $ # # Copyright 2001, 2002 by IVA Team and contributors # # This file is part of IVA. # # IVA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # IVA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with IVA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA __version__ = "$Revision: 316 $"[11:-2] import AccessControl import OFS, Globals from OFS import SimpleItem import types import time from TraversableWrapper import Traversable from Globals import Persistent from AccessControl import ClassSecurityInfo from Cruft import Cruft from common import add_dtml, translate, perm_edit, perm_view from Products.ZCatalog.CatalogAwareness import CatalogAware from input_checks import strip_tags from DateTime import DateTime import calendar calendar.setfirstweekday(0) class Crossword( OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager, Traversable, Cruft, CatalogAware ): """ One single crossword in CrosswordsDirectory """ meta_type = 'Crossword' security = ClassSecurityInfo() security.declareObjectPublic() def __init__(self, nimi): "Alustus" self.nimi=nimi self.data=[] self.solution_col=0 self.questions=[] security.declareProtected(perm_view,'getName') def getName(self): """ Event name """ return self.nimi security.declareProtected(perm_view,'setName') def setName(self, nimi): """ Event name """ self.nimi=nimi return "Nimi muudetud. Uus nimi: "+self.nimi security.declareProtected(perm_view,'showList') def showList(self, x, y, t=[]): """ Display two-dimensional list """ seq=[] x=int(x) y=int(y) # make two-dimensional list 'seq' out of one-dimensional 't' for i in range(y): seq.append(t[i*x:(i+1)*x]) return seq security.declareProtected(perm_view,'showList') def setCwData(self, x, y, solution_col, t=[], q=[]): """ Display two-dimensional list """ seq=[] x=int(x) y=int(y) # make two-dimensional list 'seq' out of one-dimensional 't' for i in range(y): seq.append(t[i*x:(i+1)*x]) self.data=seq self.solution_col=int(solution_col) self.questions=q return seq security.declareProtected(perm_view,'showList') def testSolution(self, t=[]): """ Tell, if the answer is right or wrong """ # convert data into list of words answerSeq=[] testSeq=[] for answer in self.data: answerWord="" testWord="" for answerLetter in answer: if answerLetter!="": answerWord=answerWord+answerLetter # pop the first item from list 't' testWord=testWord+t[0] t[0:1]=[] answerSeq.append(answerWord) testSeq.append(testWord) # compare the submitted answer and the correct answer summary=[] totalSummary="Kogu ristsõna on õieti lahendatud." for i in range(len(answerSeq)): if answerSeq[i]==testSeq[i]: summary.append("Vastus "+str(i+1)+" on korrektne.") else: summary.append("Vastus "+str(i+1)+" on vale.") totalSummary="Kokkuvõttes on lahendus vale. Haa!" return [summary,totalSummary] def getQuestion(self, qnr): "kysimuse saamine" return self.questions[qnr] def isSolution(self, cnr): "kas on lahendus" return cnr==self.solution_col def getLetter(self, row, col): "tähe saamine" return self.data[row][col] def getRowCount(self): "Ridade arv" return len(self.data) def getColumnCount(self): "Veergude arv" return len(self.data[0]) class CrosswordsDirectory( OFS.Folder.Folder, OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager, Traversable, Cruft ): """ some functions here do some misc stuff. find closest event folder and call'em out """ security = ClassSecurityInfo() security.declareObjectPublic() cwNr=0 def __init__(self): """ init, set id """ self.id = 'CrosswordsDirectory' security.declarePrivate('kysiUusNr') def kysiUusNr(self): self.cwNr=self.cwNr+1 while hasattr(self.aq_self, 'cw'+str(self.cwNr)): self.cwNr=self.cwNr+1 return self.cwNr def addCrossword(self, nimi): "add new crossword" cw=Crossword(nimi) cw.id="cw"+str(self.kysiUusNr()) self._setObject(cw.id, cw) return "lisatud" security.declareProtected(perm_edit,'muutmisLeht') def muutmisLeht(self, REQUEST,userLocation=''): """ Change event. If we're here then we add new event """ import YlTest from YlTest import LahendusLuba from input_checks import is_valid_title name = REQUEST.get('nimi', '') abi=LahendusLuba() #vaid ajamenüü tarbeks if not is_valid_title(name): return self.message_dialog( message='Invalid title', action='changeEvent?userLocation=%s&nimi=%s&pikk=%s&algus=%s&lopp=%s' % (userLocation, name, pikk, algus, lopp) ) if not pikk: return self.message_dialog( message='No content', action='changeEvent?userLocation=%s&nimi=%s&pikk=%s&algus=%s&lopp=%s' % (userLocation, name, pikk, algus, lopp) ) nr='event'+str(self.kysiUusNr()) k=Crossword(nr) abi=LahendusLuba() #vaid ajamenüü tarbeks k.nimi=strip_tags(name) if not k.nimi: k.nimi = nr k.id=nr self._setObject(nr, k) return REQUEST.RESPONSE.redirect('index_html?userLocation='+userLocation) # EOF