source: WAeUP_SRP/branches/srp_backend/WAeUPTables.py @ 446

Last change on this file since 446 was 438, checked in by Henrik Bettermann, 18 years ago
File size: 2.3 KB
RevLine 
[438]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 414 2006-08-24 11:10:59Z lregebro $
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
79# BBB:
80AccomodationTable = AccommodationTable
Note: See TracBrowser for help on using the repository browser.