Changeset 7003 for main


Ignore:
Timestamp:
4 Nov 2011, 21:26:33 (13 years ago)
Author:
Henrik Bettermann
Message:

We have to call notify(grok.ObjectModifiedEvent?(self)) to update the catalog when only an attribute is changed.

Only one bed per student is allowed.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
3 edited

Legend:

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

    r6998 r7003  
    1818"""
    1919import grok
     20from zope.event import notify
    2021from datetime import datetime
    2122from grok import index
     
    130131        if self.owner == NOT_OCCUPIED:
    131132            self.owner = student_id
     133            notify(grok.ObjectModifiedEvent(self))
    132134            return None
    133135        else:
     
    135137
    136138    def switchReservation(self):
    137         """Reserves a bed or unreserve bed respectively.
     139        """Reserves or unreserve bed respectively.
    138140        """
    139141        sh, sex, bt = self.bed_type.split('_')
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py

    r6988 r7003  
    1919import shutil
    2020import tempfile
     21import grok
     22from zope.event import notify
     23
    2124from zope.interface.verify import verifyClass, verifyObject
    2225from zope.component.hooks import setSite, clearSite
     
    130133        # We can find a certain bed
    131134        cat = queryUtility(ICatalog, name='beds_catalog')
    132         results = cat.searchResults(bed_type=('abc', 'abc'))
     135        results = cat.searchResults(bed_type=(u'abc', u'abc'))
     136        results = [x for x in results] # Turn results generator into list
     137        assert len(results) == 1
     138        assert results[0] is self.app['hostels']['hall-x']['xyz']
     139
     140    def test_search_by_owner(self):
     141        # We can find a certain bed
     142        myobj = self.app['hostels']['hall-x']['xyz']
     143        myobj.owner = u'abc'
     144        notify(grok.ObjectModifiedEvent(myobj))
     145        cat = queryUtility(ICatalog, name='beds_catalog')
     146        results = cat.searchResults(owner=(u'abc', u'abc'))
    133147        results = [x for x in results] # Turn results generator into list
    134148        assert len(results) == 1
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r6997 r7003  
    11081108            self.flash('Activation code is invalid.')
    11091109            return
    1110         # Search a bed and exit if no bed is found
     1110        # Search a bed and exit if no bed is found or if the student
     1111        # has already booked a bed
    11111112        cat = queryUtility(ICatalog, name='beds_catalog', default=None)
    11121113        entries = cat.searchResults(
     
    11171118            self.flash('There is no free bed in your category %s.'
    11181119                        % acc_details['bt'])
     1120            return
     1121        entries = cat.searchResults(
     1122            owner=(student.student_id,student.student_id))
     1123        if len(entries):
     1124            bed = [entry for entry in entries][0]
     1125            self.flash('You already booked bed %s.'
     1126                        % bed.bed_id)
    11191127            return
    11201128        # Mark pin as used (this also fires a pin related transition)
Note: See TracChangeset for help on using the changeset viewer.