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

Last change on this file since 10681 was 10680, checked in by Henrik Bettermann, 11 years ago

Extend IHostel so that we can configure maintenance fee for each hostel.

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