""" Container for User """ __version__ = "$Revision$"[11:-2] import Globals from Globals import Acquisition, Persistent from Acquisition import Explicit from AccessControl import ClassSecurityInfo from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from zope.interface import implements from common import commons from Permissions import * from interfaces import IUser class User(BTreeFolder2, Persistent, Explicit, commons): """ user folder """ meta_type = 'User' security = ClassSecurityInfo() security.declareObjectPublic() implements(IUser) manage_options = BTreeFolder2.manage_options def __init__(self, id): self.id = id BTreeFolder2.__init__(self, self.id) def setEmail(self, email): self.email = email def getEmail(self): """ returns user email """ return getattr(self, 'email', '') def setFirstName(self, fname): self.fname = fname def getFirstName(self): """ """ return getattr(self, 'fname', '') def setLastName(self, lname): self.lname = lname def getLastName(self): """ """ return getattr(self, 'lname', '') def getFullName(self): """ """ fname = self.getFirstName() lname = self.getLastName() if (fname != '' and lname != ''): return fname + " " + lname return self.id def getUserKeywords(self): """ """ different_keys = self.getDifferentKeywords() keys = '\n' return keys def getDifferentKeywords(self): """ returns user different keywords ['keyword1', 'keyword2', ..] """ different_keys = [] user = self.getId() query = {'getErased': 0, 'getUser': user} results = self.cat_ques(query) for res in results: keys = res.getKeywordsTuple for k in keys: k = k.strip() if k in different_keys: continue if k: different_keys.append(k) return different_keys def getUserKeywordsFrequencies(self): """ returns user keywords {'keyword1': 4, 'keyword2': 1, ..} """ user_tags = {} user = self.getId() query = {'getErased': 0, 'getUser':user} results = self.cat_ques(query) for res in results: keys = res.getKeywordsTuple for k in keys: if k.strip() != '': if user_tags.has_key(k): user_tags[k] = user_tags[k] + 1 else: user_tags[k] = 1 return user_tags Globals.InitializeClass(User) #EOF