source: trunk/ToolboxMember.py @ 66

Revision 66, 1.8 KB checked in by tarmo, 14 years ago (diff)

Changed the svn:eol-style property to "native", since
people aren't using unix line feeds uniformally.

  • Property svn:eol-style set to native
Line 
1from Products.Archetypes.public import *
2from Globals import InitializeClass
3from Products.CMFCore.utils import getToolByName
4from AccessControl import ClassSecurityInfo, Unauthorized
5from config import PROJECTNAME
6
7userproperties=('topics','grades','pedagogies','other_users','keywords','skills','languages','used_content')
8
9# A utility method for accessing a ToolboxMember object
10# Note that since this is not in ZODB, this can only be called from
11# Python code (outside sandbox).
12def getToolboxMember(id,context):
13    return ToolboxMember(id,context)
14
15# This class is never attached to ZODB tree, so it does not need
16# security settings and can only be accessed from Python code.
17class ToolboxMember:
18    """Class for handling member data."""
19
20    def __init__(self,id,context):
21        self.id=id
22        self.m_tool = getToolByName(context,'portal_membership')
23        # Get a reference to the MemberData object for this user
24        self.member=self.m_tool.getMemberById(self.id)
25
26    def getTokens(self,propname):
27        """Returns the values of a named property."""
28        return list(self.member.getProperty(propname))
29
30    def addToken(self,propname,token):
31        """Adds a new value to a named property."""
32        tokens=self.getTokens(propname)
33        if token not in tokens:
34            tokens.append(token)
35            self.setTokens(propname,tokens)
36
37    def delToken(self,propname,token):
38        """Removes a token from a property."""
39        tokens=self.getTokens(propname)
40        if token in tokens:
41            tokens.remove(token)
42            self.setTokens(propname,tokens)
43
44    def setTokens(self,propname,tokens):
45        """Sets all tokens in a property to match the given parameter."""
46        self.m_tool.getMemberById(self.id).setMemberProperties({propname:tokens})
47       
Note: See TracBrowser for help on using the repository browser.