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

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

Merge changes from trunk r9171:9207.

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