source: WAeUP_SRP/trunk/WAeUPTables.py @ 548

Last change on this file since 548 was 502, checked in by joachim, 18 years ago

Scratchcard Pin Generation
basic login in apply_admission

  • Property svn:keywords set to Id
File size: 3.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 502 2006-09-11 10:39:59Z 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    return ob
34       
35
36class WAeUPTable(ZCatalog):
37   
38    implements(IWAeUPTable)
39       
40    def addRecord(self, **data):
41        # The uid is the same as "bed".
42        uid = data[self.key]
43        res = self.searchResults({"%s" % self.key : uid})
44        if len(res) > 0:
45            raise ValueError("More than one record with uid %s" % uid)
46        self.catalog_object(dict2ob(data), uid=uid)
47        return uid
48   
49    def deleteRecord(self, uid):
50        self.uncatalog_object(uid)
51   
52    def searchAndSetRecord(self, **data):
53        raise NotImplemented
54
55    def modifyRecord(self, **data):
56        #records = self.searchResults(uid=uid)
57        uid = data[self.key]
58        records = self.searchResults({"%s" % self.key : uid})
59        if len(records) > 1:
60            # Can not happen, but anyway...
61            raise ValueError("More than one record with uid %s" % uid)
62        if len(records) == 0:
63            raise KeyError("No record for uid %s" % uid)
64        record = records[0]
65        record_data = {}
66        for field in self.schema() + self.indexes():
67            record_data[field] = getattr(record, field)
68        # Add the updated data:
69        record_data.update(data)
70        self.catalog_object(dict2ob(record_data), uid)
71
72class AccommodationTable(WAeUPTable):
73   
74    meta_type = 'WAeUP Accommodation Tool'
75    name = "accommodation"
76    key = "bed"
77    def __init__(self):
78        WAeUPTable.__init__(self, 'portal_accommodation')
79
80
81InitializeClass(AccommodationTable)
82
83class PinTable(WAeUPTable):
84   
85    meta_type = 'WAeUP Pin Tool'
86    name = "pins"
87    key = 'pin'
88    def __init__(self):
89        WAeUPTable.__init__(self, 'portal_pins')
90
91
92    def searchAndSetRecord(self, uid, jamb_reg_no):
93        #records = self.searchResults(uid=uid)
94        records = self.searchResults({"%s" % self.key : uid})
95        if len(records) > 1:
96            # Can not happen, but anyway...
97            raise ValueError("More than one record with uid %s" % uid)
98        if len(records) == 0:
99            return -1
100        record = records[0]
101        if record.student == "":
102            record_data = {}
103            for field in self.schema() + self.indexes():
104                record_data[field] = getattr(record, field)
105            # Add the updated data:
106            record_data['student'] = jamb_reg_no
107            self.catalog_object(dict2ob(record_data), uid)
108            return 1
109        if record.student != jamb_reg_no:
110            return 0
111        if record.student == jamb_reg_no:
112            return 2
113
114InitializeClass(PinTable)
115
116# BBB:
117AccomodationTable = AccommodationTable
Note: See TracBrowser for help on using the repository browser.