# -*- coding: utf-8 # Copyright (c) 2008, iCamp Consortium # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. from Globals import Persistent from OFS.SimpleItem import SimpleItem from zope.interface import implements from zope.component import getUtility from interfaces import IUser, IAffordanceManager class User(Persistent, SimpleItem): """ Affordance class """ implements(IUser) meta_type = "User" def __init__(self, id, title, fname, lname, email): self.id = id self.title = title self.firstname = fname self.lastname = lname self.email = email self._persData = {} self._toolData = {} def getAffordanceData(self, persp, _id=None): """ get affordance data from one perspective. id is affordance's id """ ws = self._persData.get(persp, {}) return ws.get(_id, 0) def getPerspectives(self): return self._persData.keys() def getTitle(self): """ get title """ rr = getattr(self, 'title', self.id) if not rr: return self.id return rr def savePerspective(self, req): """ save user's perspective data """ print "saving perspective", self.absolute_url() am = getUtility(IAffordanceManager) pers = req.get('perspective') workset = self._persData.get(pers, {}) for a in am.getAffordances(): print "getting...", req.get(a.id, 0) workset[a.id] = float(req.get(a.id, 0)) self._persData[pers] = workset self._p_changed = True return 0 def setToolData(self, toolid, affid, value): """ save user's evaluation for a tool's affordance """ if not hasattr(self.aq_base, '_toolData'): self._toolData = {} if not self._toolData.has_key(toolid): self._toolData[toolid] = {} self._toolData[toolid][affid] = value self._p_changed = True def getToolData(self, toolid, affid): """ get user's evaluation for a tool. returns -1 if no value set """ if not hasattr(self.aq_base, '_toolData'): return -1 if not self._toolData.has_key(toolid): return -1 return self._toolData[toolid][affid]