1 | ## $Id: interfaces.py 7321 2011-12-10 06:15:17Z henrik $ |
---|
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 zope.interface import invariant, Invalid |
---|
19 | from zope import schema |
---|
20 | from waeup.sirp.interfaces import ISIRPObject |
---|
21 | from waeup.sirp.hostels.vocabularies import ( |
---|
22 | bed_letters, blocks, special_handling, StudentSource) |
---|
23 | |
---|
24 | class IHostelsContainer(ISIRPObject): |
---|
25 | """A container for all kind of hostel objects. |
---|
26 | |
---|
27 | """ |
---|
28 | |
---|
29 | class IHostel(ISIRPObject): |
---|
30 | """A base representation of hostels. |
---|
31 | |
---|
32 | """ |
---|
33 | |
---|
34 | def loggerInfo(ob_class, comment): |
---|
35 | """Adds an INFO message to the log file |
---|
36 | """ |
---|
37 | |
---|
38 | def updateBeds(): |
---|
39 | """Fill hostel with beds or update beds. |
---|
40 | """ |
---|
41 | |
---|
42 | hostel_id = schema.TextLine( |
---|
43 | title = u'Hostel Id', |
---|
44 | readonly = True, |
---|
45 | ) |
---|
46 | |
---|
47 | sort_id = schema.Int( |
---|
48 | title = u'Sort Id', |
---|
49 | required = True, |
---|
50 | default = 10, |
---|
51 | ) |
---|
52 | |
---|
53 | hostel_name = schema.TextLine( |
---|
54 | title = u'Hall Name', |
---|
55 | required = True, |
---|
56 | default = u'Hall 1', |
---|
57 | ) |
---|
58 | |
---|
59 | floors_per_block = schema.Int( |
---|
60 | title = u'Floors per Block', |
---|
61 | required = True, |
---|
62 | default = 1, |
---|
63 | ) |
---|
64 | |
---|
65 | rooms_per_floor = schema.Int( |
---|
66 | title = u'Rooms per Floor', |
---|
67 | required = True, |
---|
68 | default = 2, |
---|
69 | ) |
---|
70 | |
---|
71 | beds_reserved = schema.List( |
---|
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 | |
---|
82 | blocks_for_female = schema.List( |
---|
83 | title = u'Blocks for Female Students', |
---|
84 | value_type = schema.Choice( |
---|
85 | vocabulary = blocks |
---|
86 | ), |
---|
87 | ) |
---|
88 | |
---|
89 | blocks_for_male = schema.List( |
---|
90 | title = u'Blocks for Male Students', |
---|
91 | value_type = schema.Choice( |
---|
92 | vocabulary = blocks |
---|
93 | ), |
---|
94 | ) |
---|
95 | |
---|
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 | |
---|
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 | |
---|
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 | ) |
---|
116 | |
---|
117 | beds_for_all = schema.List( |
---|
118 | title = u'Beds without category', |
---|
119 | value_type = schema.Choice( |
---|
120 | vocabulary = bed_letters |
---|
121 | ), |
---|
122 | ) |
---|
123 | |
---|
124 | special_handling = schema.Choice( |
---|
125 | title = u'Special Handling', |
---|
126 | vocabulary = special_handling, |
---|
127 | required = True, |
---|
128 | default = u'regular', |
---|
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): |
---|
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)): |
---|
145 | raise Invalid('Bed categories overlap.') |
---|
146 | |
---|
147 | class IBed(ISIRPObject): |
---|
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 | """ |
---|
159 | def bookBed(student_id): |
---|
160 | """Book a bed for a student. |
---|
161 | """ |
---|
162 | |
---|
163 | def switchReservation(): |
---|
164 | """Reserves bed or relases reserved bed respectively. |
---|
165 | """ |
---|
166 | |
---|
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 | |
---|
179 | bed_number = schema.Int( |
---|
180 | title = u'Bed Number', |
---|
181 | required = True, |
---|
182 | ) |
---|
183 | |
---|
184 | owner = schema.TextLine( |
---|
185 | title = u'Owner (Student)', |
---|
186 | required = True, |
---|
187 | default = u'', |
---|
188 | ) |
---|
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 | ) |
---|