1 | ## |
---|
2 | ## interfaces.py |
---|
3 | from zope.interface import Attribute, invariant, Invalid |
---|
4 | from zope import schema |
---|
5 | from waeup.sirp.interfaces import IWAeUPObject |
---|
6 | from waeup.sirp.hostels.vocabularies import ( |
---|
7 | bed_letters, blocks, special_handling) |
---|
8 | |
---|
9 | class IHostelsContainer(IWAeUPObject): |
---|
10 | """A container for all kind of hostel objects. |
---|
11 | |
---|
12 | """ |
---|
13 | |
---|
14 | class IHostel(IWAeUPObject): |
---|
15 | """A base representation of hostels. |
---|
16 | |
---|
17 | """ |
---|
18 | |
---|
19 | def loggerInfo(ob_class, comment): |
---|
20 | """Adds an INFO message to the log file |
---|
21 | """ |
---|
22 | |
---|
23 | def updateBeds(): |
---|
24 | """Fill hostel with beds or update beds. |
---|
25 | """ |
---|
26 | |
---|
27 | hostel_id = schema.TextLine( |
---|
28 | title = u'Hostel Id', |
---|
29 | readonly = True, |
---|
30 | ) |
---|
31 | |
---|
32 | sort_id = schema.Int( |
---|
33 | title = u'Sort Id', |
---|
34 | required = True, |
---|
35 | default = 10, |
---|
36 | ) |
---|
37 | |
---|
38 | hostel_name = schema.TextLine( |
---|
39 | title = u'Hall Name', |
---|
40 | required = True, |
---|
41 | default = u'Hall 1', |
---|
42 | ) |
---|
43 | |
---|
44 | floors_per_block = schema.Int( |
---|
45 | title = u'Floors per Block', |
---|
46 | required = True, |
---|
47 | default = 3, |
---|
48 | ) |
---|
49 | |
---|
50 | rooms_per_floor = schema.Int( |
---|
51 | title = u'Rooms per Floor', |
---|
52 | required = True, |
---|
53 | default = 20, |
---|
54 | ) |
---|
55 | |
---|
56 | #beds_per_room = schema.Int( |
---|
57 | # title = u'Beds per Room', |
---|
58 | # required = True, |
---|
59 | # default = 6, |
---|
60 | # ) |
---|
61 | |
---|
62 | blocks_for_female = schema.List( |
---|
63 | title = u'Blocks for Female Students', |
---|
64 | value_type = schema.Choice( |
---|
65 | vocabulary = blocks |
---|
66 | ), |
---|
67 | ) |
---|
68 | |
---|
69 | blocks_for_male = schema.List( |
---|
70 | title = u'Blocks for Male Students', |
---|
71 | value_type = schema.Choice( |
---|
72 | vocabulary = blocks |
---|
73 | ), |
---|
74 | ) |
---|
75 | |
---|
76 | beds_for_fresh = schema.List( |
---|
77 | title = u'Beds for Fresh Students', |
---|
78 | value_type = schema.Choice( |
---|
79 | vocabulary = bed_letters |
---|
80 | ), |
---|
81 | ) |
---|
82 | |
---|
83 | beds_for_returning = schema.List( |
---|
84 | title = u'Beds for Returning Students', |
---|
85 | value_type = schema.Choice( |
---|
86 | vocabulary = bed_letters |
---|
87 | ), |
---|
88 | ) |
---|
89 | |
---|
90 | beds_for_final = schema.List( |
---|
91 | title = u'Beds for Final Year Students', |
---|
92 | value_type = schema.Choice( |
---|
93 | vocabulary = bed_letters |
---|
94 | ), |
---|
95 | ) |
---|
96 | |
---|
97 | special_handling = schema.Choice( |
---|
98 | title = u'Special Handling', |
---|
99 | vocabulary = special_handling, |
---|
100 | required = True, |
---|
101 | default = u'none', |
---|
102 | ) |
---|
103 | |
---|
104 | reserved = schema.TextLine( |
---|
105 | title = u'Reserved Rooms', |
---|
106 | required = False, |
---|
107 | default = u'', |
---|
108 | ) |
---|
109 | |
---|
110 | @invariant |
---|
111 | def blocksOverlap(hostel): |
---|
112 | bfe = hostel.blocks_for_female |
---|
113 | bma = hostel.blocks_for_male |
---|
114 | if set(bfe).intersection(set(bma)): |
---|
115 | raise Invalid('Female and male blocks overlap.') |
---|
116 | |
---|
117 | @invariant |
---|
118 | def bedsOverlap(hostel): |
---|
119 | bfr = hostel.beds_for_fresh |
---|
120 | bre = hostel.beds_for_returning |
---|
121 | bfi = hostel.beds_for_final |
---|
122 | if (set(bfr).intersection(set(bre)) or |
---|
123 | set(bfr).intersection(set(bfi)) or |
---|
124 | set(bre).intersection(set(bfi))): |
---|
125 | raise Invalid('Bed categories overlap.') |
---|
126 | |
---|
127 | #@invariant |
---|
128 | #def numberOfBeds(hostel): |
---|
129 | # bfr = hostel.beds_for_fresh |
---|
130 | # bre = hostel.beds_for_returning |
---|
131 | # bfi = hostel.beds_for_final |
---|
132 | # if len(bfr + bre + bfi) != hostel.beds_per_room: |
---|
133 | # raise Invalid( |
---|
134 | # 'Bed categories and number of beds per room do not match.') |
---|
135 | |
---|
136 | class IBed(IWAeUPObject): |
---|
137 | """A base representation of beds. |
---|
138 | |
---|
139 | """ |
---|
140 | |
---|
141 | def loggerInfo(ob_class, comment): |
---|
142 | """Adds an INFO message to the log file |
---|
143 | """ |
---|
144 | |
---|
145 | def getBedCoordinates(): |
---|
146 | """Determine the coordinates from bed_id. |
---|
147 | """ |
---|
148 | |
---|
149 | bed_id = schema.TextLine( |
---|
150 | title = u'Bed Id', |
---|
151 | required = True, |
---|
152 | default = u'', |
---|
153 | ) |
---|
154 | |
---|
155 | bed_type = schema.TextLine( |
---|
156 | title = u'Bed Type', |
---|
157 | required = True, |
---|
158 | default = u'', |
---|
159 | ) |
---|
160 | |
---|
161 | sort_id = schema.Int( |
---|
162 | title = u'Sort Id', |
---|
163 | required = True, |
---|
164 | default = 100, |
---|
165 | ) |
---|
166 | |
---|
167 | owner = schema.TextLine( |
---|
168 | title = u'Owner (Student)', |
---|
169 | required = True, |
---|
170 | default = u'', |
---|
171 | ) |
---|