Changeset 9196 for main


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.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/browser_templates/containerpage.pt

    r8685 r9196  
    2121      <th i18n:translate="">Id</th>
    2222      <th i18n:translate="">Name</th>
     23      <th i18n:translate="">Booked Beds</th>
    2324    </tr>
    2425  </thead>
    2526  <tbody>
    26     <tr tal:repeat="value context/values">
    27       <td> <a tal:attributes="href value/__name__">
    28           <span tal:content="value/hostel_id">ID</span></a></td>
    29       <td tal:content="value/hostel_name">NAME</td>
    30     </tr>
     27    <tal:tbody repeat="value context/values">
     28      <tr tal:define = "stats value/bed_statistics">
     29        <td> <a tal:attributes="href value/__name__">
     30            <span tal:content="value/hostel_id">ID</span></a></td>
     31        <td tal:content="value/hostel_name">NAME</td>
     32        <td>
     33          <span tal:replace="stats/booked">10</span> of <span tal:replace="stats/total">100</span>
     34        </td>
     35      </tr>
     36    </tal:tbody>
    3137  </tbody>
    3238</table>
  • 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):
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/interfaces.py

    r9146 r9196  
    1717##
    1818from datetime import datetime
    19 from zope.interface import invariant, Invalid
     19from zope.interface import invariant, Invalid, Attribute
    2020from zope import schema
    2121from waeup.kofa.interfaces import (
     
    6363    """
    6464
     65    bed_statistics = Attribute('Number of booked and total beds')
     66
    6567    def loggerInfo(ob_class, comment):
    6668        """Adds an INFO message to the log file
     69        """
     70
     71    def clearHostel():
     72        """Remove all beds.
    6773        """
    6874
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r8686 r9196  
    300300        self.assertMatches(
    301301          '...No allocated bed selected...', self.browser.contents)
    302         # Managers can manually allocate studenst after cancellation
     302        # Managers can manually allocate students after cancellation
    303303        self.browser.open(self.container_path + '/hall-1/hall-1_A_101_A')
    304304        self.browser.getControl(name="form.owner").value = [self.student_id]
     
    334334        # Also the number of the bed has changed.
    335335        self.assertFalse(new_number == old_number)
     336        # The number of occupied bed are displayed on container page.
     337        self.browser.open(self.container_path)
     338        self.assertTrue('1 of 8' in self.browser.contents)
    336339        # Remove entire hostel
    337340        self.browser.open(self.manage_container_path)
Note: See TracChangeset for help on using the changeset viewer.