source: main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py @ 7138

Last change on this file since 7138 was 7068, checked in by Henrik Bettermann, 13 years ago

Much more logic for bed allocation, bed release.

Implement student relocation.

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1##
2## interfaces.py
3from zope.interface import Attribute, invariant, Invalid
4from zope import schema
5from waeup.sirp.interfaces import IWAeUPObject
6from waeup.sirp.hostels.vocabularies import (
7    bed_letters, blocks, special_handling, StudentSource)
8
9class IHostelsContainer(IWAeUPObject):
10    """A container for all kind of hostel objects.
11
12    """
13
14class 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    beds_reserved = schema.List(
57        title = u'Reserved Beds',
58        value_type = schema.TextLine(
59            default = u'',
60            required = False,
61        ),
62        required = True,
63        readonly = False,
64        default = [],
65        )
66
67    blocks_for_female = schema.List(
68        title = u'Blocks for Female Students',
69        value_type = schema.Choice(
70            vocabulary = blocks
71            ),
72        )
73
74    blocks_for_male = schema.List(
75        title = u'Blocks for Male Students',
76        value_type = schema.Choice(
77            vocabulary = blocks
78            ),
79        )
80
81    beds_for_fresh = schema.List(
82        title = u'Beds for Fresh Students',
83        value_type = schema.Choice(
84            vocabulary = bed_letters
85            ),
86        )
87
88    beds_for_returning = schema.List(
89        title = u'Beds for Returning Students',
90        value_type = schema.Choice(
91            vocabulary = bed_letters
92            ),
93        )
94
95    beds_for_final = schema.List(
96        title = u'Beds for Final Year Students',
97        value_type = schema.Choice(
98            vocabulary = bed_letters
99            ),
100        )
101
102    beds_for_all = schema.List(
103        title = u'Beds without category',
104        value_type = schema.Choice(
105            vocabulary = bed_letters
106            ),
107        )
108
109    special_handling = schema.Choice(
110        title = u'Special Handling',
111        vocabulary = special_handling,
112        required = True,
113        default = u'regular',
114        )
115
116    @invariant
117    def blocksOverlap(hostel):
118        bfe = hostel.blocks_for_female
119        bma = hostel.blocks_for_male
120        if set(bfe).intersection(set(bma)):
121            raise Invalid('Female and male blocks overlap.')
122
123    @invariant
124    def bedsOverlap(hostel):
125        beds = (hostel.beds_for_fresh +
126                hostel.beds_for_returning +
127                hostel.beds_for_final +
128                hostel.beds_for_all)
129        if len(beds) != len(set(beds)):
130            raise Invalid('Bed categories overlap.')
131
132class IBed(IWAeUPObject):
133    """A base representation of beds.
134
135    """
136
137    def loggerInfo(ob_class, comment):
138        """Adds an INFO message to the log file
139        """
140
141    def getBedCoordinates():
142        """Determine the coordinates from bed_id.
143        """
144    def bookBed(student_id):
145        """Book a bed for a student.
146        """
147
148    def switchReservation():
149        """Reserves bed or relases reserved bed respectively.
150        """
151
152    bed_id = schema.TextLine(
153        title = u'Bed Id',
154        required = True,
155        default = u'',
156        )
157
158    bed_type = schema.TextLine(
159        title = u'Bed Type',
160        required = True,
161        default = u'',
162        )
163
164    bed_number = schema.Int(
165        title = u'Bed Number',
166        required = True,
167        )
168
169    owner = schema.TextLine(
170        title = u'Owner (Student)',
171        required = True,
172        default = u'',
173        )
174
175
176
177class IBedAllocateStudent(IBed):
178    """A representation of beds for allocation form only.
179
180    """
181
182    owner = schema.Choice(
183        title = u'Owner (Student)',
184        source = StudentSource(),
185        default = None,
186        required = True,
187        )
Note: See TracBrowser for help on using the repository browser.