# -*- coding: utf-8 # $Id: Kodutoo.py 327 2005-09-06 21:40:47Z 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: 327 $"[11:-2] import AccessControl import OFS, Globals from OFS import SimpleItem import types import time import re from TraversableWrapper import Traversable from Globals import Persistent, PersistentMapping from AccessControl import ClassSecurityInfo from AccessControl import allow_module, allow_class, allow_type from Cruft import Cruft from common import add_dtml, translate, perm_edit, perm_view class Kodutoo( OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager, Traversable, Cruft ): meta_type = 'Assignment' security = ClassSecurityInfo() """ Assignment object """ def __init__(self, REQUEST, tyyp, kirjeldus="", normPunkte=0,kalendriID=None): """ init """ self.tyyp=int(tyyp) self.kirjeldus=kirjeldus self.pealkiri = "" #self.loppaeg=None #Esituspiiri pole määratud. no deadline # now we always have deadline self.loppaeg = time.time() self.normPunkte=normPunkte self.kalendriID=None #kalendrisyndmuse id. event id. self.ylesanded=None #list of exercises. for Dist. set of Exerc. only self.hwID = None #assignment id. for peer review only. self.testiID = None #quiz id. for quiz type assignment only. self.reviewMapping = PersistentMapping() self.lockingFolder = None def manage_afterAdd(self, item, container): container.grades[self.id] = {} def lockFolder(self): """ lock folder """ return getattr(self, 'lockingFolder', 0) def getAssignmentID(self): return getattr(self, 'hwID', "") security.declareProtected(perm_edit, 'setAssignmentID') def setAssignmentID(self,hwID): self.hwID = hwID def get_id(self): return self.id def getDeadline(self, REQUEST): return time.strftime(translate(self,'timestamp_format',default="%H:%M %Y-%m-%d",target=self.giveLanguage(REQUEST)), time.localtime(self.loppaeg)) def getGrades(self,user,detail='', individual=1): """ doc string """ if self.tyyp == 2 and not individual: user = 'subgroup_'+user gradesObj = getattr(self, 'grades') if not gradesObj.has_key(self.get_id()): gradesObj[self.get_id()] = {} grades = gradesObj[self.get_id()] if not grades.has_key(user): value = float(0) self.setUserPoints(self.get_id(), user, detail, value) if not gradesObj['Overall'].has_key(user): gradesObj['Overall'][user] = {} return grades[user][detail] def getRawType(self): """ return assignment type as integer """ return self.tyyp def getType(self, REQUEST): """ get assignment type word """ return self.getTypes(REQUEST)[self.tyyp] def getPoints(self): """ get assignment value in points """ return self.normPunkte def quizID(self): return getattr(self, 'testiID', None) def getTitle(self, REQUEST=None): "Antakse kui on" if len(self.pealkiri.strip())==0: return "(untitled)" return self.pealkiri def getGroups(self): """ gets groupwork groups""" if not hasattr(self, 'grupid'): self.grupid = [] return self.grupid def kodutooMaterjal(self,bs, tulem='',level=1): i=1 aste="" if not hasattr(self, 'juhend'): self.juhend = "" while i!=level: aste += "--" i=i+1 for obj in bs.list_contents(criteria='weight'): s=obj.absolute_url()[len(self.fle_root().absolute_url()):] tulem += "\n