Changeset 7718 for main/waeup.sirp/trunk/src/waeup/sirp/hostels
- Timestamp:
- 28 Feb 2012, 19:34:51 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/hostels
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py
r7694 r7718 20 20 import grok 21 21 import sys 22 from zope.i18n import translate 23 from zope.component import getUtility 22 24 from waeup.sirp.browser import ( 23 25 SIRPEditFormPage, SIRPAddFormPage, SIRPDisplayFormPage, … … 30 32 ManageActionButton, PrimaryNavTab) 31 33 from waeup.sirp.browser.layout import jsaction, action 32 from waeup.sirp.interfaces import ISIRPObject 34 from waeup.sirp.interfaces import ISIRPObject, ISIRPUtils 35 from waeup.sirp.interfaces import MessageFactory as _ 33 36 from waeup.sirp.hostels.vocabularies import NOT_OCCUPIED 34 37 from waeup.sirp.hostels.hostel import Hostel 35 38 from waeup.sirp.hostels.interfaces import ( 36 39 IHostelsContainer, IHostel, IBed, IBedAllocateStudent) 37 38 from waeup.sirp.interfaces import MessageFactory as _39 40 40 41 def write_log_message(view, message): … … 51 52 fields_string = ' + '.join(changed_fields) 52 53 view.context._p_changed = True 53 view.flash( 'Form has been saved.')54 view.flash(_('Form has been saved.')) 54 55 if fields_string: 55 56 write_log_message(view, 'saved: % s' % fields_string) … … 75 76 """ 76 77 grok.context(IHostelsContainer) 77 title = u'Hostels'78 title = _(u'Hostels') 78 79 79 80 class HostelBreadcrumb(Breadcrumb): … … 92 93 def title(self): 93 94 co = self.context.getBedCoordinates() 94 return 'Block %s, Room %s, Bed %s' % (co[1], co[2], co[3]) 95 return _('Block ${a}, Room ${b}, Bed ${c}', 96 mapping = {'a':co[1], 'b':co[2], 'c':co[3]}) 95 97 96 98 class HostelsContainerPage(SIRPDisplayFormPage): … … 101 103 grok.require('waeup.viewHostels') 102 104 grok.template('containerpage') 103 label = 'Accommodation Section'105 label = _('Accommodation Section') 104 106 pnav = 5 105 107 … … 109 111 grok.view(HostelsContainerPage) 110 112 grok.require('waeup.manageHostels') 111 text = 'Manage accommodation section'113 text = _('Manage accommodation section') 112 114 113 115 class HostelsContainerManagePage(SIRPDisplayFormPage): … … 119 121 grok.template('containermanagepage') 120 122 pnav = 5 121 label = 'Manage accommodation section'123 label = _('Manage accommodation section') 122 124 123 125 def update(self): … … 127 129 # It's quite dangerous to remove entire hostels with its content (beds). 128 130 # Thus, this remove method should be combined with an archiving function. 129 @jsaction( 'Remove selected')131 @jsaction(_('Remove selected')) 130 132 def delHostels(self, **data): 131 133 form = self.request.form … … 141 143 return 142 144 143 @action( 'Add hostel', validator=NullValidator)145 @action(_('Add hostel'), validator=NullValidator) 144 146 def addSubunit(self, **data): 145 147 self.redirect(self.url(self.context, 'addhostel')) … … 153 155 grok.name('addhostel') 154 156 #grok.template('hosteladdpage') 155 form_fields = grok.AutoFields(IHostel) 156 label = 'Add hostel'157 pnav = 5 158 159 @action( 'Create hostel')157 form_fields = grok.AutoFields(IHostel).omit('beds_reserved') 158 label = _('Add hostel') 159 pnav = 5 160 161 @action(_('Create hostel')) 160 162 def addHostel(self, **data): 161 163 hostel = Hostel() … … 166 168 self.context.addHostel(hostel) 167 169 except KeyError: 168 self.flash( 'The hostel already exists.')170 self.flash(_('The hostel already exists.')) 169 171 return 170 self.flash( 'Hostel created.')172 self.flash(_('Hostel created.')) 171 173 write_log_message(self, 'added: % s' % data['hostel_name']) 172 174 self.redirect(self.url(self.context[hostel.hostel_id], 'index')) … … 191 193 grok.view(HostelDisplayFormPage) 192 194 grok.require('waeup.manageHostels') 193 text = 'Manage'195 text = _('Manage') 194 196 target = 'manage' 195 197 … … 201 203 grok.require('waeup.manageHostels') 202 204 form_fields = grok.AutoFields(IHostel).omit('hostel_id') 205 form_fields['beds_reserved'].for_display = True 203 206 grok.template('hostelmanagepage') 204 label = 'Manage hostel'205 pnav = 5 206 taboneactions = [ 'Save']207 tabtwoactions = [ 'Update all beds',208 'Switch reservation of selected beds',209 'Release selected beds']207 label = _('Manage hostel') 208 pnav = 5 209 taboneactions = [_('Save')] 210 tabtwoactions = [_('Update all beds'), 211 _('Switch reservation of selected beds'), 212 _('Release selected beds')] 210 213 not_occupied = NOT_OCCUPIED 211 214 … … 226 229 return 227 230 228 @action( 'Save')231 @action(_('Save')) 229 232 def save(self, **data): 230 233 msave(self, **data) 231 234 return 232 235 233 @action( 'Update all beds')236 @action(_('Update all beds')) 234 237 def updateBeds(self, **data): 235 238 removed, added, modified, modified_beds = self.context.updateBeds() 236 239 message = '%d empty beds removed, %d beds added, %d occupied beds modified (%s)' % ( 237 240 removed, added, modified, modified_beds) 238 self.flash(message) 241 flash_message = _( 242 '${a} empty beds removed, ${b} beds added, ' 243 + '${c} occupied beds modified (${d})', 244 mapping = {'a':removed, 'b':added, 'c':modified, 'd':modified_beds}) 245 self.flash(flash_message) 239 246 write_log_message(self, message) 240 247 self.redirect(self.url(self.context, '@@manage')+'?tab2') 241 248 return 242 249 243 @action( 'Switch reservation of selected beds')250 @action(_('Switch reservation of selected beds')) 244 251 def switchReservations(self, **data): 245 252 form = self.request.form … … 247 254 child_id = form['val_id'] 248 255 else: 249 self.flash( 'No item selected.')256 self.flash(_('No item selected.')) 250 257 self.redirect(self.url(self.context, '@@manage')+'?tab2') 251 258 return 252 259 if not isinstance(child_id, list): 253 260 child_id = [child_id] 254 switched = [] 261 switched = [] # for log file 262 switched_translated = [] # for flash message 263 portal_language = getUtility(ISIRPUtils).PORTAL_LANGUAGE 264 preferred_language = self.request.cookies.get( 265 'sirp.language', portal_language) 255 266 for bed_id in child_id: 256 try: 257 message = self.context[bed_id].switchReservation() 258 switched.append('%s (%s)' % (bed_id,message)) 259 except: 260 self.flash('Could not switch %s: %s: %s' % ( 261 id, sys.exc_info()[0], sys.exc_info()[1])) 262 self.redirect(self.url(self.context, '@@manage')+'?tab2') 263 return 267 message = self.context[bed_id].switchReservation() 268 switched.append('%s (%s)' % (bed_id,message)) 269 m_translated = translate(message, 'waeup.sirp', 270 target_language=preferred_language) 271 switched_translated.append('%s (%s)' % (bed_id,m_translated)) 264 272 if len(switched): 265 273 message = ', '.join(switched) 266 self.flash('Successfully switched beds: %s' % message) 274 m_translated = ', '.join(switched_translated) 275 self.flash(_('Successfully switched beds: ${a}', 276 mapping = {'a':m_translated})) 267 277 write_log_message(self, 'switched: %s' % message) 268 278 self.redirect(self.url(self.context, '@@manage')+'?tab2') 269 279 return 270 280 271 @action( 'Release selected beds')281 @action(_('Release selected beds')) 272 282 def releaseBeds(self, **data): 273 283 form = self.request.form … … 275 285 child_id = form['val_id'] 276 286 else: 277 self.flash( 'No item selected.')287 self.flash(_('No item selected.')) 278 288 self.redirect(self.url(self.context, '@@manage')+'?tab2') 279 289 return … … 287 297 if len(released): 288 298 message = ', '.join(released) 289 self.flash('Successfully released beds: %s' % message) 299 self.flash(_('Successfully released beds: ${a}', 300 mapping = {'a':message})) 290 301 write_log_message(self, 'released: %s' % message) 291 302 self.redirect(self.url(self.context, '@@manage')+'?tab2') 292 303 else: 293 self.flash( 'No allocated bed selected.')304 self.flash(_('No allocated bed selected.')) 294 305 self.redirect(self.url(self.context, '@@manage')+'?tab2') 295 306 return … … 303 314 form_fields = grok.AutoFields(IBedAllocateStudent).omit( 304 315 'bed_id').omit('bed_number').omit('bed_type') 305 label = 'Allocate student'306 pnav = 5 307 308 @action( 'Save')316 label = _('Allocate student') 317 pnav = 5 318 319 @action(_('Save')) 309 320 def save(self, **data): 310 321 msave(self, **data) -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser_templates/containermanagepage.pt
r7464 r7718 1 <form action="." tal:attributes="action request/URL" method="POST" enctype="multipart/form-data"> 1 <form action="." tal:attributes="action request/URL" 2 i18n:domain="waeup.sirp" 3 method="POST" enctype="multipart/form-data"> 2 4 <table> 3 5 <thead> … … 5 7 <th> 6 8 </th> 7 <th >Id9 <th i18n:translate="">Id 8 10 </th> 9 <th >Name11 <th i18n:translate="">Name 10 12 </th> 11 13 </tr> -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser_templates/containerpage.pt
r7464 r7718 1 <div tal:condition="python: not len(context.keys())"> 1 <div i18n:domain="waeup.sirp" 2 i18n:translate="" tal:condition="python: not len(context.keys())"> 2 3 There no subobjects registered yet. 3 4 </div> 4 5 5 <table >6 <table i18n:domain="waeup.sirp"> 6 7 <thead> 7 8 <tr> 8 <th >Id</th>9 <th >Name</th>9 <th i18n:translate="">Id</th> 10 <th i18n:translate="">Name</th> 10 11 </tr> 11 12 </thead> … … 13 14 <tr tal:repeat="value context/values"> 14 15 <td> <a tal:attributes="href value/__name__"> 15 <span tal:content="value/hostel_id">I d</span></a></td>16 <td tal:content="value/hostel_name">N ame</td>16 <span tal:content="value/hostel_id">ID</span></a></td> 17 <td tal:content="value/hostel_name">NAME</td> 17 18 </tr> 18 19 </tbody> -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser_templates/hostelmanagepage.pt
r7669 r7718 1 1 <form action="." tal:attributes="action request/URL" method="POST" 2 enctype="multipart/form-data">2 i18n:domain="waeup.sirp" enctype="multipart/form-data"> 3 3 4 4 <ul class="tabs" data-tabs="tabs"> 5 <li tal:attributes="class view/tab1"><a href="#tab-1"><span>Hostel Data</span></a></li> 6 <li tal:attributes="class view/tab2"><a href="#tab-2"><span>Beds</span></a></li> 5 <li tal:attributes="class view/tab1"><a href="#tab-1"> 6 <span i18n:translate="">Hostel Data</span></a> 7 </li> 8 <li tal:attributes="class view/tab2"><a href="#tab-2"> 9 <span i18n:translate="">Beds</span></a> 10 </li> 7 11 </ul> 8 12 … … 15 19 <td class="fieldname"> 16 20 <span class="required" tal:condition="widget/required">*</span> 17 <span tal:content="widget/label"> label</span>:21 <span tal:content="widget/label">LABEL</span>: 18 22 </td> 19 23 <td> … … 22 26 </span> 23 27 <tal:error tal:condition="widget/error"> 24 <span tal:replace="structure widget/error"> error</span>28 <span tal:replace="structure widget/error">ERROR</span> 25 29 </tal:error> 26 30 <tal:hint tal:condition="widget/hint"> 27 <span tal:content="structure widget/hint"> hint</span>31 <span tal:content="structure widget/hint">HINT</span> 28 32 </tal:hint> 29 33 </td> … … 47 51 <tr> 48 52 <th> </th> 49 <th >Id</th>50 <th >Type</th>51 <th >Number</th>52 <th >Owner</th>53 <th i18n:translate="">Id</th> 54 <th i18n:translate="">Type</th> 55 <th i18n:translate="">Number</th> 56 <th i18n:translate="">Owner</th> 53 57 </tr> 54 58 </thead> … … 59 63 tal:attributes="value value/__name__" /> 60 64 </td> 61 <td tal:content="value/bed_id">I d</td>62 <td tal:content="value/bed_type">T ype</td>63 <td tal:content="value/bed_number">N umber</td>65 <td tal:content="value/bed_id">ID</td> 66 <td tal:content="value/bed_type">TYPE</td> 67 <td tal:content="value/bed_number">NUMBER</td> 64 68 <td> 65 69 <a tal:condition="python: value.owner != view.not_occupied" 66 70 tal:attributes="href python: '%s/%s/accommodation' % 67 71 (view.students_url,value.owner)"> 68 <span tal:content="value/owner">O wner</span>72 <span tal:content="value/owner">OWNER</span> 69 73 </a> 70 74 <a tal:condition="python: value.owner == view.not_occupied" 71 tal:attributes="href python: view.url(value)"> 75 tal:attributes="href python: view.url(value)" 76 i18n:translate=""> 72 77 [allocate student] 73 78 </a> -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py
r7257 r7718 26 26 from waeup.sirp.hostels.interfaces import IHostel, IBed, IBedAllocateStudent 27 27 from waeup.sirp.students.interfaces import IBedTicket 28 from waeup.sirp.interfaces import MessageFactory as _ 28 29 29 30 class Hostel(grok.Container): … … 159 160 bt = 're' 160 161 bt = u'%s_%s_%s' % (sh, sex, bt) 161 hostel.beds_reserved.remove(bed_string) 162 message = u'unreserved' 163 else: 164 bt = u'%s_%s_reserved' % (sh, sex) 165 hostel.beds_reserved.append(bed_string) 162 166 163 # Comment of Martijn: 167 164 # If you have a non-Persistent subobject (like a list) and you change it, … … 172 169 # (PersistentList, PersistentMapping), and more advanced building blocks 173 170 # for indexes (BTrees), that don't have this issue. 174 hostel._p_changed = True 175 message = u'reserved' 171 #hostel._p_changed = True 172 173 # Henrik: Unfortunately, this doesn't work in our case. 174 # After restarting the portal, 175 # added or removed list items are gone. The only way to ensure 176 # persistance is to reassign the list attribute. 177 br = hostel.beds_reserved 178 br.remove(bed_string) 179 hostel.beds_reserved = br 180 message = _(u'unreserved') 181 else: 182 bt = u'%s_%s_reserved' % (sh, sex) 183 # See comment above 184 br = hostel.beds_reserved 185 br.append(bed_string) 186 hostel.beds_reserved = br 187 message = _(u'reserved') 176 188 self.bed_type = bt 177 189 return message -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py
r7321 r7718 19 19 from zope import schema 20 20 from waeup.sirp.interfaces import ISIRPObject 21 from waeup.sirp.interfaces import MessageFactory as _ 21 22 from waeup.sirp.hostels.vocabularies import ( 22 23 bed_letters, blocks, special_handling, StudentSource) … … 41 42 42 43 hostel_id = schema.TextLine( 43 title = u'Hostel Id',44 title = _(u'Hostel Id'), 44 45 readonly = True, 45 46 ) 46 47 47 48 sort_id = schema.Int( 48 title = u'Sort Id',49 title = _(u'Sort Id'), 49 50 required = True, 50 51 default = 10, … … 52 53 53 54 hostel_name = schema.TextLine( 54 title = u'Hall Name',55 title = _(u'Hostel Name'), 55 56 required = True, 56 57 default = u'Hall 1', … … 58 59 59 60 floors_per_block = schema.Int( 60 title = u'Floors per Block',61 title = _(u'Floors per Block'), 61 62 required = True, 62 63 default = 1, … … 64 65 65 66 rooms_per_floor = schema.Int( 66 title = u'Rooms per Floor',67 title = _(u'Rooms per Floor'), 67 68 required = True, 68 69 default = 2, … … 70 71 71 72 beds_reserved = schema.List( 72 title = u'Reserved Beds',73 title = _(u'Reserved Beds'), 73 74 value_type = schema.TextLine( 74 75 default = u'', … … 81 82 82 83 blocks_for_female = schema.List( 83 title = u'Blocks for Female Students',84 title = _(u'Blocks for Female Students'), 84 85 value_type = schema.Choice( 85 86 vocabulary = blocks … … 88 89 89 90 blocks_for_male = schema.List( 90 title = u'Blocks for Male Students',91 title = _(u'Blocks for Male Students'), 91 92 value_type = schema.Choice( 92 93 vocabulary = blocks … … 95 96 96 97 beds_for_fresh = schema.List( 97 title = u'Beds for Fresh Students',98 title = _(u'Beds for Fresh Students'), 98 99 value_type = schema.Choice( 99 100 vocabulary = bed_letters … … 102 103 103 104 beds_for_returning = schema.List( 104 title = u'Beds for Returning Students',105 title = _(u'Beds for Returning Students'), 105 106 value_type = schema.Choice( 106 107 vocabulary = bed_letters … … 109 110 110 111 beds_for_final = schema.List( 111 title = u'Beds for Final Year Students',112 title = _(u'Beds for Final Year Students'), 112 113 value_type = schema.Choice( 113 114 vocabulary = bed_letters … … 116 117 117 118 beds_for_all = schema.List( 118 title = u'Beds without category',119 title = _(u'Beds without category'), 119 120 value_type = schema.Choice( 120 121 vocabulary = bed_letters … … 123 124 124 125 special_handling = schema.Choice( 125 title = u'Special Handling',126 title = _(u'Special Handling'), 126 127 vocabulary = special_handling, 127 128 required = True, … … 134 135 bma = hostel.blocks_for_male 135 136 if set(bfe).intersection(set(bma)): 136 raise Invalid( 'Female and male blocks overlap.')137 raise Invalid(_('Female and male blocks overlap.')) 137 138 138 139 @invariant … … 143 144 hostel.beds_for_all) 144 145 if len(beds) != len(set(beds)): 145 raise Invalid( 'Bed categories overlap.')146 raise Invalid(_('Bed categories overlap.')) 146 147 147 148 class IBed(ISIRPObject): … … 166 167 167 168 bed_id = schema.TextLine( 168 title = u'Bed Id',169 title = _(u'Bed Id'), 169 170 required = True, 170 171 default = u'', … … 172 173 173 174 bed_type = schema.TextLine( 174 title = u'Bed Type',175 title = _(u'Bed Type'), 175 176 required = True, 176 177 default = u'', … … 178 179 179 180 bed_number = schema.Int( 180 title = u'Bed Number',181 title = _(u'Bed Number'), 181 182 required = True, 182 183 ) 183 184 184 185 owner = schema.TextLine( 185 title = u'Owner (Student)',186 title = _(u'Owner (Student)'), 186 187 required = True, 187 188 default = u'', … … 196 197 197 198 owner = schema.Choice( 198 title = u'Owner (Student)',199 title = _(u'Owner (Student)'), 199 200 source = StudentSource(), 200 201 default = None, -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py
r7484 r7718 246 246 assert self.app['hostels']['hall-1'][ 247 247 'hall-1_A_101_D'].bed_type == 'regular_female_reserved' 248 expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_A" />' 249 self.assertTrue(expected in self.browser.contents) 250 # Provoke exception 251 self.app['hostels']['hall-1']['hall-1_A_101_D'].bed_type = u'nonsense' 252 ctrl = self.browser.getControl(name='val_id') 253 ctrl.getControl(value='hall-1_A_101_D').selected = True 254 self.browser.getControl("Switch reservation", index=0).click() 255 self.assertMatches( 256 '...need more than 1 value to unpack...', self.browser.contents) 257 self.app['hostels']['hall-1'][ 258 'hall-1_A_101_D'].bed_type = u'regular_female_reserved' 248 self.assertTrue('<li>A_101_A</li>' in self.browser.contents) 259 249 # Change hostel configuration 260 250 hall.beds_for_all = ['D'] -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py
r7321 r7718 23 23 from zc.sourcefactory.contextual import BasicContextualSourceFactory 24 24 from waeup.sirp.interfaces import SimpleSIRPVocabulary 25 from waeup.sirp.interfaces import MessageFactory as _ 25 26 26 27 NOT_OCCUPIED = u'not occupied' … … 54 55 55 56 bed_letters = SimpleSIRPVocabulary( 56 ( 'Bed A','A'),57 ( 'Bed B','B'),58 ( 'Bed C','C'),59 ( 'Bed D','D'),60 ( 'Bed E','E'),61 ( 'Bed F','F'),62 ( 'Bed G','G'),63 ( 'Bed H','H'),64 ( 'Bed I','I'),57 (_('Bed A'),'A'), 58 (_('Bed B'),'B'), 59 (_('Bed C'),'C'), 60 (_('Bed D'),'D'), 61 (_('Bed E'),'E'), 62 (_('Bed F'),'F'), 63 (_('Bed G'),'G'), 64 (_('Bed H'),'H'), 65 (_('Bed I'),'I'), 65 66 ) 66 67 67 68 blocks = SimpleSIRPVocabulary( 68 ( 'Block A','A'),69 ( 'Block B','B'),70 ( 'Block C','C'),71 ( 'Block D','D'),72 ( 'Block E','E'),73 ( 'Block F','F'),74 ( 'Block G','G'),75 ( 'Block H','H'),76 ( 'Block I','I'),77 ( 'Block K','K'),78 ( 'Block L','L'),79 ( 'Block M','M'),80 ( 'Block N','N'),81 ( 'Block O','O'),82 ( 'Block P','P'),69 (_('Block A'),'A'), 70 (_('Block B'),'B'), 71 (_('Block C'),'C'), 72 (_('Block D'),'D'), 73 (_('Block E'),'E'), 74 (_('Block F'),'F'), 75 (_('Block G'),'G'), 76 (_('Block H'),'H'), 77 (_('Block I'),'I'), 78 (_('Block K'),'K'), 79 (_('Block L'),'L'), 80 (_('Block M'),'M'), 81 (_('Block N'),'N'), 82 (_('Block O'),'O'), 83 (_('Block P'),'P'), 83 84 ) 84 85 85 86 special_handling = SimpleSIRPVocabulary( 86 ( 'Regular Hostel','regular'),87 ( 'Blocked Hostel','blocked'),88 ( 'Postgraduate Hostel','pg'),87 (_('Regular Hostel'),'regular'), 88 (_('Blocked Hostel'),'blocked'), 89 (_('Postgraduate Hostel'),'pg'), 89 90 )
Note: See TracChangeset for help on using the changeset viewer.