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): self.id = id self.title = title self._persData = {} def getAffordanceData(self, persp, id): """ 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 """ am = getUtility(IAffordanceManager) pers = req.get('perspective') workset = self._persData.get(pers, {}) for a in am.getAffordances(): workset[a.id] = float(req.get(a.id)) self._persData[pers] = workset self._p_changed = True return 0