[7195] | 1 | ## $Id: interfaces.py 7257 2011-12-03 05:56:47Z 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 | ## |
---|
[7257] | 18 | from zope.interface import invariant, Invalid |
---|
[6951] | 19 | from zope import schema |
---|
| 20 | from waeup.sirp.interfaces import IWAeUPObject |
---|
[6970] | 21 | from waeup.sirp.hostels.vocabularies import ( |
---|
[7068] | 22 | bed_letters, blocks, special_handling, StudentSource) |
---|
[6951] | 23 | |
---|
| 24 | class IHostelsContainer(IWAeUPObject): |
---|
| 25 | """A container for all kind of hostel objects. |
---|
| 26 | |
---|
| 27 | """ |
---|
| 28 | |
---|
| 29 | class IHostel(IWAeUPObject): |
---|
| 30 | """A base representation of hostels. |
---|
| 31 | |
---|
| 32 | """ |
---|
[6952] | 33 | |
---|
| 34 | def loggerInfo(ob_class, comment): |
---|
| 35 | """Adds an INFO message to the log file |
---|
| 36 | """ |
---|
| 37 | |
---|
[6970] | 38 | def updateBeds(): |
---|
| 39 | """Fill hostel with beds or update beds. |
---|
| 40 | """ |
---|
| 41 | |
---|
[6952] | 42 | hostel_id = schema.TextLine( |
---|
[6956] | 43 | title = u'Hostel Id', |
---|
| 44 | readonly = True, |
---|
| 45 | ) |
---|
| 46 | |
---|
| 47 | sort_id = schema.Int( |
---|
| 48 | title = u'Sort Id', |
---|
[6954] | 49 | required = True, |
---|
[6956] | 50 | default = 10, |
---|
| 51 | ) |
---|
| 52 | |
---|
| 53 | hostel_name = schema.TextLine( |
---|
| 54 | title = u'Hall Name', |
---|
| 55 | required = True, |
---|
[6959] | 56 | default = u'Hall 1', |
---|
[6956] | 57 | ) |
---|
| 58 | |
---|
[6959] | 59 | floors_per_block = schema.Int( |
---|
| 60 | title = u'Floors per Block', |
---|
[6956] | 61 | required = True, |
---|
[6971] | 62 | default = 1, |
---|
[6956] | 63 | ) |
---|
| 64 | |
---|
| 65 | rooms_per_floor = schema.Int( |
---|
[6958] | 66 | title = u'Rooms per Floor', |
---|
[6956] | 67 | required = True, |
---|
[6971] | 68 | default = 2, |
---|
[6956] | 69 | ) |
---|
| 70 | |
---|
[6976] | 71 | beds_reserved = schema.List( |
---|
[6975] | 72 | title = u'Reserved Beds', |
---|
| 73 | value_type = schema.TextLine( |
---|
| 74 | default = u'', |
---|
| 75 | required = False, |
---|
| 76 | ), |
---|
| 77 | required = True, |
---|
| 78 | readonly = False, |
---|
| 79 | default = [], |
---|
| 80 | ) |
---|
| 81 | |
---|
[6958] | 82 | blocks_for_female = schema.List( |
---|
| 83 | title = u'Blocks for Female Students', |
---|
| 84 | value_type = schema.Choice( |
---|
| 85 | vocabulary = blocks |
---|
| 86 | ), |
---|
| 87 | ) |
---|
| 88 | |
---|
[6970] | 89 | blocks_for_male = schema.List( |
---|
| 90 | title = u'Blocks for Male Students', |
---|
| 91 | value_type = schema.Choice( |
---|
| 92 | vocabulary = blocks |
---|
| 93 | ), |
---|
| 94 | ) |
---|
| 95 | |
---|
[6958] | 96 | beds_for_fresh = schema.List( |
---|
| 97 | title = u'Beds for Fresh Students', |
---|
| 98 | value_type = schema.Choice( |
---|
| 99 | vocabulary = bed_letters |
---|
| 100 | ), |
---|
| 101 | ) |
---|
| 102 | |
---|
[6970] | 103 | beds_for_returning = schema.List( |
---|
| 104 | title = u'Beds for Returning Students', |
---|
| 105 | value_type = schema.Choice( |
---|
| 106 | vocabulary = bed_letters |
---|
| 107 | ), |
---|
| 108 | ) |
---|
| 109 | |
---|
[6958] | 110 | beds_for_final = schema.List( |
---|
| 111 | title = u'Beds for Final Year Students', |
---|
| 112 | value_type = schema.Choice( |
---|
| 113 | vocabulary = bed_letters |
---|
| 114 | ), |
---|
| 115 | ) |
---|
[6963] | 116 | |
---|
[6971] | 117 | beds_for_all = schema.List( |
---|
| 118 | title = u'Beds without category', |
---|
| 119 | value_type = schema.Choice( |
---|
| 120 | vocabulary = bed_letters |
---|
| 121 | ), |
---|
| 122 | ) |
---|
| 123 | |
---|
[6970] | 124 | special_handling = schema.Choice( |
---|
| 125 | title = u'Special Handling', |
---|
| 126 | vocabulary = special_handling, |
---|
| 127 | required = True, |
---|
[6973] | 128 | default = u'regular', |
---|
[6970] | 129 | ) |
---|
| 130 | |
---|
| 131 | @invariant |
---|
| 132 | def blocksOverlap(hostel): |
---|
| 133 | bfe = hostel.blocks_for_female |
---|
| 134 | bma = hostel.blocks_for_male |
---|
| 135 | if set(bfe).intersection(set(bma)): |
---|
| 136 | raise Invalid('Female and male blocks overlap.') |
---|
| 137 | |
---|
| 138 | @invariant |
---|
| 139 | def bedsOverlap(hostel): |
---|
[6981] | 140 | beds = (hostel.beds_for_fresh + |
---|
| 141 | hostel.beds_for_returning + |
---|
| 142 | hostel.beds_for_final + |
---|
| 143 | hostel.beds_for_all) |
---|
| 144 | if len(beds) != len(set(beds)): |
---|
[6970] | 145 | raise Invalid('Bed categories overlap.') |
---|
| 146 | |
---|
[6963] | 147 | class IBed(IWAeUPObject): |
---|
| 148 | """A base representation of beds. |
---|
| 149 | |
---|
| 150 | """ |
---|
| 151 | |
---|
| 152 | def loggerInfo(ob_class, comment): |
---|
| 153 | """Adds an INFO message to the log file |
---|
| 154 | """ |
---|
| 155 | |
---|
| 156 | def getBedCoordinates(): |
---|
| 157 | """Determine the coordinates from bed_id. |
---|
| 158 | """ |
---|
[6996] | 159 | def bookBed(student_id): |
---|
| 160 | """Book a bed for a student. |
---|
| 161 | """ |
---|
[6963] | 162 | |
---|
[6974] | 163 | def switchReservation(): |
---|
| 164 | """Reserves bed or relases reserved bed respectively. |
---|
| 165 | """ |
---|
| 166 | |
---|
[6963] | 167 | bed_id = schema.TextLine( |
---|
| 168 | title = u'Bed Id', |
---|
| 169 | required = True, |
---|
| 170 | default = u'', |
---|
| 171 | ) |
---|
| 172 | |
---|
| 173 | bed_type = schema.TextLine( |
---|
| 174 | title = u'Bed Type', |
---|
| 175 | required = True, |
---|
| 176 | default = u'', |
---|
| 177 | ) |
---|
| 178 | |
---|
[6971] | 179 | bed_number = schema.Int( |
---|
| 180 | title = u'Bed Number', |
---|
[6963] | 181 | required = True, |
---|
| 182 | ) |
---|
| 183 | |
---|
| 184 | owner = schema.TextLine( |
---|
| 185 | title = u'Owner (Student)', |
---|
| 186 | required = True, |
---|
| 187 | default = u'', |
---|
| 188 | ) |
---|
[7068] | 189 | |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | class IBedAllocateStudent(IBed): |
---|
| 193 | """A representation of beds for allocation form only. |
---|
| 194 | |
---|
| 195 | """ |
---|
| 196 | |
---|
| 197 | owner = schema.Choice( |
---|
| 198 | title = u'Owner (Student)', |
---|
| 199 | source = StudentSource(), |
---|
| 200 | default = None, |
---|
| 201 | required = True, |
---|
| 202 | ) |
---|