[7195] | 1 | ## $Id: interfaces.py 9211 2012-09-21 08:19:35Z 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] | 18 | from datetime import datetime |
---|
[9211] | 19 | from zope.interface import invariant, Invalid |
---|
[6951] | 20 | from zope import schema |
---|
[8685] | 21 | from waeup.kofa.interfaces import ( |
---|
| 22 | IKofaObject, academic_sessions_vocab, registration_states_vocab) |
---|
[7811] | 23 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 24 | from waeup.kofa.hostels.vocabularies import ( |
---|
[7068] | 25 | bed_letters, blocks, special_handling, StudentSource) |
---|
[6951] | 26 | |
---|
[7819] | 27 | class 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] | 60 | class 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 | |
---|
[6958] | 127 | beds_for_fresh = schema.List( |
---|
[7718] | 128 | title = _(u'Beds for Fresh Students'), |
---|
[6958] | 129 | value_type = schema.Choice( |
---|
| 130 | vocabulary = bed_letters |
---|
| 131 | ), |
---|
| 132 | ) |
---|
| 133 | |
---|
[6970] | 134 | beds_for_returning = schema.List( |
---|
[7718] | 135 | title = _(u'Beds for Returning Students'), |
---|
[6970] | 136 | value_type = schema.Choice( |
---|
| 137 | vocabulary = bed_letters |
---|
| 138 | ), |
---|
| 139 | ) |
---|
| 140 | |
---|
[6958] | 141 | beds_for_final = schema.List( |
---|
[7718] | 142 | title = _(u'Beds for Final Year Students'), |
---|
[6958] | 143 | value_type = schema.Choice( |
---|
| 144 | vocabulary = bed_letters |
---|
| 145 | ), |
---|
| 146 | ) |
---|
[6963] | 147 | |
---|
[6971] | 148 | beds_for_all = schema.List( |
---|
[7718] | 149 | title = _(u'Beds without category'), |
---|
[6971] | 150 | value_type = schema.Choice( |
---|
| 151 | vocabulary = bed_letters |
---|
| 152 | ), |
---|
| 153 | ) |
---|
| 154 | |
---|
[6970] | 155 | special_handling = schema.Choice( |
---|
[7718] | 156 | title = _(u'Special Handling'), |
---|
[6970] | 157 | vocabulary = special_handling, |
---|
| 158 | required = True, |
---|
[6973] | 159 | default = u'regular', |
---|
[6970] | 160 | ) |
---|
| 161 | |
---|
| 162 | @invariant |
---|
| 163 | def blocksOverlap(hostel): |
---|
| 164 | bfe = hostel.blocks_for_female |
---|
| 165 | bma = hostel.blocks_for_male |
---|
| 166 | if set(bfe).intersection(set(bma)): |
---|
[7718] | 167 | raise Invalid(_('Female and male blocks overlap.')) |
---|
[6970] | 168 | |
---|
| 169 | @invariant |
---|
| 170 | def bedsOverlap(hostel): |
---|
[6981] | 171 | beds = (hostel.beds_for_fresh + |
---|
| 172 | hostel.beds_for_returning + |
---|
| 173 | hostel.beds_for_final + |
---|
| 174 | hostel.beds_for_all) |
---|
| 175 | if len(beds) != len(set(beds)): |
---|
[7718] | 176 | raise Invalid(_('Bed categories overlap.')) |
---|
[6970] | 177 | |
---|
[7819] | 178 | class IBed(IKofaObject): |
---|
[6963] | 179 | """A base representation of beds. |
---|
| 180 | |
---|
| 181 | """ |
---|
| 182 | |
---|
| 183 | def loggerInfo(ob_class, comment): |
---|
| 184 | """Adds an INFO message to the log file |
---|
| 185 | """ |
---|
| 186 | |
---|
[9211] | 187 | def getBedCoordinates(): |
---|
| 188 | """Determine the coordinates from bed_id. |
---|
| 189 | """ |
---|
[6996] | 190 | def bookBed(student_id): |
---|
| 191 | """Book a bed for a student. |
---|
| 192 | """ |
---|
[6963] | 193 | |
---|
[6974] | 194 | def switchReservation(): |
---|
| 195 | """Reserves bed or relases reserved bed respectively. |
---|
| 196 | """ |
---|
| 197 | |
---|
[6963] | 198 | bed_id = schema.TextLine( |
---|
[7718] | 199 | title = _(u'Bed Id'), |
---|
[6963] | 200 | required = True, |
---|
| 201 | default = u'', |
---|
| 202 | ) |
---|
| 203 | |
---|
| 204 | bed_type = schema.TextLine( |
---|
[7718] | 205 | title = _(u'Bed Type'), |
---|
[6963] | 206 | required = True, |
---|
| 207 | default = u'', |
---|
| 208 | ) |
---|
| 209 | |
---|
[6971] | 210 | bed_number = schema.Int( |
---|
[7718] | 211 | title = _(u'Bed Number'), |
---|
[6963] | 212 | required = True, |
---|
| 213 | ) |
---|
| 214 | |
---|
| 215 | owner = schema.TextLine( |
---|
[7718] | 216 | title = _(u'Owner (Student)'), |
---|
[6963] | 217 | required = True, |
---|
| 218 | default = u'', |
---|
| 219 | ) |
---|
[7068] | 220 | |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | class IBedAllocateStudent(IBed): |
---|
| 224 | """A representation of beds for allocation form only. |
---|
| 225 | |
---|
| 226 | """ |
---|
| 227 | |
---|
| 228 | owner = schema.Choice( |
---|
[7718] | 229 | title = _(u'Owner (Student)'), |
---|
[7068] | 230 | source = StudentSource(), |
---|
| 231 | default = None, |
---|
| 232 | required = True, |
---|
| 233 | ) |
---|