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

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

Add pre-study beds to configuration form.

  • Property svn:keywords set to Id
File size: 6.2 KB
RevLine 
[7195]1## $Id: interfaces.py 9146 2012-09-03 10:51:01Z henrik $
[6951]2##
[7195]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##
[8685]18from datetime import datetime
[7257]19from zope.interface import invariant, Invalid
[6951]20from zope import schema
[8685]21from waeup.kofa.interfaces import (
22    IKofaObject, academic_sessions_vocab, registration_states_vocab)
[7811]23from waeup.kofa.interfaces import MessageFactory as _
24from waeup.kofa.hostels.vocabularies import (
[7068]25    bed_letters, blocks, special_handling, StudentSource)
[6951]26
[7819]27class IHostelsContainer(IKofaObject):
[6951]28    """A container for all kind of hostel objects.
29
30    """
31
[8685]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
[7819]60class IHostel(IKofaObject):
[6951]61    """A base representation of hostels.
62
63    """
[6952]64
65    def loggerInfo(ob_class, comment):
66        """Adds an INFO message to the log file
67        """
68
[6970]69    def updateBeds():
70        """Fill hostel with beds or update beds.
71        """
72
[6952]73    hostel_id = schema.TextLine(
[7718]74        title = _(u'Hostel Id'),
[6956]75        readonly = True,
76        )
77
78    sort_id = schema.Int(
[7718]79        title = _(u'Sort Id'),
[6954]80        required = True,
[6956]81        default = 10,
82        )
83
84    hostel_name = schema.TextLine(
[7718]85        title = _(u'Hostel Name'),
[6956]86        required = True,
[6959]87        default = u'Hall 1',
[6956]88        )
89
[6959]90    floors_per_block = schema.Int(
[7718]91        title = _(u'Floors per Block'),
[6956]92        required = True,
[6971]93        default = 1,
[6956]94        )
95
96    rooms_per_floor = schema.Int(
[7718]97        title = _(u'Rooms per Floor'),
[6956]98        required = True,
[6971]99        default = 2,
[6956]100        )
101
[6976]102    beds_reserved = schema.List(
[7718]103        title = _(u'Reserved Beds'),
[6975]104        value_type = schema.TextLine(
105            default = u'',
106            required = False,
107        ),
108        required = True,
109        readonly = False,
110        default = [],
111        )
112
[6958]113    blocks_for_female = schema.List(
[7718]114        title = _(u'Blocks for Female Students'),
[6958]115        value_type = schema.Choice(
116            vocabulary = blocks
117            ),
118        )
119
[6970]120    blocks_for_male = schema.List(
[7718]121        title = _(u'Blocks for Male Students'),
[6970]122        value_type = schema.Choice(
123            vocabulary = blocks
124            ),
125        )
126
[9146]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
[6958]134    beds_for_fresh = schema.List(
[7718]135        title = _(u'Beds for Fresh Students'),
[6958]136        value_type = schema.Choice(
137            vocabulary = bed_letters
138            ),
139        )
140
[6970]141    beds_for_returning = schema.List(
[7718]142        title = _(u'Beds for Returning Students'),
[6970]143        value_type = schema.Choice(
144            vocabulary = bed_letters
145            ),
146        )
147
[6958]148    beds_for_final = schema.List(
[7718]149        title = _(u'Beds for Final Year Students'),
[6958]150        value_type = schema.Choice(
151            vocabulary = bed_letters
152            ),
153        )
[6963]154
[6971]155    beds_for_all = schema.List(
[7718]156        title = _(u'Beds without category'),
[6971]157        value_type = schema.Choice(
158            vocabulary = bed_letters
159            ),
160        )
161
[6970]162    special_handling = schema.Choice(
[7718]163        title = _(u'Special Handling'),
[6970]164        vocabulary = special_handling,
165        required = True,
[6973]166        default = u'regular',
[6970]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)):
[7718]174            raise Invalid(_('Female and male blocks overlap.'))
[6970]175
176    @invariant
177    def bedsOverlap(hostel):
[6981]178        beds = (hostel.beds_for_fresh +
179                hostel.beds_for_returning +
180                hostel.beds_for_final +
[9146]181                hostel.beds_for_pre +
[6981]182                hostel.beds_for_all)
183        if len(beds) != len(set(beds)):
[7718]184            raise Invalid(_('Bed categories overlap.'))
[6970]185
[7819]186class IBed(IKofaObject):
[6963]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        """
[6996]198    def bookBed(student_id):
199        """Book a bed for a student.
200        """
[6963]201
[6974]202    def switchReservation():
203        """Reserves bed or relases reserved bed respectively.
204        """
205
[6963]206    bed_id = schema.TextLine(
[7718]207        title = _(u'Bed Id'),
[6963]208        required = True,
209        default = u'',
210        )
211
212    bed_type = schema.TextLine(
[7718]213        title = _(u'Bed Type'),
[6963]214        required = True,
215        default = u'',
216        )
217
[6971]218    bed_number = schema.Int(
[7718]219        title = _(u'Bed Number'),
[6963]220        required = True,
221        )
222
223    owner = schema.TextLine(
[7718]224        title = _(u'Owner (Student)'),
[6963]225        required = True,
226        default = u'',
227        )
[7068]228
229
230
231class IBedAllocateStudent(IBed):
232    """A representation of beds for allocation form only.
233
234    """
235
236    owner = schema.Choice(
[7718]237        title = _(u'Owner (Student)'),
[7068]238        source = StudentSource(),
239        default = None,
240        required = True,
241        )
Note: See TracBrowser for help on using the repository browser.