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 = 1, |
---|
48 | ) |
---|
49 | |
---|
50 | rooms_per_floor = schema.Int( |
---|
51 | title = u'Rooms per Floor', |
---|
52 | required = True, |
---|
53 | default = 2, |
---|
54 | ) |
---|
55 | |
---|
56 | blocks_for_female = schema.List( |
---|
57 | title = u'Blocks for Female Students', |
---|
58 | value_type = schema.Choice( |
---|
59 | vocabulary = blocks |
---|
60 | ), |
---|
61 | ) |
---|
62 | |
---|
63 | blocks_for_male = schema.List( |
---|
64 | title = u'Blocks for Male Students', |
---|
65 | value_type = schema.Choice( |
---|
66 | vocabulary = blocks |
---|
67 | ), |
---|
68 | ) |
---|
69 | |
---|
70 | beds_for_fresh = schema.List( |
---|
71 | title = u'Beds for Fresh Students', |
---|
72 | value_type = schema.Choice( |
---|
73 | vocabulary = bed_letters |
---|
74 | ), |
---|
75 | ) |
---|
76 | |
---|
77 | beds_for_returning = schema.List( |
---|
78 | title = u'Beds for Returning Students', |
---|
79 | value_type = schema.Choice( |
---|
80 | vocabulary = bed_letters |
---|
81 | ), |
---|
82 | ) |
---|
83 | |
---|
84 | beds_for_final = schema.List( |
---|
85 | title = u'Beds for Final Year Students', |
---|
86 | value_type = schema.Choice( |
---|
87 | vocabulary = bed_letters |
---|
88 | ), |
---|
89 | ) |
---|
90 | |
---|
91 | beds_for_all = schema.List( |
---|
92 | title = u'Beds without category', |
---|
93 | value_type = schema.Choice( |
---|
94 | vocabulary = bed_letters |
---|
95 | ), |
---|
96 | ) |
---|
97 | |
---|
98 | special_handling = schema.Choice( |
---|
99 | title = u'Special Handling', |
---|
100 | vocabulary = special_handling, |
---|
101 | required = True, |
---|
102 | default = u'none', |
---|
103 | ) |
---|
104 | |
---|
105 | reserved = schema.TextLine( |
---|
106 | title = u'Reserved Rooms', |
---|
107 | required = False, |
---|
108 | default = u'', |
---|
109 | ) |
---|
110 | |
---|
111 | @invariant |
---|
112 | def blocksOverlap(hostel): |
---|
113 | bfe = hostel.blocks_for_female |
---|
114 | bma = hostel.blocks_for_male |
---|
115 | if set(bfe).intersection(set(bma)): |
---|
116 | raise Invalid('Female and male blocks overlap.') |
---|
117 | |
---|
118 | @invariant |
---|
119 | def bedsOverlap(hostel): |
---|
120 | bfr = hostel.beds_for_fresh |
---|
121 | bre = hostel.beds_for_returning |
---|
122 | bfi = hostel.beds_for_final |
---|
123 | if (set(bfr).intersection(set(bre)) or |
---|
124 | set(bfr).intersection(set(bfi)) or |
---|
125 | set(bre).intersection(set(bfi))): |
---|
126 | raise Invalid('Bed categories overlap.') |
---|
127 | |
---|
128 | class IBed(IWAeUPObject): |
---|
129 | """A base representation of beds. |
---|
130 | |
---|
131 | """ |
---|
132 | |
---|
133 | def loggerInfo(ob_class, comment): |
---|
134 | """Adds an INFO message to the log file |
---|
135 | """ |
---|
136 | |
---|
137 | def getBedCoordinates(): |
---|
138 | """Determine the coordinates from bed_id. |
---|
139 | """ |
---|
140 | |
---|
141 | bed_id = schema.TextLine( |
---|
142 | title = u'Bed Id', |
---|
143 | required = True, |
---|
144 | default = u'', |
---|
145 | ) |
---|
146 | |
---|
147 | bed_type = schema.TextLine( |
---|
148 | title = u'Bed Type', |
---|
149 | required = True, |
---|
150 | default = u'', |
---|
151 | ) |
---|
152 | |
---|
153 | bed_number = schema.Int( |
---|
154 | title = u'Bed Number', |
---|
155 | required = True, |
---|
156 | ) |
---|
157 | |
---|
158 | owner = schema.TextLine( |
---|
159 | title = u'Owner (Student)', |
---|
160 | required = True, |
---|
161 | default = u'', |
---|
162 | ) |
---|