Changeset 9197 for main


Ignore:
Timestamp:
18 Sep 2012, 16:24:21 (12 years ago)
Author:
Henrik Bettermann
Message:

Add view and content component methods to clear hostels.

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

Legend:

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

    r8685 r9197  
    130130    form_fields = grok.AutoFields(IHostelsContainer)
    131131    taboneactions = [_('Save')]
    132     tabtwoactions = [_('Add hostel'), _('Remove selected')]
     132    tabtwoactions = [_('Add hostel'),
     133        _('Clear all hostels'),
     134        _('Remove selected')]
    133135
    134136    def update(self):
     
    164166        return
    165167
     168    @jsaction(_('Clear all hostels'))
     169    def clearHostels(self, **data):
     170        self.context.clearAllHostels()
     171        self.flash(_('All hostels cleared.'))
     172        write_log_message(self, 'all hostels cleared')
     173        self.redirect(self.url(self.context, '@@manage')+'?tab2')
     174        return
     175
    166176    @action(_('Save'), style='primary')
    167177    def save(self, **data):
     
    232242    tabtwoactions = [_('Update all beds'),
    233243        _('Switch reservation of selected beds'),
    234         _('Release selected beds')]
     244        _('Release selected beds'),
     245        _('Clear hostel')]
    235246    not_occupied = NOT_OCCUPIED
    236247
     
    243254        tabs.need()
    244255        datatable.need()
     256        warning.need()
    245257        self.tab1 = self.tab2 = ''
    246258        qs = self.request.get('QUERY_STRING', '')
     
    327339        return
    328340
     341    @jsaction(_('Clear hostel'))
     342    def clearHostel(self, **data):
     343        self.context.clearHostel()
     344        self.flash(_('Hostel cleared.'))
     345        write_log_message(self, 'cleared')
     346        self.redirect(self.url(self.context, '@@manage')+'?tab2')
     347        return
     348
    329349class BedManageFormPage(KofaEditFormPage):
    330350    """ View to edit bed data
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/container.py

    r8686 r9197  
    5151        return
    5252
     53    def clearAllHostels(self):
     54        """Clear all hostels.
     55        """
     56        for hostel in self.values():
     57            hostel.clearHostel()
     58        return
     59
    5360    logger_name = 'waeup.kofa.${sitename}.hostels'
    5461    logger_filename = 'hostels.log'
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py

    r9196 r9197  
    5151
    5252    def clearHostel(self):
    53         """Remove all beds.
    54 
    55         This methods is pretty fast and optimized. Use it instead of
    56         removing all items manually yourself.
    57         """
    58         # This internal function is implemented in C and thus much
    59         # faster as we could do it in pure Python.
    60         self._SampleContainer__data.clear()
    61         # The length attribute is 'lazy'. See `zope.container` for details.
    62         # This way we make sure, the next time len() is called, it returns
    63         # the real value and not a cached one.
    64         del self.__dict__['_BTreeContainer__len']
     53        """Remove all beds
     54        """
     55        keys = [i for i in self.keys()] # create deep copy
     56        for bed in keys:
     57            del self[bed]
     58        return
    6559
    6660    def addBed(self, bed):
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/interfaces.py

    r9196 r9197  
    5757        default = [],
    5858        )
     59
     60    def clearAllHostels():
     61        """Clear all hostels.
     62        """
    5963
    6064class IHostel(IKofaObject):
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r9196 r9197  
    1919Tests for hostels and their UI components.
    2020"""
     21import os
    2122import shutil
    2223import tempfile
     
    349350        results = [x for x in results]
    350351        assert len(results) == 0
     352
     353    def test_clear_hostels(self):
     354        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     355        self.browser.open(self.container_path)
     356        self.browser.getLink("Manage accommodation").click()
     357        self.browser.getControl("Add hostel").click()
     358        self.browser.getControl("Create hostel").click()
     359        hall = self.app['hostels']['hall-1']
     360        hall.blocks_for_female = ['A','B']
     361        hall.rooms_per_floor = 1
     362        hall.beds_for_fresh = ['A']
     363        hall.beds_for_returning = ['B']
     364        hall.beds_for_final = ['C']
     365        hall.beds_for_all = ['D','E']
     366        self.browser.open(self.container_path + '/hall-1/manage')
     367        self.browser.getControl("Update all beds").click()
     368        cat = queryUtility(ICatalog, name='beds_catalog')
     369        results = cat.searchResults(bed_type=(None, None))
     370        self.assertEqual(len(results), 11)
     371        self.browser.getControl("Clear hostel").click()
     372        self.assertEqual(len(self.app['hostels']['hall-1']), 0)
     373        # Only the bed in hall-x remains in the catalog.
     374        results = cat.searchResults(bed_type=(None, None))
     375        self.assertEqual(len(results), 1)
     376        # We can clear all hostels at the same time.
     377        self.browser.open(self.manage_container_path)
     378        self.browser.getControl("Clear all hostels").click()
     379        results = cat.searchResults(bed_type=(None, None))
     380        self.assertEqual(len(results), 0)
     381        # Both actions have been logged.
     382        logfile = os.path.join(
     383            self.app['datacenter'].storage, 'logs', 'hostels.log')
     384        logcontent = open(logfile).read()
     385        self.assertTrue('INFO - zope.mgr - hostels.browser.HostelManageFormPage'
     386                        ' - hall-1 - cleared' in logcontent)
     387        self.assertTrue('zope.mgr - hostels.browser.HostelsContainerManagePage'
     388                        ' - hostels - all hostels cleared' in logcontent)
Note: See TracChangeset for help on using the changeset viewer.