Changeset 7718 for main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py
- Timestamp:
- 28 Feb 2012, 19:34:51 (13 years ago)
- File:
-
- 1 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)
Note: See TracChangeset for help on using the changeset viewer.