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

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

Do not allow that students can be removed from a bed by using the BedManageFormPage?.

  • Property svn:keywords set to Id
File size: 7.3 KB
RevLine 
[7195]1## $Id: interfaces.py 9416 2012-10-25 11:41:19Z 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##
[9414]18from  grok import getSite
[8685]19from datetime import datetime
[9414]20from zope.component import getUtility
21from zope.catalog.interfaces import ICatalog
[9196]22from zope.interface import invariant, Invalid, Attribute
[6951]23from zope import schema
[8685]24from waeup.kofa.interfaces import (
25    IKofaObject, academic_sessions_vocab, registration_states_vocab)
[7811]26from waeup.kofa.interfaces import MessageFactory as _
27from waeup.kofa.hostels.vocabularies import (
[9414]28    bed_letters, blocks, SpecialHandlingSource,
29    NOT_OCCUPIED)
[6951]30
[7819]31class IHostelsContainer(IKofaObject):
[6951]32    """A container for all kind of hostel objects.
33
34    """
35
[8685]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
[9197]64    def clearAllHostels():
65        """Clear all hostels.
66        """
67
[7819]68class IHostel(IKofaObject):
[6951]69    """A base representation of hostels.
70
71    """
[6952]72
[9196]73    bed_statistics = Attribute('Number of booked and total beds')
74
[6952]75    def loggerInfo(ob_class, comment):
76        """Adds an INFO message to the log file
77        """
78
[9196]79    def clearHostel():
80        """Remove all beds.
81        """
82
[6970]83    def updateBeds():
84        """Fill hostel with beds or update beds.
85        """
86
[6952]87    hostel_id = schema.TextLine(
[7718]88        title = _(u'Hostel Id'),
[6956]89        readonly = True,
90        )
91
92    sort_id = schema.Int(
[7718]93        title = _(u'Sort Id'),
[6954]94        required = True,
[6956]95        default = 10,
96        )
97
98    hostel_name = schema.TextLine(
[7718]99        title = _(u'Hostel Name'),
[6956]100        required = True,
[6959]101        default = u'Hall 1',
[6956]102        )
103
[6959]104    floors_per_block = schema.Int(
[7718]105        title = _(u'Floors per Block'),
[6956]106        required = True,
[6971]107        default = 1,
[6956]108        )
109
110    rooms_per_floor = schema.Int(
[7718]111        title = _(u'Rooms per Floor'),
[6956]112        required = True,
[6971]113        default = 2,
[6956]114        )
115
[6976]116    beds_reserved = schema.List(
[7718]117        title = _(u'Reserved Beds'),
[6975]118        value_type = schema.TextLine(
119            default = u'',
120            required = False,
121        ),
122        required = True,
123        readonly = False,
124        default = [],
125        )
126
[6958]127    blocks_for_female = schema.List(
[7718]128        title = _(u'Blocks for Female Students'),
[6958]129        value_type = schema.Choice(
130            vocabulary = blocks
131            ),
132        )
133
[6970]134    blocks_for_male = schema.List(
[7718]135        title = _(u'Blocks for Male Students'),
[6970]136        value_type = schema.Choice(
137            vocabulary = blocks
138            ),
139        )
140
[9146]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
[6958]148    beds_for_fresh = schema.List(
[7718]149        title = _(u'Beds for Fresh Students'),
[6958]150        value_type = schema.Choice(
151            vocabulary = bed_letters
152            ),
153        )
154
[6970]155    beds_for_returning = schema.List(
[7718]156        title = _(u'Beds for Returning Students'),
[6970]157        value_type = schema.Choice(
158            vocabulary = bed_letters
159            ),
160        )
161
[6958]162    beds_for_final = schema.List(
[7718]163        title = _(u'Beds for Final Year Students'),
[6958]164        value_type = schema.Choice(
165            vocabulary = bed_letters
166            ),
167        )
[6963]168
[6971]169    beds_for_all = schema.List(
[7718]170        title = _(u'Beds without category'),
[6971]171        value_type = schema.Choice(
172            vocabulary = bed_letters
173            ),
174        )
175
[6970]176    special_handling = schema.Choice(
[7718]177        title = _(u'Special Handling'),
[9400]178        source = SpecialHandlingSource(),
[6970]179        required = True,
[6973]180        default = u'regular',
[6970]181        )
182
183    @invariant
184    def blocksOverlap(hostel):
185        bfe = hostel.blocks_for_female
186        bma = hostel.blocks_for_male
187        if set(bfe).intersection(set(bma)):
[7718]188            raise Invalid(_('Female and male blocks overlap.'))
[6970]189
190    @invariant
191    def bedsOverlap(hostel):
[6981]192        beds = (hostel.beds_for_fresh +
193                hostel.beds_for_returning +
194                hostel.beds_for_final +
[9146]195                hostel.beds_for_pre +
[6981]196                hostel.beds_for_all)
197        if len(beds) != len(set(beds)):
[7718]198            raise Invalid(_('Bed categories overlap.'))
[6970]199
[7819]200class IBed(IKofaObject):
[6963]201    """A base representation of beds.
202
203    """
204
[9199]205    coordinates = Attribute('The coordinates of the bed from bed_id')
206
[6963]207    def loggerInfo(ob_class, comment):
208        """Adds an INFO message to the log file
209        """
210
[6996]211    def bookBed(student_id):
212        """Book a bed for a student.
213        """
[6963]214
[6974]215    def switchReservation():
216        """Reserves bed or relases reserved bed respectively.
217        """
218
[6963]219    bed_id = schema.TextLine(
[7718]220        title = _(u'Bed Id'),
[6963]221        required = True,
222        default = u'',
223        )
224
225    bed_type = schema.TextLine(
[7718]226        title = _(u'Bed Type'),
[6963]227        required = True,
228        default = u'',
229        )
230
[6971]231    bed_number = schema.Int(
[7718]232        title = _(u'Bed Number'),
[6963]233        required = True,
234        )
235
236    owner = schema.TextLine(
[7718]237        title = _(u'Owner (Student)'),
[9416]238        description = _('Enter valid student id.'),
[6963]239        required = True,
240        default = u'',
241        )
[7068]242
[9414]243    @invariant
244    def allowed_owners(bed):
245        if bed.owner == NOT_OCCUPIED:
246            return
247        catalog = getUtility(ICatalog, name='students_catalog')
248        accommodation_session = getSite()['hostels'].accommodation_session
249        students = catalog.searchResults(current_session=(
250            accommodation_session,accommodation_session))
251        student_ids = [student.student_id for student in students]
252        if not bed.owner in student_ids:
253            raise Invalid(_(
[9416]254                "Either student does not exist or student "
255                "is not in accommodation session."))
[9414]256        catalog = getUtility(ICatalog, name='beds_catalog')
257        beds = catalog.searchResults(owner=(bed.owner,bed.owner))
258        if len(beds):
259            allocated_bed = [bed.bed_id for bed in beds][0]
260            raise Invalid(_(
261                "This student resides in bed ${a}.", mapping = {'a':allocated_bed}))
Note: See TracBrowser for help on using the repository browser.