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