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

Last change on this file since 9169 was 9169, checked in by uli, 12 years ago

Merge changes from trunk, r8786-HEAD

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1## $Id: interfaces.py 9169 2012-09-10 11:05:07Z uli $
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_pre= schema.List(
128        title = _(u'Beds for Pre-Study Students'),
129        value_type = schema.Choice(
130            vocabulary = bed_letters
131            ),
132        )
133
134    beds_for_fresh = schema.List(
135        title = _(u'Beds for Fresh Students'),
136        value_type = schema.Choice(
137            vocabulary = bed_letters
138            ),
139        )
140
141    beds_for_returning = schema.List(
142        title = _(u'Beds for Returning Students'),
143        value_type = schema.Choice(
144            vocabulary = bed_letters
145            ),
146        )
147
148    beds_for_final = schema.List(
149        title = _(u'Beds for Final Year Students'),
150        value_type = schema.Choice(
151            vocabulary = bed_letters
152            ),
153        )
154
155    beds_for_all = schema.List(
156        title = _(u'Beds without category'),
157        value_type = schema.Choice(
158            vocabulary = bed_letters
159            ),
160        )
161
162    special_handling = schema.Choice(
163        title = _(u'Special Handling'),
164        vocabulary = special_handling,
165        required = True,
166        default = u'regular',
167        )
168
169    @invariant
170    def blocksOverlap(hostel):
171        bfe = hostel.blocks_for_female
172        bma = hostel.blocks_for_male
173        if set(bfe).intersection(set(bma)):
174            raise Invalid(_('Female and male blocks overlap.'))
175
176    @invariant
177    def bedsOverlap(hostel):
178        beds = (hostel.beds_for_fresh +
179                hostel.beds_for_returning +
180                hostel.beds_for_final +
181                hostel.beds_for_pre +
182                hostel.beds_for_all)
183        if len(beds) != len(set(beds)):
184            raise Invalid(_('Bed categories overlap.'))
185
186class IBed(IKofaObject):
187    """A base representation of beds.
188
189    """
190
191    def loggerInfo(ob_class, comment):
192        """Adds an INFO message to the log file
193        """
194
195    def getBedCoordinates():
196        """Determine the coordinates from bed_id.
197        """
198    def bookBed(student_id):
199        """Book a bed for a student.
200        """
201
202    def switchReservation():
203        """Reserves bed or relases reserved bed respectively.
204        """
205
206    bed_id = schema.TextLine(
207        title = _(u'Bed Id'),
208        required = True,
209        default = u'',
210        )
211
212    bed_type = schema.TextLine(
213        title = _(u'Bed Type'),
214        required = True,
215        default = u'',
216        )
217
218    bed_number = schema.Int(
219        title = _(u'Bed Number'),
220        required = True,
221        )
222
223    owner = schema.TextLine(
224        title = _(u'Owner (Student)'),
225        required = True,
226        default = u'',
227        )
228
229
230
231class IBedAllocateStudent(IBed):
232    """A representation of beds for allocation form only.
233
234    """
235
236    owner = schema.Choice(
237        title = _(u'Owner (Student)'),
238        source = StudentSource(),
239        default = None,
240        required = True,
241        )
Note: See TracBrowser for help on using the repository browser.