Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
PlonePAS.plugins.property.ZODBMutablePropertyProvider Class Reference
Inheritance diagram for PlonePAS.plugins.property.ZODBMutablePropertyProvider:
Inheritance graph
[legend]
Collaboration diagram for PlonePAS.plugins.property.ZODBMutablePropertyProvider:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getPropertiesForUser
def setPropertiesForUser
def deleteUser
def testMemberData
def enumerateUsers

Public Attributes

 id
 title

Static Public Attributes

string meta_type = 'ZODB Mutable Property Provider'

Private Member Functions

def _getSchema
def _getDefaultValues

Private Attributes

 _storage
 _schema
 _defaultvalues

Detailed Description

Storage for mutable properties in the ZODB for users/groups.

API sounds like it's only for users, but groups work as well.

Definition at line 55 of file property.py.


Constructor & Destructor Documentation

def PlonePAS.plugins.property.ZODBMutablePropertyProvider.__init__ (   self,
  id,
  title = '',
  schema = None,
  kw 
)
Create in-ZODB mutable property provider.

Provide a schema either as a list of (name,type,value) tuples
in the 'schema' parameter or as a series of keyword parameters
'name=value'. Types will be guessed in this case.

The 'value' is meant as the default value, and will be used
unless the user provides data.

If no schema is provided by constructor, the properties of the
portal_memberdata object will be used.

Types available: string, text, boolean, int, long, float, lines, date

Definition at line 63 of file property.py.

00063 
00064     def __init__(self, id, title='', schema=None, **kw):
00065         """Create in-ZODB mutable property provider.
00066 
00067         Provide a schema either as a list of (name,type,value) tuples
00068         in the 'schema' parameter or as a series of keyword parameters
00069         'name=value'. Types will be guessed in this case.
00070 
00071         The 'value' is meant as the default value, and will be used
00072         unless the user provides data.
00073 
00074         If no schema is provided by constructor, the properties of the
00075         portal_memberdata object will be used.
00076 
00077         Types available: string, text, boolean, int, long, float, lines, date
00078         """
00079         self.id = id
00080         self.title = title
00081         self._storage = OOBTree()
00082 
00083         # calculate schema and default values
00084         defaultvalues = {}
00085         if not schema and not kw:
00086             schema = ()
00087         elif not schema and kw:
00088             schema = _guessSchema(kw)
00089             defaultvalues = kw
00090         else:
00091             valuetuples = [(name, value) for name, type, value in schema]
00092             schema = [(name, type) for name, type, value in schema]
00093             for name, value in valuetuples: defaultvalues[name] = value
00094         self._schema = tuple(schema)
00095         self._defaultvalues = defaultvalues
00096 
00097         # don't use _schema directly or you'll lose the fallback! use
00098         # _getSchema instead same for default values
00099 


Member Function Documentation

def PlonePAS.plugins.property.ZODBMutablePropertyProvider._getDefaultValues (   self,
  isgroup = None 
) [private]
Returns a dictionary mapping of property names to default values.
Defaults to portal_*data tool if necessary.

Definition at line 116 of file property.py.

00116 
00117     def _getDefaultValues(self, isgroup=None):
00118         """Returns a dictionary mapping of property names to default values.
00119         Defaults to portal_*data tool if necessary.
00120         """
00121         datatool = isgroup and "portal_groupdata" or "portal_memberdata"
00122 
00123         defaultvalues = self._defaultvalues
00124         if not self._schema:
00125             # if no schema is provided, use portal_*data properties
00126             defaultvalues = {}
00127             mdtool = getToolByName(self, datatool, None)
00128             # Don't fail badly if tool is not available.
00129             if mdtool is not None:
00130                 # we rely on propertyMap and propertyItems mapping
00131                 mdvalues = mdtool.propertyItems()
00132                 for name, value in mdvalues:
00133                     # For selection types the default value is the name of a
00134                     # method which returns the possible values. There is no way
00135                     # to set a default value for those types.
00136                     ptype = mdtool.getPropertyType(name)
00137                     if ptype == "selection":
00138                         defaultvalues[name] = ""
00139                     elif ptype == "multiple selection":
00140                         defaultvalues[name] = []
00141                     else:
00142                         defaultvalues[name] = value
00143 
00144             # ALERT! if someone gives their *_data tool a title, and want a title
00145             #        as a property of the user/group (and groups do by default)
00146             #        we don't want them all to have this title, since a title is
00147             #        used in the UI if it exists
00148             if defaultvalues.get("title"): defaultvalues["title"] = ""
00149         return defaultvalues
00150 

Here is the call graph for this function:

Here is the caller graph for this function:

def PlonePAS.plugins.property.ZODBMutablePropertyProvider._getSchema (   self,
  isgroup = None 
) [private]

Definition at line 100 of file property.py.

00100 
00101     def _getSchema(self, isgroup=None):
00102         # this could probably stand to be cached
00103         datatool = isgroup and "portal_groupdata" or "portal_memberdata"
00104 
00105         schema = self._schema
00106         if not schema:
00107             # if no schema is provided, use portal_memberdata properties
00108             schema = ()
00109             mdtool = getToolByName(self, datatool, None)
00110             # Don't fail badly if tool is not available.
00111             if mdtool is not None:
00112                 mdschema = mdtool.propertyMap()
00113                 schema = [(elt['id'], elt['type']) for elt in mdschema]
00114         return schema
00115 

Here is the call graph for this function:

Here is the caller graph for this function:

Delete all user properties

Definition at line 204 of file property.py.

00204 
00205     def deleteUser(self, user_id):
00206         """Delete all user properties
00207         """
00208         # Do nothing if an unknown user_id is given
00209         try:
00210             del self._storage[user_id]
00211         except KeyError:
00212             pass
00213 
00214 

def PlonePAS.plugins.property.ZODBMutablePropertyProvider.enumerateUsers (   self,
  id = None,
  login = None,
  exact_match = False,
  kw 
)
See IUserEnumerationPlugin.

Definition at line 249 of file property.py.

00249 
00250                       ):
00251 
00252         """ See IUserEnumerationPlugin.
00253         """
00254         plugin_id = self.getId()
00255 
00256         criteria=copy.copy(kw)
00257         if id is not None:
00258             criteria["id"]=id
00259         if login is not None:
00260             criteria["login"]=login
00261 
00262         users=[ (user,data) for (user,data) in self._storage.items()
00263                     if self.testMemberData(data, criteria, exact_match)]
00264 
00265         user_info=[ { 'id' : self.prefix + user_id,
00266                      'login' : user_id,
00267                      'title' : data.get('fullname', user_id),
00268                      'description' : data.get('fullname', user_id),
00269                      'email' : data.get('email', ''),
00270                      'pluginid' : plugin_id } for (user_id, data) in users ]
00271 
00272         return tuple(user_info)
00273 
00274 
00275 
00276 classImplements(ZODBMutablePropertyProvider,
00277                 IPropertiesPlugin,
00278                 IUserEnumerationPlugin,
00279                 IMutablePropertiesPlugin)
00280 
00281 InitializeClass(ZODBMutablePropertyProvider)

Here is the caller graph for this function:

Get property values for a user or group.
Returns a dictionary of values or a PropertySheet.

This implementation will always return a MutablePropertySheet.

NOTE: Must always return something, or else the property sheet
won't get created and this will screw up portal_memberdata.

Definition at line 151 of file property.py.

00151 
00152     def getPropertiesForUser(self, user, request=None):
00153         """Get property values for a user or group.
00154         Returns a dictionary of values or a PropertySheet.
00155 
00156         This implementation will always return a MutablePropertySheet.
00157 
00158         NOTE: Must always return something, or else the property sheet
00159         won't get created and this will screw up portal_memberdata.
00160         """
00161         isGroup = getattr(user, 'isGroup', lambda: None)()
00162 
00163         data = self._storage.get(user.getId())
00164         defaults = self._getDefaultValues(isGroup)
00165 
00166         # provide default values where missing
00167         if not data: data = {}
00168         for key, val in defaults.items():
00169             if not data.has_key(key):
00170                 data[key] = val
00171 
00172         return MutablePropertySheet(self.id,
00173                                     schema=self._getSchema(isGroup), **data)
00174 

Here is the call graph for this function:

Set the properties of a user or group based on the contents of a
property sheet.

Definition at line 175 of file property.py.

00175 
00176     def setPropertiesForUser(self, user, propertysheet):
00177         """Set the properties of a user or group based on the contents of a
00178         property sheet.
00179         """
00180         isGroup = getattr(user, 'isGroup', lambda: None)()
00181 
00182         properties = dict(propertysheet.propertyItems())
00183 
00184         for name, property_type in self._getSchema(isGroup) or ():
00185             if (name in properties and not
00186                 validateValue(property_type, properties[name])):
00187                 raise ValueError, ('Invalid value: %s does not conform '
00188                                    'to %s' % (name, property_type))
00189 
00190         allowed_prop_keys = [pn for pn, pt in self._getSchema(isGroup) or ()]
00191         if allowed_prop_keys:
00192             prop_names = Set(properties.keys()) - Set(allowed_prop_keys)
00193             if prop_names:
00194                 raise ValueError, 'Unknown Properties: %r' % prop_names
00195 
00196         userid = user.getId()
00197         userprops = self._storage.get(userid)
00198         if userprops is not None:
00199             userprops.update(properties)
00200             self._storage[userid] = self._storage[userid]   # notify persistence machinery of change
00201         else:
00202             self._storage.insert(user.getId(), properties)
00203 

Here is the call graph for this function:

def PlonePAS.plugins.property.ZODBMutablePropertyProvider.testMemberData (   self,
  memberdata,
  criteria,
  exact_match = False 
)
Test if a memberdata matches the search criteria.

Definition at line 215 of file property.py.

00215 
00216     def testMemberData(self, memberdata, criteria, exact_match=False):
00217         """Test if a memberdata matches the search criteria.
00218         """
00219         for (key, value) in criteria.items():
00220             testvalue=memberdata.get(key, None)
00221             if testvalue is None:
00222                 return False
00223 
00224             if isStringType(testvalue):
00225                 testvalue=testvalue.lower()
00226             if isStringType(value):
00227                 value=value.lower()
00228                 
00229             if exact_match:
00230                 if value!=testvalue:
00231                     return False
00232             else:
00233                 try:
00234                     if value not in testvalue:
00235                         return False
00236                 except TypeError:
00237                     # Fall back to exact match if we can check for sub-component
00238                     if value!=testvalue:
00239                         return False
00240 
00241 
00242         return True
00243 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 94 of file property.py.

Definition at line 93 of file property.py.

Definition at line 80 of file property.py.

Definition at line 78 of file property.py.

string PlonePAS.plugins.property.ZODBMutablePropertyProvider.meta_type = 'ZODB Mutable Property Provider' [static]
Storage for mutable properties in the ZODB for users/groups.

API sounds like it's only for users, but groups work as well.

Definition at line 61 of file property.py.

Definition at line 79 of file property.py.


The documentation for this class was generated from the following file: