Ignore:
Timestamp:
18 Sep 2012, 10:42:09 (12 years ago)
Author:
Henrik Bettermann
Message:

Show number of occupied beds on hostels page.

Add clearHostel method. Not yet tested.

File:
1 edited

Legend:

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

    r8685 r9196  
    4040        target = self.__name__
    4141        return grok.getSite()['hostels'].logger_info(ob_class,target,comment)
     42
     43    @property
     44    def bed_statistics(self):
     45        total = len(self.keys())
     46        booked = 0
     47        for value in self.values():
     48            if value.owner != NOT_OCCUPIED:
     49                booked += 1
     50        return {'booked':booked, 'total':total}
     51
     52    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']
    4265
    4366    def addBed(self, bed):
Note: See TracChangeset for help on using the changeset viewer.