Ignore:
Timestamp:
28 Feb 2012, 19:34:51 (13 years ago)
Author:
Henrik Bettermann
Message:

Internationalize hostels package.

Remove exception catcher in switchReservations and corresponding test.

When testing the hostel configuration manually I found out that the beds_reserved list attribute of halls
only changed during the lifetime of a running instance. After restarting the portal all changes were gone.
Also "hostel._p_changed = True" didn't help. The only solution was to reassign the attribute to ensure persistance.

Unfortunately, the current tests don't catch such a malfunction. This has to be improved.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py

    r7694 r7718  
    2020import grok
    2121import sys
     22from zope.i18n import translate
     23from zope.component import getUtility
    2224from waeup.sirp.browser import (
    2325    SIRPEditFormPage, SIRPAddFormPage, SIRPDisplayFormPage,
     
    3032    ManageActionButton, PrimaryNavTab)
    3133from waeup.sirp.browser.layout import jsaction, action
    32 from waeup.sirp.interfaces import ISIRPObject
     34from waeup.sirp.interfaces import ISIRPObject, ISIRPUtils
     35from waeup.sirp.interfaces import MessageFactory as _
    3336from waeup.sirp.hostels.vocabularies import NOT_OCCUPIED
    3437from waeup.sirp.hostels.hostel import Hostel
    3538from waeup.sirp.hostels.interfaces import (
    3639    IHostelsContainer, IHostel, IBed, IBedAllocateStudent)
    37 
    38 from waeup.sirp.interfaces import MessageFactory as _
    3940
    4041def write_log_message(view, message):
     
    5152    fields_string = ' + '.join(changed_fields)
    5253    view.context._p_changed = True
    53     view.flash('Form has been saved.')
     54    view.flash(_('Form has been saved.'))
    5455    if fields_string:
    5556        write_log_message(view, 'saved: % s' % fields_string)
     
    7576    """
    7677    grok.context(IHostelsContainer)
    77     title = u'Hostels'
     78    title = _(u'Hostels')
    7879
    7980class HostelBreadcrumb(Breadcrumb):
     
    9293    def title(self):
    9394        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]})
    9597
    9698class HostelsContainerPage(SIRPDisplayFormPage):
     
    101103    grok.require('waeup.viewHostels')
    102104    grok.template('containerpage')
    103     label = 'Accommodation Section'
     105    label = _('Accommodation Section')
    104106    pnav = 5
    105107
     
    109111    grok.view(HostelsContainerPage)
    110112    grok.require('waeup.manageHostels')
    111     text = 'Manage accommodation section'
     113    text = _('Manage accommodation section')
    112114
    113115class HostelsContainerManagePage(SIRPDisplayFormPage):
     
    119121    grok.template('containermanagepage')
    120122    pnav = 5
    121     label = 'Manage accommodation section'
     123    label = _('Manage accommodation section')
    122124
    123125    def update(self):
     
    127129    # It's quite dangerous to remove entire hostels with its content (beds).
    128130    # Thus, this remove method should be combined with an archiving function.
    129     @jsaction('Remove selected')
     131    @jsaction(_('Remove selected'))
    130132    def delHostels(self, **data):
    131133        form = self.request.form
     
    141143        return
    142144
    143     @action('Add hostel', validator=NullValidator)
     145    @action(_('Add hostel'), validator=NullValidator)
    144146    def addSubunit(self, **data):
    145147        self.redirect(self.url(self.context, 'addhostel'))
     
    153155    grok.name('addhostel')
    154156    #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'))
    160162    def addHostel(self, **data):
    161163        hostel = Hostel()
     
    166168            self.context.addHostel(hostel)
    167169        except KeyError:
    168             self.flash('The hostel already exists.')
     170            self.flash(_('The hostel already exists.'))
    169171            return
    170         self.flash('Hostel created.')
     172        self.flash(_('Hostel created.'))
    171173        write_log_message(self, 'added: % s' % data['hostel_name'])
    172174        self.redirect(self.url(self.context[hostel.hostel_id], 'index'))
     
    191193    grok.view(HostelDisplayFormPage)
    192194    grok.require('waeup.manageHostels')
    193     text = 'Manage'
     195    text = _('Manage')
    194196    target = 'manage'
    195197
     
    201203    grok.require('waeup.manageHostels')
    202204    form_fields = grok.AutoFields(IHostel).omit('hostel_id')
     205    form_fields['beds_reserved'].for_display = True
    203206    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')]
    210213    not_occupied = NOT_OCCUPIED
    211214
     
    226229        return
    227230
    228     @action('Save')
     231    @action(_('Save'))
    229232    def save(self, **data):
    230233        msave(self, **data)
    231234        return
    232235
    233     @action('Update all beds')
     236    @action(_('Update all beds'))
    234237    def updateBeds(self, **data):
    235238        removed, added, modified, modified_beds = self.context.updateBeds()
    236239        message = '%d empty beds removed, %d beds added, %d occupied beds modified (%s)' % (
    237240            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)
    239246        write_log_message(self, message)
    240247        self.redirect(self.url(self.context, '@@manage')+'?tab2')
    241248        return
    242249
    243     @action('Switch reservation of selected beds')
     250    @action(_('Switch reservation of selected beds'))
    244251    def switchReservations(self, **data):
    245252        form = self.request.form
     
    247254            child_id = form['val_id']
    248255        else:
    249             self.flash('No item selected.')
     256            self.flash(_('No item selected.'))
    250257            self.redirect(self.url(self.context, '@@manage')+'?tab2')
    251258            return
    252259        if not isinstance(child_id, list):
    253260            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)
    255266        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))
    264272        if len(switched):
    265273            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}))
    267277            write_log_message(self, 'switched: %s' % message)
    268278            self.redirect(self.url(self.context, '@@manage')+'?tab2')
    269279        return
    270280
    271     @action('Release selected beds')
     281    @action(_('Release selected beds'))
    272282    def releaseBeds(self, **data):
    273283        form = self.request.form
     
    275285            child_id = form['val_id']
    276286        else:
    277             self.flash('No item selected.')
     287            self.flash(_('No item selected.'))
    278288            self.redirect(self.url(self.context, '@@manage')+'?tab2')
    279289            return
     
    287297        if len(released):
    288298            message = ', '.join(released)
    289             self.flash('Successfully released beds: %s' % message)
     299            self.flash(_('Successfully released beds: ${a}',
     300                mapping = {'a':message}))
    290301            write_log_message(self, 'released: %s' % message)
    291302            self.redirect(self.url(self.context, '@@manage')+'?tab2')
    292303        else:
    293             self.flash('No allocated bed selected.')
     304            self.flash(_('No allocated bed selected.'))
    294305            self.redirect(self.url(self.context, '@@manage')+'?tab2')
    295306        return
     
    303314    form_fields = grok.AutoFields(IBedAllocateStudent).omit(
    304315        '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'))
    309320    def save(self, **data):
    310321        msave(self, **data)
Note: See TracChangeset for help on using the changeset viewer.