[6951] | 1 | ## |
---|
| 2 | ## interfaces.py |
---|
[6970] | 3 | from zope.interface import Attribute, invariant, Invalid |
---|
[6951] | 4 | from zope import schema |
---|
| 5 | from waeup.sirp.interfaces import IWAeUPObject |
---|
[6970] | 6 | from waeup.sirp.hostels.vocabularies import ( |
---|
[7068] | 7 | bed_letters, blocks, special_handling, StudentSource) |
---|
[6951] | 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 | """ |
---|
[6952] | 18 | |
---|
| 19 | def loggerInfo(ob_class, comment): |
---|
| 20 | """Adds an INFO message to the log file |
---|
| 21 | """ |
---|
| 22 | |
---|
[6970] | 23 | def updateBeds(): |
---|
| 24 | """Fill hostel with beds or update beds. |
---|
| 25 | """ |
---|
| 26 | |
---|
[6952] | 27 | hostel_id = schema.TextLine( |
---|
[6956] | 28 | title = u'Hostel Id', |
---|
| 29 | readonly = True, |
---|
| 30 | ) |
---|
| 31 | |
---|
| 32 | sort_id = schema.Int( |
---|
| 33 | title = u'Sort Id', |
---|
[6954] | 34 | required = True, |
---|
[6956] | 35 | default = 10, |
---|
| 36 | ) |
---|
| 37 | |
---|
| 38 | hostel_name = schema.TextLine( |
---|
| 39 | title = u'Hall Name', |
---|
| 40 | required = True, |
---|
[6959] | 41 | default = u'Hall 1', |
---|
[6956] | 42 | ) |
---|
| 43 | |
---|
[6959] | 44 | floors_per_block = schema.Int( |
---|
| 45 | title = u'Floors per Block', |
---|
[6956] | 46 | required = True, |
---|
[6971] | 47 | default = 1, |
---|
[6956] | 48 | ) |
---|
| 49 | |
---|
| 50 | rooms_per_floor = schema.Int( |
---|
[6958] | 51 | title = u'Rooms per Floor', |
---|
[6956] | 52 | required = True, |
---|
[6971] | 53 | default = 2, |
---|
[6956] | 54 | ) |
---|
| 55 | |
---|
[6976] | 56 | beds_reserved = schema.List( |
---|
[6975] | 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 | |
---|
[6958] | 67 | blocks_for_female = schema.List( |
---|
| 68 | title = u'Blocks for Female Students', |
---|
| 69 | value_type = schema.Choice( |
---|
| 70 | vocabulary = blocks |
---|
| 71 | ), |
---|
| 72 | ) |
---|
| 73 | |
---|
[6970] | 74 | blocks_for_male = schema.List( |
---|
| 75 | title = u'Blocks for Male Students', |
---|
| 76 | value_type = schema.Choice( |
---|
| 77 | vocabulary = blocks |
---|
| 78 | ), |
---|
| 79 | ) |
---|
| 80 | |
---|
[6958] | 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 | |
---|
[6970] | 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 | |
---|
[6958] | 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 | ) |
---|
[6963] | 101 | |
---|
[6971] | 102 | beds_for_all = schema.List( |
---|
| 103 | title = u'Beds without category', |
---|
| 104 | value_type = schema.Choice( |
---|
| 105 | vocabulary = bed_letters |
---|
| 106 | ), |
---|
| 107 | ) |
---|
| 108 | |
---|
[6970] | 109 | special_handling = schema.Choice( |
---|
| 110 | title = u'Special Handling', |
---|
| 111 | vocabulary = special_handling, |
---|
| 112 | required = True, |
---|
[6973] | 113 | default = u'regular', |
---|
[6970] | 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): |
---|
[6981] | 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)): |
---|
[6970] | 130 | raise Invalid('Bed categories overlap.') |
---|
| 131 | |
---|
[6963] | 132 | class 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 | """ |
---|
[6996] | 144 | def bookBed(student_id): |
---|
| 145 | """Book a bed for a student. |
---|
| 146 | """ |
---|
[6963] | 147 | |
---|
[6974] | 148 | def switchReservation(): |
---|
| 149 | """Reserves bed or relases reserved bed respectively. |
---|
| 150 | """ |
---|
| 151 | |
---|
[6963] | 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 | |
---|
[6971] | 164 | bed_number = schema.Int( |
---|
| 165 | title = u'Bed Number', |
---|
[6963] | 166 | required = True, |
---|
| 167 | ) |
---|
| 168 | |
---|
| 169 | owner = schema.TextLine( |
---|
| 170 | title = u'Owner (Student)', |
---|
| 171 | required = True, |
---|
| 172 | default = u'', |
---|
| 173 | ) |
---|
[7068] | 174 | |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | class 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 | ) |
---|