Ignore:
Timestamp:
14 Oct 2015, 17:07:35 (9 years ago)
Author:
Henrik Bettermann
Message:

Add page to release all expired allocations.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/hostels
Files:
3 edited

Legend:

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

    r13177 r13319  
    2424from waeup.kofa.browser.layout import (
    2525    KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage,
    26     NullValidator)
     26    NullValidator, UtilityView)
    2727from waeup.kofa.browser.breadcrumbs import Breadcrumb
    2828from waeup.kofa.browser.layout import default_primary_nav_template
     
    164164        self.applyData(self.context, **data)
    165165        self.flash(_('Settings have been saved.'))
     166        return
     167
     168class ReleaseExpiredAllocationsPage(UtilityView, grok.View):
     169    """Release all expired allocated beds.
     170    """
     171    grok.context(IHostelsContainer)
     172    grok.name('releaseexpired')
     173    grok.require('waeup.waeup.manageHostels')
     174
     175    def update(self, n=7):
     176        released = self.context.releaseExpiredAllocations(n)
     177        if len(released):
     178            message = ', '.join(released)
     179            self.context.writeLogMessage(self, 'released: %s' % message)
     180            flash_msg = _('Successfully released beds: ${a}', mapping = {'a':message})
     181        else:
     182            flash_msg = _('No bed released.')
     183        self.flash(flash_msg, type='success')
     184        self.redirect(self.url(self.context))
     185        return
     186
     187    def render(self):
    166188        return
    167189
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/container.py

    r13318 r13319  
    6565            if student_id:
    6666                released.append('%s (%s)' % (bed.bed_id,student_id))
    67         if len(released):
    68             message = ', '.join(released)
    69             self.writeLogMessage(self, 'released: %s' % message)
    7067        return released
    7168
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r13318 r13319  
    180180
    181181    def test_release_expired_allocations(self):
     182        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    182183        cat = queryUtility(ICatalog, name='beds_catalog')
    183184        bedticket = BedTicket()
     
    191192        results = cat.searchResults(owner=(self.student_id, self.student_id))
    192193        self.assertEqual(len(results), 1)
    193         released = self.app['hostels'].releaseExpiredAllocations(7)
    194         self.assertEqual(released, [])
     194        self.browser.open(self.container_path + '/releaseexpired')
     195        self.assertTrue('No bed released' in self.browser.contents)
    195196        delta = timedelta(days=10)
    196197        bedticket.booking_date = datetime.utcnow() - delta
    197         released = self.app['hostels'].releaseExpiredAllocations(7)
    198         self.assertEqual(len(released), 1)
    199         self.assertEqual(released, ['hall_block_room_bed (K1000000)'])
     198        self.browser.open(self.container_path + '/releaseexpired')
     199        self.assertTrue(
     200            'Successfully released beds: hall_block_room_bed (K1000000)'
     201            in self.browser.contents)
    200202        results = cat.searchResults(owner=(self.student_id, self.student_id))
    201203        self.assertEqual(len(results), 0)
     
    208210        logcontent = open(self.logfile).read()
    209211        self.assertTrue(
    210             'hostels.container.HostelsContainer - hostels - '
     212            'hostels.browser.ReleaseExpiredAllocationsPage - hostels - '
    211213            'released: hall_block_room_bed (K1000000)'
    212214            in logcontent)
Note: See TracChangeset for help on using the changeset viewer.