# -*- coding: utf-8 # Copyright 2005 by Vahur Rebas from Products.CMFCore.utils import UniqueObject from OFS.SimpleItem import SimpleItem from OFS.PropertyManager import PropertyManager from AccessControl import ClassSecurityInfo from Globals import InitializeClass, PersistentMapping class TTTool(UniqueObject, SimpleItem, PropertyManager): """ School tool. handles user management """ id = 'time_tool' meta_type = 'Time Table Tool' plone_tool = 1 content_icon='tt_icon.gif' manage_options = PropertyManager.manage_options security = ClassSecurityInfo() def __init__(self): self._lectures = {} self._teach_map = {} self._relat_map = {} def addNewLecture(self, lecture,short): from random import randint id = '%s%d' % (short,randint(1,9999)) while 1: if not self._lectures.has_key(id): break id = '%s%d' % ('sub',randint(1,9999)) self._lectures[id] = [id,lecture,short] self._p_changed = True def removeLecture(self, lecture): self._lectures.pop(lecture) def getLectures(self): return self._lectures def getLecture(self,key): return self._lectures[key] def setTeacherMap(self, teacher_name, req): user_obj = teacher_name teacher_name = str(teacher_name) if not self._teach_map.has_key(teacher_name): self._teach_map[teacher_name] = {} x = teacher_name self._teach_map[teacher_name]['totalh'] = req.get('total_'+x+'_hours', 0) self._teach_map[teacher_name]['colour'] = req.get('colour_'+x, 'yellow') self._teach_map[teacher_name]['monday'] = int(req.get('free_'+x+'_monday', 0)) self._teach_map[teacher_name]['thesdy'] = int(req.get('free_'+x+'_thesdy', 0)) self._teach_map[teacher_name]['wedndy'] = int(req.get('free_'+x+'_wedndy', 0)) self._teach_map[teacher_name]['thuday'] = int(req.get('free_'+x+'_thuday', 0)) self._teach_map[teacher_name]['friday'] = int(req.get('free_'+x+'_friday', 0)) self._teach_map[teacher_name]['satday'] = int(req.get('free_'+x+'_satday', 0)) self._teach_map[teacher_name]['sunday'] = int(req.get('free_'+x+'_sunday', 0)) self._teach_map[teacher_name]['direct'] = str(req.get('direct_'+x, '')) self._p_changed = True print self._teach_map def getTeacherMap(self, teacher_name): if not self._teach_map.has_key(teacher_name): return {} return self._teach_map[teacher_name] def getColors(self): #Vanad värvid mida oli liiga vähe #colo = { # 'green':'green', # 'blue':'blue', # 'magenta':'magenta', # 'yellow':'yellow', # 'red':'red', # 'black':'black'} symbols = ['FF','CC','99','66','33','00'] colors = [] #composing the table of websafe colors, it is too complicated because tryed to put colors into order that will #be easy to use. i = 0 j = 5 k = 5 staadium = 0 for suureneb in range(0, 5): colors.append('#'+symbols[suureneb]+symbols[suureneb]+symbols[suureneb]) for suureneb in range(0, 54): colors.append('#'+symbols[i]+symbols[j]+symbols[k]) if staadium < 4: i = i + 1 elif staadium == 4: i = 0 elif staadium >= 4 and staadium < 9: k = k - 1 elif staadium >= 9 and staadium < 13: i = i + 1 k = k + 1 elif staadium == 13: i = 0 k = 0 elif staadium >= 13 and staadium < 18: i = i + 1 elif staadium >= 18 and staadium < 22: k = k + 1 elif staadium == 22: k = 0 elif staadium >= 22 and staadium < 27: j = j - 1 elif staadium >= 27 and staadium < 31: j = j + 1 k = k + 1 elif staadium == 31: j = 0 k = 0 elif staadium >= 31 and staadium < 36: k = k + 1 elif staadium >= 36 and staadium < 40: j = j + 1 elif staadium == 40: j = 0 elif staadium >= 40 and staadium < 45: i = i - 1 elif staadium >= 45 and staadium < 49: i = i + 1 j = j + 1 elif staadium == 49: i = 0 j = 0 elif staadium >= 49 and staadium < 54: j = j + 1 else: return 'L6hki' staadium = staadium + 1 return colors def setRelationsMap(self, subject, req): print "sr_sub",subject if not self._relat_map.has_key(subject): self._relat_map[subject] = {} for x in self.prefs_user_group_search('','groups'): if not self._relat_map[subject].has_key(str(x)): self._relat_map[subject][str(x)] = {} self._relat_map[subject][str(x)]['teacher'] = req.get('teacher_'+subject+'_'+str(x),'') self._relat_map[subject][str(x)]['weight'] = req.get('weight_'+subject+'_'+str(x),'') self._p_changed = True def getRelationsMap(self, subject): if not self._relat_map.has_key(subject): return {} print "relats ",self._relat_map[subject] return self._relat_map[subject] def getGroups(self): list = [] tmp = self.prefs_user_group_search('', 'groups') for x in tmp: if x.klass: list.append(x) return list def getTeachers(self): """ returns a list of teachers """ list = [] tmp = self.prefs_user_group_search('', 'users') for x in tmp: if 'Teacher' in x.getRolesInContext(self): list.append(x) return list InitializeClass(TTTool)