source: main/waeup.kofa/trunk/src/waeup/kofa/hostels/interfaces.py @ 13316

Last change on this file since 13316 was 13316, checked in by Henrik Bettermann, 9 years ago

Add some methods to release expired bed allocations. View
components have to be added in custom packages.

  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1## $Id: interfaces.py 13316 2015-10-14 09:34:30Z 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  grok import getSite
19from datetime import datetime
20from zope.component import getUtility
21from zope.catalog.interfaces import ICatalog
22from zope.interface import invariant, Invalid, Attribute
23from zope import schema
24from waeup.kofa.interfaces import (
25    IKofaObject, academic_sessions_vocab, registration_states_vocab)
26from waeup.kofa.interfaces import MessageFactory as _
27from waeup.kofa.hostels.vocabularies import (
28    bed_letters, blocks, SpecialHandlingSource,
29    NOT_OCCUPIED)
30
31class IHostelsContainer(IKofaObject):
32    """A container for hostel objects.
33    """
34
35    expired = Attribute('True if current datetime is in application period.')
36
37    startdate = schema.Datetime(
38        title = _(u'Hostel Allocation Start Date'),
39        required = False,
40        description = _('Example: ') + u'2011-12-01 18:30:00+01:00',
41        )
42
43    enddate = schema.Datetime(
44        title = _(u'Hostel Allocation Closing Date'),
45        required = False,
46        description = _('Example: ') + u'2011-12-31 23:59:59+01:00',
47        )
48
49    accommodation_session = schema.Choice(
50        title = _(u'Booking Session'),
51        source = academic_sessions_vocab,
52        default = datetime.now().year,
53        required = False,
54        readonly = False,
55        )
56
57    accommodation_states = schema.List(
58        title = _(u'Allowed States'),
59        value_type = schema.Choice(
60            vocabulary = registration_states_vocab,
61            ),
62        default = [],
63        )
64
65    def clearAllHostels():
66        """Clear all hostels.
67        """
68
69    def addHostel(hostel):
70        """Add a hostel.
71        """
72
73    def releaseExpiredAllocations(n):
74        """Release bed if bed allocation has expired. Allocation expires
75        after `n` days if maintenance fee has not been paid.
76        """
77
78    def writeLogMessage(view, message):
79        """Add an INFO message to hostels.log.
80        """
81
82class IHostel(IKofaObject):
83    """Representation of a hostel.
84    """
85
86    bed_statistics = Attribute('Number of booked and total beds')
87
88    def clearHostel():
89        """Remove all beds.
90        """
91
92    def updateBeds():
93        """Fill hostel with beds or update beds.
94        """
95
96    hostel_id = schema.TextLine(
97        title = _(u'Hostel Id'),
98        )
99
100    sort_id = schema.Int(
101        title = _(u'Sort Id'),
102        required = True,
103        default = 10,
104        )
105
106    hostel_name = schema.TextLine(
107        title = _(u'Hostel Name'),
108        required = True,
109        default = u'Hall 1',
110        )
111
112    floors_per_block = schema.Int(
113        title = _(u'Floors per Block'),
114        required = True,
115        default = 1,
116        )
117
118    rooms_per_floor = schema.Int(
119        title = _(u'Rooms per Floor'),
120        required = True,
121        default = 2,
122        )
123
124    beds_reserved = schema.List(
125        title = _(u'Reserved Beds'),
126        value_type = schema.TextLine(
127            default = u'',
128            required = False,
129        ),
130        required = True,
131        readonly = False,
132        default = [],
133        )
134
135    blocks_for_female = schema.List(
136        title = _(u'Blocks for Female Students'),
137        value_type = schema.Choice(
138            vocabulary = blocks
139            ),
140        )
141
142    blocks_for_male = schema.List(
143        title = _(u'Blocks for Male Students'),
144        value_type = schema.Choice(
145            vocabulary = blocks
146            ),
147        )
148
149    beds_for_pre= schema.List(
150        title = _(u'Beds for Pre-Study Students'),
151        value_type = schema.Choice(
152            vocabulary = bed_letters
153            ),
154        )
155
156    beds_for_fresh = schema.List(
157        title = _(u'Beds for Fresh Students'),
158        value_type = schema.Choice(
159            vocabulary = bed_letters
160            ),
161        )
162
163    beds_for_returning = schema.List(
164        title = _(u'Beds for Returning Students'),
165        value_type = schema.Choice(
166            vocabulary = bed_letters
167            ),
168        )
169
170    beds_for_final = schema.List(
171        title = _(u'Beds for Final Year Students'),
172        value_type = schema.Choice(
173            vocabulary = bed_letters
174            ),
175        )
176
177    beds_for_all = schema.List(
178        title = _(u'Beds without category'),
179        value_type = schema.Choice(
180            vocabulary = bed_letters
181            ),
182        )
183
184    special_handling = schema.Choice(
185        title = _(u'Special Handling'),
186        source = SpecialHandlingSource(),
187        required = True,
188        default = u'regular',
189        )
190
191    maint_fee = schema.Float(
192        title = _(u'Rent'),
193        default = 0.0,
194        required = False,
195        )
196
197    @invariant
198    def blocksOverlap(hostel):
199        bfe = hostel.blocks_for_female
200        bma = hostel.blocks_for_male
201        if set(bfe).intersection(set(bma)):
202            raise Invalid(_('Female and male blocks overlap.'))
203
204    @invariant
205    def bedsOverlap(hostel):
206        beds = (hostel.beds_for_fresh +
207                hostel.beds_for_returning +
208                hostel.beds_for_final +
209                hostel.beds_for_pre +
210                hostel.beds_for_all)
211        if len(beds) != len(set(beds)):
212            raise Invalid(_('Bed categories overlap.'))
213
214    def writeLogMessage(view, message):
215        """Add an INFO message to hostels.log.
216        """
217
218class IBed(IKofaObject):
219    """Representation of a bed.
220    """
221
222    coordinates = Attribute('Coordinates tuple derived from bed_id')
223    hall = Attribute('Hall id, for exporter only')
224    block = Attribute('Block letter, for exporter only')
225    room = Attribute('Room number, for exporter only')
226    bed = Attribute('Bed letter, for exporter only')
227    special_handling = Attribute('Special handling code, for exporter only')
228    sex = Attribute('Sex, for exporter only')
229    bt = Attribute('Last part of bed type, for exporter only')
230
231    def bookBed(student_id):
232        """Book a bed for a student.
233        """
234
235    def switchReservation():
236        """Reserves bed or relases reserved bed respectively.
237        """
238
239    def releaseBedIfMaintenanceNotPaid():
240        """Release bed if maintenance fee has not been paid on time.
241        """
242
243    bed_id = schema.TextLine(
244        title = _(u'Bed Id'),
245        required = True,
246        default = u'',
247        )
248
249    bed_type = schema.TextLine(
250        title = _(u'Bed Type'),
251        required = True,
252        default = u'',
253        )
254
255    bed_number = schema.Int(
256        title = _(u'Bed Number'),
257        required = True,
258        )
259
260    owner = schema.TextLine(
261        title = _(u'Owner (Student)'),
262        description = _('Enter valid student id.'),
263        required = True,
264        default = u'',
265        )
266
267    @invariant
268    def allowed_owners(bed):
269        if bed.owner == NOT_OCCUPIED:
270            return
271        catalog = getUtility(ICatalog, name='students_catalog')
272        accommodation_session = getSite()['hostels'].accommodation_session
273        students = catalog.searchResults(current_session=(
274            accommodation_session,accommodation_session))
275        student_ids = [student.student_id for student in students]
276        if not bed.owner in student_ids:
277            raise Invalid(_(
278                "Either student does not exist or student "
279                "is not in accommodation session."))
280        catalog = getUtility(ICatalog, name='beds_catalog')
281        beds = catalog.searchResults(owner=(bed.owner,bed.owner))
282        if len(beds):
283            allocated_bed = [bed.bed_id for bed in beds][0]
284            raise Invalid(_(
285                "This student resides in bed ${a}.",
286                mapping = {'a':allocated_bed}))
287
288    def writeLogMessage(view, message):
289        """Add an INFO message to hostels.log.
290        """
Note: See TracBrowser for help on using the repository browser.