1 | ## $Id: interfaces.py 9208 2012-09-20 08:22:52Z uli $ |
---|
2 | ## |
---|
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 | ## |
---|
18 | from datetime import datetime |
---|
19 | from zope.interface import invariant, Invalid, Attribute |
---|
20 | from zope import schema |
---|
21 | from waeup.kofa.interfaces import ( |
---|
22 | IKofaObject, academic_sessions_vocab, registration_states_vocab) |
---|
23 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
24 | from waeup.kofa.hostels.vocabularies import ( |
---|
25 | bed_letters, blocks, special_handling, StudentSource) |
---|
26 | |
---|
27 | class IHostelsContainer(IKofaObject): |
---|
28 | """A container for all kind of hostel objects. |
---|
29 | |
---|
30 | """ |
---|
31 | |
---|
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 | |
---|
60 | def clearAllHostels(): |
---|
61 | """Clear all hostels. |
---|
62 | """ |
---|
63 | |
---|
64 | class IHostel(IKofaObject): |
---|
65 | """A base representation of hostels. |
---|
66 | |
---|
67 | """ |
---|
68 | |
---|
69 | bed_statistics = Attribute('Number of booked and total beds') |
---|
70 | |
---|
71 | def loggerInfo(ob_class, comment): |
---|
72 | """Adds an INFO message to the log file |
---|
73 | """ |
---|
74 | |
---|
75 | def clearHostel(): |
---|
76 | """Remove all beds. |
---|
77 | """ |
---|
78 | |
---|
79 | def updateBeds(): |
---|
80 | """Fill hostel with beds or update beds. |
---|
81 | """ |
---|
82 | |
---|
83 | hostel_id = schema.TextLine( |
---|
84 | title = _(u'Hostel Id'), |
---|
85 | readonly = True, |
---|
86 | ) |
---|
87 | |
---|
88 | sort_id = schema.Int( |
---|
89 | title = _(u'Sort Id'), |
---|
90 | required = True, |
---|
91 | default = 10, |
---|
92 | ) |
---|
93 | |
---|
94 | hostel_name = schema.TextLine( |
---|
95 | title = _(u'Hostel Name'), |
---|
96 | required = True, |
---|
97 | default = u'Hall 1', |
---|
98 | ) |
---|
99 | |
---|
100 | floors_per_block = schema.Int( |
---|
101 | title = _(u'Floors per Block'), |
---|
102 | required = True, |
---|
103 | default = 1, |
---|
104 | ) |
---|
105 | |
---|
106 | rooms_per_floor = schema.Int( |
---|
107 | title = _(u'Rooms per Floor'), |
---|
108 | required = True, |
---|
109 | default = 2, |
---|
110 | ) |
---|
111 | |
---|
112 | beds_reserved = schema.List( |
---|
113 | title = _(u'Reserved Beds'), |
---|
114 | value_type = schema.TextLine( |
---|
115 | default = u'', |
---|
116 | required = False, |
---|
117 | ), |
---|
118 | required = True, |
---|
119 | readonly = False, |
---|
120 | default = [], |
---|
121 | ) |
---|
122 | |
---|
123 | blocks_for_female = schema.List( |
---|
124 | title = _(u'Blocks for Female Students'), |
---|
125 | value_type = schema.Choice( |
---|
126 | vocabulary = blocks |
---|
127 | ), |
---|
128 | ) |
---|
129 | |
---|
130 | blocks_for_male = schema.List( |
---|
131 | title = _(u'Blocks for Male Students'), |
---|
132 | value_type = schema.Choice( |
---|
133 | vocabulary = blocks |
---|
134 | ), |
---|
135 | ) |
---|
136 | |
---|
137 | beds_for_pre= schema.List( |
---|
138 | title = _(u'Beds for Pre-Study Students'), |
---|
139 | value_type = schema.Choice( |
---|
140 | vocabulary = bed_letters |
---|
141 | ), |
---|
142 | ) |
---|
143 | |
---|
144 | beds_for_fresh = schema.List( |
---|
145 | title = _(u'Beds for Fresh Students'), |
---|
146 | value_type = schema.Choice( |
---|
147 | vocabulary = bed_letters |
---|
148 | ), |
---|
149 | ) |
---|
150 | |
---|
151 | beds_for_returning = schema.List( |
---|
152 | title = _(u'Beds for Returning Students'), |
---|
153 | value_type = schema.Choice( |
---|
154 | vocabulary = bed_letters |
---|
155 | ), |
---|
156 | ) |
---|
157 | |
---|
158 | beds_for_final = schema.List( |
---|
159 | title = _(u'Beds for Final Year Students'), |
---|
160 | value_type = schema.Choice( |
---|
161 | vocabulary = bed_letters |
---|
162 | ), |
---|
163 | ) |
---|
164 | |
---|
165 | beds_for_all = schema.List( |
---|
166 | title = _(u'Beds without category'), |
---|
167 | value_type = schema.Choice( |
---|
168 | vocabulary = bed_letters |
---|
169 | ), |
---|
170 | ) |
---|
171 | |
---|
172 | special_handling = schema.Choice( |
---|
173 | title = _(u'Special Handling'), |
---|
174 | vocabulary = special_handling, |
---|
175 | required = True, |
---|
176 | default = u'regular', |
---|
177 | ) |
---|
178 | |
---|
179 | @invariant |
---|
180 | def blocksOverlap(hostel): |
---|
181 | bfe = hostel.blocks_for_female |
---|
182 | bma = hostel.blocks_for_male |
---|
183 | if set(bfe).intersection(set(bma)): |
---|
184 | raise Invalid(_('Female and male blocks overlap.')) |
---|
185 | |
---|
186 | @invariant |
---|
187 | def bedsOverlap(hostel): |
---|
188 | beds = (hostel.beds_for_fresh + |
---|
189 | hostel.beds_for_returning + |
---|
190 | hostel.beds_for_final + |
---|
191 | hostel.beds_for_pre + |
---|
192 | hostel.beds_for_all) |
---|
193 | if len(beds) != len(set(beds)): |
---|
194 | raise Invalid(_('Bed categories overlap.')) |
---|
195 | |
---|
196 | class IBed(IKofaObject): |
---|
197 | """A base representation of beds. |
---|
198 | |
---|
199 | """ |
---|
200 | |
---|
201 | coordinates = Attribute('The coordinates of the bed from bed_id') |
---|
202 | |
---|
203 | def loggerInfo(ob_class, comment): |
---|
204 | """Adds an INFO message to the log file |
---|
205 | """ |
---|
206 | |
---|
207 | def bookBed(student_id): |
---|
208 | """Book a bed for a student. |
---|
209 | """ |
---|
210 | |
---|
211 | def switchReservation(): |
---|
212 | """Reserves bed or relases reserved bed respectively. |
---|
213 | """ |
---|
214 | |
---|
215 | bed_id = schema.TextLine( |
---|
216 | title = _(u'Bed Id'), |
---|
217 | required = True, |
---|
218 | default = u'', |
---|
219 | ) |
---|
220 | |
---|
221 | bed_type = schema.TextLine( |
---|
222 | title = _(u'Bed Type'), |
---|
223 | required = True, |
---|
224 | default = u'', |
---|
225 | ) |
---|
226 | |
---|
227 | bed_number = schema.Int( |
---|
228 | title = _(u'Bed Number'), |
---|
229 | required = True, |
---|
230 | ) |
---|
231 | |
---|
232 | owner = schema.TextLine( |
---|
233 | title = _(u'Owner (Student)'), |
---|
234 | required = True, |
---|
235 | default = u'', |
---|
236 | ) |
---|
237 | |
---|
238 | |
---|
239 | |
---|
240 | class IBedAllocateStudent(IBed): |
---|
241 | """A representation of beds for allocation form only. |
---|
242 | |
---|
243 | """ |
---|
244 | |
---|
245 | owner = schema.Choice( |
---|
246 | title = _(u'Owner (Student)'), |
---|
247 | source = StudentSource(), |
---|
248 | default = None, |
---|
249 | required = True, |
---|
250 | ) |
---|