Ignore:
Timestamp:
11 Nov 2015, 22:24:22 (9 years ago)
Author:
Henrik Bettermann
Message:

Add event handler which removes bed object from bed ticket if bed is removed.

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

Legend:

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

    r13352 r13440  
    306306        notify(grok.ObjectModifiedEvent(bedticket.bed))
    307307
     308@grok.subscribe(IBed, grok.IObjectRemovedEvent)
     309def handle_bed_removed(bed, event):
     310    """If a bed is deleted, we make sure that the bed object is
     311    removed also from the owner's bed ticket.
     312    """
     313    if bed.owner == NOT_OCCUPIED:
     314        return
     315    accommodation_session = grok.getSite()['hostels'].accommodation_session
     316    try:
     317        bedticket = grok.getSite()['students'][bed.owner][
     318                      'accommodation'][str(accommodation_session)]
     319    except KeyError:
     320        return
     321    bedticket.bed = None
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r13432 r13440  
    145145        self.student['studycourse'].current_session = 2004
    146146        self.student['studycourse'].entry_session = 2004
     147
    147148        # The students_catalog must be informed that the
    148149        # session attribute has changed
     
    435436        self.browser.open(self.container_path)
    436437        self.assertTrue('2 of 10' in self.browser.contents)
     438        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
    437439        # Remove entire hostel.
    438440        self.browser.open(self.manage_container_path)
     
    447449        results = [x for x in results]
    448450        assert len(results) == 0
     451        # Bed has been removed from bedticket
     452        self.assertEqual(bedticket.bed, None)
    449453        # Actions are logged.
    450454        logcontent = open(self.logfile).read()
Note: See TracChangeset for help on using the changeset viewer.