# -*- coding: utf-8 # $Id$ # # 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 """Tracker module.""" __version__ = "$Revision$"[11:-2] import Globals from OFS.SimpleItem import SimpleItem from OFS.PropertyManager import PropertyManager import AccessControl from common import perm_view,perm_manage, perm_edit, translate from ZODB.PersistentList import PersistentList from DateTime import DateTime class TrackerTask(SimpleItem): """ generic TrackerTask """ security = AccessControl.ClassSecurityInfo() security.declareObjectPublic() security.setDefaultAccess("allow") meta_type = "TrackerTask" def __init__(self, id, title, type, start, end, desc, area, remote=None): self.title = title self.sub_type = type self.starting_time = start self.ending_time = end self.desc = desc self.id = id self.area = area self.remoteObjId = remote def getArea(self): return self.area security.declarePublic('getStart') def getStart(self): a = self.starting_time.strip() if not a: return None return a def getEnd(self): a = self.ending_time.strip() if not a: return None return a def getTitle(self): return self.title def getId(self): return self.id def getShortDesc(self): return self.desc def getType(self): return self.sub_type def setRemote(self, remote): """ id of an object in IVA. Or URL? relative from fle_root()? """ self.remoteObjId = remote def getRemote(self): """ return an id of anobject """ return self.remoteObjId class Tracker(PropertyManager, SimpleItem): """ Tracker. Simple course desing """ security = AccessControl.ClassSecurityInfo() security.declareObjectPublic() meta_type = 'Tracker' def __init__(self): """ init """ self.id = 'tracker' self.activated = 0 self.container = PersistentList([]) self.tracker_source = '' security.declareProtected(perm_view, 'index_html') def index_html(self, REQUEST): """ index_html -> tracker_index """ return self.tracker_index() security.declareProtected(perm_view, 'is_activated') def is_activated(self): """ return true if tracker is activated """ return self.activated security.declareProtected(perm_edit, 'setActivated') def setActivated(self, status): """ status is 1 or 0 (int) """ self.activated = status return self.activated security.declareProtected(perm_view, 'get_weeks_range') def get_weeks_range(self): """ return range of weeks. dates come from course info """ start = DateTime(self.get_start_date()) end = DateTime(self.get_end_date()) runner = start range = [] while runner.lessThanEqualTo(end): range.append(runner.week()) runner = runner + 7 return range security.declareProtected(perm_view, 'get_start_n_end_date') def get_start_n_end_date(self): """ return start and end date. DateTime object. starting date must be monday! """ start = DateTime(self.get_start_date()) if start.dow() != 1: while start.dow() != 1: start = start-1 end = DateTime(self.get_end_date()) return start, end security.declarePrivate('get_for_js') def get_for_js(self, type): """ generic method getting different types for javascript """ res = [] final = [] for t in self.container: if t.getArea() == type: res.append(t) for x in res: title = unicode(x.getTitle(), 'utf-8') final.append([x.getId(), x.getStart(), x.getEnd(), title.encode('iso-8859-1', 'replace')]) return final security.declareProtected(perm_edit, 'get_meetings_js') def get_meetings_js(self): """ same as get_meetings but returns a javascript array """ return self.get_for_js('meeting') security.declareProtected(perm_edit, 'get_assignments_js') def get_assignments_js(self): """ same as get_assignments but returns a javascript array """ return self.get_for_js('assignments') security.declareProtected(perm_edit, 'get_reading_js') def get_reading_js(self): """ same as get_assignments but returns a javascript array """ return self.get_for_js('reading') security.declareProtected(perm_edit, 'get_groupwork_js') def get_groupwork_js(self): """ same as get_assignments but returns a javascript array """ return self.get_for_js('groupwork') security.declareProtected(perm_edit, 'get_comments_js') def get_comments_js(self): """ same as get_assignments but returns a javascript array """ return self.get_for_js('comments') security.declareProtected(perm_edit, 'get_meetings') def get_meetings(self): """ return a tuple of tuple of meetings [[start_date, end_date, meeting],[],...] """ res = [] for t in self.container: if t.getArea() == 'meeting': res.append(t) return res security.declareProtected(perm_edit, 'get_assignments') def get_assignments(self): """ return a tuple of tuple of meetings [[start_date, end_date, meeting],[],...] """ res = [] for t in self.container: if t.getArea() == 'assignments': res.append(t) return res security.declareProtected(perm_edit, 'get_reading') def get_reading(self): """ return a tuple of tuple of meetings [[start_date, end_date, meeting],[],...] """ res = [] for t in self.container: if t.getArea() == 'reading': res.append(t) return res security.declareProtected(perm_edit, 'get_groupwork') def get_groupwork(self): """ return a tuple of tuple of meetings [[start_date, end_date, meeting],[],...] """ res = [] for t in self.container: if t.getArea() == 'groupwork': res.append(t) return res security.declareProtected(perm_edit, 'get_comments') def get_comments(self): """ return a tuple of tuple of meetings [[start_date, end_date, meeting],[],...] """ res = [] for t in self.container: if t.getArea() == 'comments': res.append(t) return res security.declareProtected(perm_edit, 'add_new') def add_new(self, title='', type='', start='', end='', desc='', area='', remote='', workshop_id=''): """ generic method for creating ... stuff """ import time response = 0 if not title.strip(): return 1 try: DateTime(start) except: return 2 try: DateTime(end) except: return 3 if not area: return 4 if DateTime(end) 100: return response else: self.container.append(task) self._p_changed = 1 return response security.declareProtected(perm_edit, 'delete_task') def delete_task(self, id, delete=1): """ delete trackerTask """ new_container = [] for x in self.container: if str(x.getId()) == str(id): rem = x.getRemote() if rem and delete: if x.getArea() == 'meeting': events = self.getCalendar() try: events._delObject(rem) except AttributeError: # event is already gone! pass if x.getArea() == 'assignments': as = self.kodutood try: as._delObject(rem) except AttributeError: # assignment is already gone! pass if x.getArea() == 'groupwork' and x.getType() == 'concept_map': as = self.kodutood try: as._delObject(rem) except AttributeError: # assignment is already gone! pass del x continue new_container.append(x) self.container = new_container self._p_changed = 1 return id security.declareProtected(perm_edit, 'getTypesFor') def getTypesFor(self, type, language): """ get types for specific area """ types = [] if type == 'meeting': types = [['Lecture', 'loeng'], ['tracer_type_workshop', 'praktikum'], ['Seminar', 'seminar'], ['Other', 'muu'] ] if type == 'assignments': types = [['Product', 'product'], ['Concept map', 'concept_map'], ['Quiz', 'quiz'], ['Presentation', 'presentation'], ['Peer review', 'peer_review'], ] if type == 'reading': types = [['Reading', 'reading']] if type == 'groupwork': types = [['tracer_type_kb_disc','kb_discussion'], ['tracer_jam_sess', 'jam_session'], ['Wordmap', 'concept_map'], ['Groupwork', 'groupwork'] ] if type == 'comments': types = [['Comment', 'comment']] if not types: return ['Error!', 'error'] res = [] for x in types: tmp = [] # XXX: testme #tmp.append(translate(self, x[0], target=language).decode('utf-8').encode('iso-8859-1')) tmp.append(translate(self, x[0], target=language)) tmp.append(x[1]) res.append(tmp) return res security.declareProtected(perm_edit, 'getAreas') def getAreas(self): """ return areas """ return ['meeting', 'assignments', 'reading', 'groupwork', 'comments'] security.declareProtected(perm_edit, 'getTaskById') def getTaskById(self, id): """ return a task with a given id """ for s in self.container: if str(s.getId()) == str(id): return s return None security.declareProtected(perm_edit, 'getTitleFor') def getTitleFor(self, id): """ return a title for a trackerTask with a given id """ task = self.getTaskById(id) if task is None: return "" return task.getTitle() security.declareProtected(perm_edit, 'getStartFor') def getStartFor(self, id): """ return a starting time for a trackerTask with a given id """ task = self.getTaskById(id) if task is None: return "" return task.getStart() security.declareProtected(perm_edit, 'getEndFor') def getEndFor(self, id): """ return a ending time for a trackerTask with a given id """ task = self.getTaskById(id) if task is None: return "" return task.getEnd() security.declareProtected(perm_edit, 'getShortDescFor') def getShortDescFor(self, id): """ return a short description of a trackerTask with a given id """ task = self.getTaskById(id) if task is None: return "" return task.getShortDesc() security.declareProtected(perm_edit, 'getTypeFor') def getTypeFor(self, id): """ return a type of a trackerTask with a given id """ task = self.getTaskById(id) if task is None: return "" return task.getType() security.declareProtected(perm_edit, 'getRemoteFor') def getRemoteFor(self, id): """ return a objects id """ task = self.getTaskById(id) if task is None: return "" return task.getRemote() security.declareProtected(perm_edit, 'publish_tracker') def publish_tracker(self, source): """ published tracker """ import re source = re.sub('onclick', 'onmouseout="javascript:hideme(event)" onmouseover', source) source = unicode(source, 'ISO-8859-1').encode('utf-8') self.tracker_source = source self._p_changed = 1 return 0 security.declareProtected(perm_edit, 'unpublish_tracker') def unpublish_tracker(self): """ unpublish tracker """ self.tracker_source = '' return 0 security.declareProtected(perm_view, 'get_tracker_source') def get_tracker_source(self): """ get tracker /student view/ """ return self.tracker_source security.declareProtected(perm_view, 'is_tracker_published') def is_tracker_published(self): """ Is tracker published """ if len(self.tracker_source)>0: return 1 else: return 0 security.declareProtected(perm_edit, 'getGuidelinesList') def getGuidelinesList(self, bs=None, tulem='', level=1): if bs is None: bs = self.gf 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' return res def getJammings(self): js = self.jamming.get_children('JamSession') res = '' for x in js: res += '\n' return res Globals.InitializeClass(Tracker)