source: main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py @ 11110

Last change on this file since 11110 was 7718, checked in by Henrik Bettermann, 13 years ago

Internationalize hostels package.

Remove exception catcher in switchReservations and corresponding test.

When testing the hostel configuration manually I found out that the beds_reserved list attribute of halls
only changed during the lifetime of a running instance. After restarting the portal all changes were gone.
Also "hostel._p_changed = True" didn't help. The only solution was to reassign the attribute to ensure persistance.

Unfortunately, the current tests don't catch such a malfunction. This has to be improved.

  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1## $Id: interfaces.py 7718 2012-02-28 19:34:51Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18from zope.interface import invariant, Invalid
19from zope import schema
20from waeup.sirp.interfaces import ISIRPObject
21from waeup.sirp.interfaces import MessageFactory as _
22from waeup.sirp.hostels.vocabularies import (
23    bed_letters, blocks, special_handling, StudentSource)
24
25class IHostelsContainer(ISIRPObject):
26    """A container for all kind of hostel objects.
27
28    """
29
30class IHostel(ISIRPObject):
31    """A base representation of hostels.
32
33    """
34
35    def loggerInfo(ob_class, comment):
36        """Adds an INFO message to the log file
37        """
38
39    def updateBeds():
40        """Fill hostel with beds or update beds.
41        """
42
43    hostel_id = schema.TextLine(
44        title = _(u'Hostel Id'),
45        readonly = True,
46        )
47
48    sort_id = schema.Int(
49        title = _(u'Sort Id'),
50        required = True,
51        default = 10,
52        )
53
54    hostel_name = schema.TextLine(
55        title = _(u'Hostel Name'),
56        required = True,
57        default = u'Hall 1',
58        )
59
60    floors_per_block = schema.Int(
61        title = _(u'Floors per Block'),
62        required = True,
63        default = 1,
64        )
65
66    rooms_per_floor = schema.Int(
67        title = _(u'Rooms per Floor'),
68        required = True,
69        default = 2,
70        )
71
72    beds_reserved = schema.List(
73        title = _(u'Reserved Beds'),
74        value_type = schema.TextLine(
75            default = u'',
76            required = False,
77        ),
78        required = True,
79        readonly = False,
80        default = [],
81        )
82
83    blocks_for_female = schema.List(
84        title = _(u'Blocks for Female Students'),
85        value_type = schema.Choice(
86            vocabulary = blocks
87            ),
88        )
89
90    blocks_for_male = schema.List(
91        title = _(u'Blocks for Male Students'),
92        value_type = schema.Choice(
93            vocabulary = blocks
94            ),
95        )
96
97    beds_for_fresh = schema.List(
98        title = _(u'Beds for Fresh Students'),
99        value_type = schema.Choice(
100            vocabulary = bed_letters
101            ),
102        )
103
104    beds_for_returning = schema.List(
105        title = _(u'Beds for Returning Students'),
106        value_type = schema.Choice(
107            vocabulary = bed_letters
108            ),
109        )
110
111    beds_for_final = schema.List(
112        title = _(u'Beds for Final Year Students'),
113        value_type = schema.Choice(
114            vocabulary = bed_letters
115            ),
116        )
117
118    beds_for_all = schema.List(
119        title = _(u'Beds without category'),
120        value_type = schema.Choice(
121            vocabulary = bed_letters
122            ),
123        )
124
125    special_handling = schema.Choice(
126        title = _(u'Special Handling'),
127        vocabulary = special_handling,
128        required = True,
129        default = u'regular',
130        )
131
132    @invariant
133    def blocksOverlap(hostel):
134        bfe = hostel.blocks_for_female
135        bma = hostel.blocks_for_male
136        if set(bfe).intersection(set(bma)):
137            raise Invalid(_('Female and male blocks overlap.'))
138
139    @invariant
140    def bedsOverlap(hostel):
141        beds = (hostel.beds_for_fresh +
142                hostel.beds_for_returning +
143                hostel.beds_for_final +
144                hostel.beds_for_all)
145        if len(beds) != len(set(beds)):
146            raise Invalid(_('Bed categories overlap.'))
147
148class IBed(ISIRPObject):
149    """A base representation of beds.
150
151    """
152
153    def loggerInfo(ob_class, comment):
154        """Adds an INFO message to the log file
155        """
156
157    def getBedCoordinates():
158        """Determine the coordinates from bed_id.
159        """
160    def bookBed(student_id):
161        """Book a bed for a student.
162        """
163
164    def switchReservation():
165        """Reserves bed or relases reserved bed respectively.
166        """
167
168    bed_id = schema.TextLine(
169        title = _(u'Bed Id'),
170        required = True,
171        default = u'',
172        )
173
174    bed_type = schema.TextLine(
175        title = _(u'Bed Type'),
176        required = True,
177        default = u'',
178        )
179
180    bed_number = schema.Int(
181        title = _(u'Bed Number'),
182        required = True,
183        )
184
185    owner = schema.TextLine(
186        title = _(u'Owner (Student)'),
187        required = True,
188        default = u'',
189        )
190
191
192
193class IBedAllocateStudent(IBed):
194    """A representation of beds for allocation form only.
195
196    """
197
198    owner = schema.Choice(
199        title = _(u'Owner (Student)'),
200        source = StudentSource(),
201        default = None,
202        required = True,
203        )
Note: See TracBrowser for help on using the repository browser.