source: main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/hostels/interfaces.py @ 8916

Last change on this file since 8916 was 8685, checked in by Henrik Bettermann, 12 years ago

Add hostel allocation start end end date attributes to hostels.

Move hostel allocation parameters from configuration to hostels. AccommodationOfficer? must be able to edit these parameters.

  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
1## $Id: interfaces.py 8685 2012-06-12 07:17:01Z 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 datetime import datetime
19from zope.interface import invariant, Invalid
20from zope import schema
21from waeup.kofa.interfaces import (
22    IKofaObject, academic_sessions_vocab, registration_states_vocab)
23from waeup.kofa.interfaces import MessageFactory as _
24from waeup.kofa.hostels.vocabularies import (
25    bed_letters, blocks, special_handling, StudentSource)
26
27class IHostelsContainer(IKofaObject):
28    """A container for all kind of hostel objects.
29
30    """
31
32    startdate = schema.Datetime(
33        title = _(u'Hostel Allocation Start Date'),
34        required = False,
35        description = _('Example:') + u'2011-12-01 18:30:00+01:00',
36        )
37
38    enddate = schema.Datetime(
39        title = _(u'Hostel Allocation Closing Date'),
40        required = False,
41        description = _('Example:') + u'2011-12-31 23:59:59+01:00',
42        )
43
44    accommodation_session = schema.Choice(
45        title = _(u'Booking Session'),
46        source = academic_sessions_vocab,
47        default = datetime.now().year,
48        required = False,
49        readonly = False,
50        )
51
52    accommodation_states = schema.List(
53        title = _(u'Allowed States'),
54        value_type = schema.Choice(
55            vocabulary = registration_states_vocab,
56            ),
57        default = [],
58        )
59
60class IHostel(IKofaObject):
61    """A base representation of hostels.
62
63    """
64
65    def loggerInfo(ob_class, comment):
66        """Adds an INFO message to the log file
67        """
68
69    def updateBeds():
70        """Fill hostel with beds or update beds.
71        """
72
73    hostel_id = schema.TextLine(
74        title = _(u'Hostel Id'),
75        readonly = True,
76        )
77
78    sort_id = schema.Int(
79        title = _(u'Sort Id'),
80        required = True,
81        default = 10,
82        )
83
84    hostel_name = schema.TextLine(
85        title = _(u'Hostel Name'),
86        required = True,
87        default = u'Hall 1',
88        )
89
90    floors_per_block = schema.Int(
91        title = _(u'Floors per Block'),
92        required = True,
93        default = 1,
94        )
95
96    rooms_per_floor = schema.Int(
97        title = _(u'Rooms per Floor'),
98        required = True,
99        default = 2,
100        )
101
102    beds_reserved = schema.List(
103        title = _(u'Reserved Beds'),
104        value_type = schema.TextLine(
105            default = u'',
106            required = False,
107        ),
108        required = True,
109        readonly = False,
110        default = [],
111        )
112
113    blocks_for_female = schema.List(
114        title = _(u'Blocks for Female Students'),
115        value_type = schema.Choice(
116            vocabulary = blocks
117            ),
118        )
119
120    blocks_for_male = schema.List(
121        title = _(u'Blocks for Male Students'),
122        value_type = schema.Choice(
123            vocabulary = blocks
124            ),
125        )
126
127    beds_for_fresh = schema.List(
128        title = _(u'Beds for Fresh Students'),
129        value_type = schema.Choice(
130            vocabulary = bed_letters
131            ),
132        )
133
134    beds_for_returning = schema.List(
135        title = _(u'Beds for Returning Students'),
136        value_type = schema.Choice(
137            vocabulary = bed_letters
138            ),
139        )
140
141    beds_for_final = schema.List(
142        title = _(u'Beds for Final Year Students'),
143        value_type = schema.Choice(
144            vocabulary = bed_letters
145            ),
146        )
147
148    beds_for_all = schema.List(
149        title = _(u'Beds without category'),
150        value_type = schema.Choice(
151            vocabulary = bed_letters
152            ),
153        )
154
155    special_handling = schema.Choice(
156        title = _(u'Special Handling'),
157        vocabulary = special_handling,
158        required = True,
159        default = u'regular',
160        )
161
162    @invariant
163    def blocksOverlap(hostel):
164        bfe = hostel.blocks_for_female
165        bma = hostel.blocks_for_male
166        if set(bfe).intersection(set(bma)):
167            raise Invalid(_('Female and male blocks overlap.'))
168
169    @invariant
170    def bedsOverlap(hostel):
171        beds = (hostel.beds_for_fresh +
172                hostel.beds_for_returning +
173                hostel.beds_for_final +
174                hostel.beds_for_all)
175        if len(beds) != len(set(beds)):
176            raise Invalid(_('Bed categories overlap.'))
177
178class IBed(IKofaObject):
179    """A base representation of beds.
180
181    """
182
183    def loggerInfo(ob_class, comment):
184        """Adds an INFO message to the log file
185        """
186
187    def getBedCoordinates():
188        """Determine the coordinates from bed_id.
189        """
190    def bookBed(student_id):
191        """Book a bed for a student.
192        """
193
194    def switchReservation():
195        """Reserves bed or relases reserved bed respectively.
196        """
197
198    bed_id = schema.TextLine(
199        title = _(u'Bed Id'),
200        required = True,
201        default = u'',
202        )
203
204    bed_type = schema.TextLine(
205        title = _(u'Bed Type'),
206        required = True,
207        default = u'',
208        )
209
210    bed_number = schema.Int(
211        title = _(u'Bed Number'),
212        required = True,
213        )
214
215    owner = schema.TextLine(
216        title = _(u'Owner (Student)'),
217        required = True,
218        default = u'',
219        )
220
221
222
223class IBedAllocateStudent(IBed):
224    """A representation of beds for allocation form only.
225
226    """
227
228    owner = schema.Choice(
229        title = _(u'Owner (Student)'),
230        source = StudentSource(),
231        default = None,
232        required = True,
233        )
Note: See TracBrowser for help on using the repository browser.