source: WAeUP_SRP/trunk/WAeUPTables.py @ 446

Last change on this file since 446 was 440, checked in by joachim, 18 years ago

levels can be created
keyerror elective fixed
check for blanks in Id's checked

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1# (C) Copyright 2005 AixtraWare <http://aixtraware.de>
2# Author: Joachim Schmitz <js@aixtraware.de>
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: WAeUPTables.py 440 2006-08-29 11:56:53Z joachim $
19
20from zope.interface import implements
21from Globals import InitializeClass
22from Products.ZCatalog.ZCatalog import ZCatalog
23
24from interfaces import IWAeUPTable
25
26class AttributeHolder(object):
27    pass
28
29def dict2ob(dict):
30    ob = AttributeHolder()
31    for key, value in dict.items():
32        setattr(ob, key, value)
33       
34    return ob
35       
36
37class WAeUPTable(ZCatalog):
38   
39    implements(IWAeUPTable)
40       
41    def addRecord(self, **data):
42        raise NotImplementedError
43   
44    def deleteRecord(self, uid):
45        self.uncatalog_object(uid)
46   
47    def modifyRecord(self, uid, **data):
48        records = self.searchResults(uid=uid)
49        if len(records) > 1:
50            # Can not happen, but anyway...
51            raise ValueError("More than one record with uid %s" % uid)
52        if len(records) == 0:
53            raise KeyError("No record for uid %s" % uid)
54       
55        record = records[0]
56        record_data = {}
57        for field in self.schema() + self.indexes():
58            record_data[field] = getattr(record, field)
59        # Add the updated data:
60        record_data.update(data)
61        self.catalog_object(dict2ob(record_data), uid)
62
63class AccommodationTable(WAeUPTable):
64   
65    meta_type = 'WAeUP Accommodation Tool'
66   
67    def __init__(self):
68        WAeUPTable.__init__(self, 'portal_accommodation')
69
70    def addRecord(self, **data):
71        # The uid is the same as "bed".
72        uid = data['bed']
73        self.catalog_object(dict2ob(data), uid=uid)
74        return uid
75
76
77InitializeClass(AccommodationTable)
78
79class PinTable(WAeUPTable):
80   
81    meta_type = 'WAeUP Pin Tool'
82   
83    def __init__(self):
84        WAeUPTable.__init__(self, 'portal_pins')
85
86    def addRecord(self, **data):
87        # The uid is the same as "bed".
88        uid = data['bed']
89        self.catalog_object(dict2ob(data), uid=uid)
90        return uid
91
92
93InitializeClass(PinTable)
94
95# BBB:
96AccomodationTable = AccommodationTable
Note: See TracBrowser for help on using the repository browser.