Changeset 6970
- Timestamp:
- 30 Oct 2011, 08:29:17 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/hostels
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py
r6966 r6970 142 142 grok.require('waeup.manageHostels') 143 143 grok.name('addhostel') 144 grok.template('hosteladdpage')144 #grok.template('hosteladdpage') 145 145 form_fields = grok.AutoFields(IHostel) 146 146 title = 'Hostels' … … 186 186 grok.require('waeup.manageHostels') 187 187 text = 'Manage' 188 target = ' edit'188 target = 'manage' 189 189 190 190 class HostelManageFormPage(WAeUPEditFormPage): … … 192 192 """ 193 193 grok.context(IHostel) 194 grok.name(' edit')194 grok.name('manage') 195 195 grok.require('waeup.manageHostels') 196 196 form_fields = grok.AutoFields(IHostel).omit('hostel_id') 197 #grok.template('hostelmanagepage')197 grok.template('hostelmanagepage') 198 198 label = 'Manage hostel' 199 199 pnav = 5 200 taboneactions = ['Save'] 201 tabtwoactions = ['Update beds'] 200 202 201 203 @property … … 205 207 def update(self): 206 208 datepicker.need() # Enable jQuery datepicker in date fields. 209 tabs.need() 210 datatable.need() 207 211 super(HostelManageFormPage, self).update() 208 212 return … … 212 216 msave(self, **data) 213 217 return 218 219 @grok.action('Update beds') 220 def updateBeds(self, **data): 221 added, modified = self.context.updateBeds() 222 self.flash('%d added, %d modified' % (added, modified)) 223 self.redirect(self.url(self.context, '@@manage')+'#tab-2') 224 return -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py
r6963 r6970 23 23 from waeup.sirp.hostels.interfaces import IHostel, IBed 24 24 25 NOT_OCCUPIED = u'not occupied' 26 25 27 class Hostel(grok.Container): 26 28 """This is a hostel. … … 34 36 35 37 def addBed(self, bed): 36 """Add a hostel.38 """Add a bed. 37 39 """ 38 40 if not IBed.providedBy(bed): 39 41 raise TypeError( 40 42 'Hostels contain only IBed instances') 41 self[ hostel.bed_id] = bed43 self[bed.bed_id] = bed 42 44 return 45 46 # not yet tested nor used 47 def updateBeds(self): 48 """Fill hostel with beds or update beds. 49 """ 50 added_counter = 0 51 modified_counter = 0 52 blocks_for_female = getattr(self,'blocks_for_female',[]) 53 blocks_for_male = getattr(self,'blocks_for_male',[]) 54 beds_for_fresh = getattr(self,'beds_for_fresh',[]) 55 beds_for_pre = getattr(self,'beds_for_pre',[]) 56 beds_for_returning = getattr(self,'beds_for_returning',[]) 57 beds_for_final = getattr(self,'beds_for_final',[]) 58 beds_reserved = [] #temporarily empty 59 all_blocks = blocks_for_female + blocks_for_male 60 all_beds = (beds_for_pre + beds_for_fresh + 61 beds_for_returning + beds_for_final) 62 #import pdb;pdb.set_trace() 63 for block in all_blocks: 64 sex = 'male' 65 if block in blocks_for_female: 66 sex = 'female' 67 for floor in range(1,int(self.floors_per_block)+1): 68 for room in range(1,int(self.rooms_per_floor)+1): 69 for bed in all_beds: 70 room_nr = floor*100 + room 71 bt = 'all' 72 if (block,room_nr) in beds_reserved: 73 bt = "reserved" 74 # Hostels with special handling and 75 # without bed categorisation 76 elif (self.special_handling != 'none' and not 77 self.special_handling.endswith("_withcat")): 78 bt = self.special_handling[3:] 79 elif bed in beds_for_fresh: 80 bt = 'fr' 81 elif bed in beds_for_pre: 82 bt = 'pr' 83 elif bed in beds_for_final: 84 bt = 'fi' 85 elif bed in beds_for_returning: 86 bt = 're' 87 # Hostels with special handling and 88 # with bed categorisation 89 if (self.special_handling != 'none' and 90 self.special_handling.endswith("_withcat")): 91 bt += "_" + self.special_handling 92 bt = u'%(sex)s_%(bt)s' % vars() 93 uid = u'%s_%s_%d_%s' % (self.hostel_id,block,room_nr,bed) 94 if self.has_key(uid): 95 bed = self[uid] 96 if bed.bed_type != bt: 97 bed.bed_type = bt 98 bed.sort_id = getattr(self,'sort_id',0) 99 #modified.append('"%(uid)s","%(bt)s","%(bed.owner)s"' % vars()) 100 modified_counter += 1 101 else: 102 bed = Bed() 103 bed.bed_id = uid 104 bed.bed_type = bt 105 bed.sort_id = getattr(self,'sort_id',0) 106 bed.owner = NOT_OCCUPIED 107 self.addBed(bed) 108 #generated.append('"%(uid)s","%(bt)s"' % vars()) 109 added_counter +=1 110 return added_counter, modified_counter 43 111 44 112 Hostel = attrs_to_fields(Hostel) -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py
r6963 r6970 1 1 ## 2 2 ## interfaces.py 3 from zope.interface import Attribute, invariant 3 from zope.interface import Attribute, invariant, Invalid 4 4 from zope import schema 5 5 from waeup.sirp.interfaces import IWAeUPObject 6 from waeup.sirp.hostels.vocabularies import bed_letters, blocks 6 from waeup.sirp.hostels.vocabularies import ( 7 bed_letters, blocks, special_handling) 7 8 8 9 class IHostelsContainer(IWAeUPObject): … … 18 19 def loggerInfo(ob_class, comment): 19 20 """Adds an INFO message to the log file 21 """ 22 23 def updateBeds(): 24 """Fill hostel with beds or update beds. 20 25 """ 21 26 … … 37 42 ) 38 43 39 nr_of_blocks = schema.Int(40 title = u'Number of Blocks',41 required = True,42 default = 3,43 )44 45 44 floors_per_block = schema.Int( 46 45 title = u'Floors per Block', … … 55 54 ) 56 55 57 beds_per_room = schema.Int(58 title = u'Beds per Room',59 required = True,60 default = 6,61 )56 #beds_per_room = schema.Int( 57 # title = u'Beds per Room', 58 # required = True, 59 # default = 6, 60 # ) 62 61 63 62 blocks_for_female = schema.List( 64 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', 65 71 value_type = schema.Choice( 66 72 vocabulary = blocks … … 75 81 ) 76 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 77 90 beds_for_final = schema.List( 78 91 title = u'Beds for Final Year Students', … … 81 94 ), 82 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.') 83 135 84 136 class IBed(IWAeUPObject): -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py
r6963 r6970 133 133 <li>Block B</li></ul>...''' 134 134 self.assertMatches(expected,self.browser.contents) 135 self.browser.open(self.container_path + '/hall_1/ edit')136 self.browser.getControl(name="form. nr_of_blocks").value = '5'135 self.browser.open(self.container_path + '/hall_1/manage') 136 self.browser.getControl(name="form.floors_per_block").value = '4' 137 137 self.browser.getControl("Save").click() 138 138 self.assertTrue('Form has been saved' in self.browser.contents) -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py
r6958 r6970 34 34 ('Block P','P'), 35 35 ) 36 37 special_handling = SimpleWAeUPVocabulary( 38 ('No special handling','none'), 39 ('Blocked','blocked'), 40 ('Postgraduate Hostel','pg'), 41 )
Note: See TracChangeset for help on using the changeset viewer.