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

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

Remove non-implemented methods.

Add methods to hostel section interfaces.

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