source: WAeUP_SRP/trunk/PatchCPSStackingDirectoryStorageAdapter.py @ 1054

Last change on this file since 1054 was 933, checked in by joachim, 18 years ago

added a students directory,
students are now put in this directory
all other members remain in members
waeup_stacking_dir handles this

File size: 2.1 KB
Line 
1# (C) Copyright 2004 Nuxeo SARL <http://nuxeo.com>
2# Author: Georges Racinet <gracinet@nuxeo.com>
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License version 2 as published
6# by the Free Software Foundation.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16# 02111-1307, USA.
17#
18# $Id: utils.py 35055 2006-04-10 15:51:21Z gracinet $
19
20from Products.CMFCore.utils import getToolByName
21from Products.CPSDirectory.BaseDirectory import ConfigurationError
22
23def _setData(self, data, **kw):
24    """Set data to the entry, from a mapping."""
25
26    # TODO : this code should be placed in parent class
27    # and used by all StorageAdapter descendants
28    data = self._setDataDoProcess(data, **kw)
29
30    if not self._creation:
31        # XXX Note: if we attempt to change the backing id here, we get
32        # a KeyError. Unless an entry with the new backing id already
33        # exists,
34        # in which case, it would be overwritten...
35        # An explicit test would be better.
36        old_entry, b_dir = self._dir._getEntryFromBacking(self._id)
37        b_dir._editEntry(data)
38    else:
39        dir_id = self._dir.creation_dir
40        if "Student" in data.get('roles'):
41            dir_id = "students"
42        if not dir_id:
43            raise ValueError("Creation not allowed (no backing directory)")
44
45        dtool = getToolByName(self._dir, 'portal_directories')
46        try:
47            b_dir = getattr(dtool, dir_id)
48        except AttributeError:
49            raise ConfigurationError("No backing directory '%s'" % dir_id)
50
51        b_dir._createEntry(data)
52
53from Products.CPSDirectory.StackingDirectory import StackingStorageAdapter
54StackingStorageAdapter._setData = _setData
Note: See TracBrowser for help on using the repository browser.