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

Last change on this file since 11003 was 10683, checked in by Henrik Bettermann, 11 years ago

hostel_id must not be readonly. Otherwise updateEntry doesn't work in update mode.

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