source: main/waeup.sirp/trunk/src/waeup/sirp/hostel/hostelcontainer.py @ 6534

Last change on this file since 6534 was 4920, checked in by uli, 15 years ago

Make unit tests run again with the new package layout.

  • Property svn:eol-style set to native
File size: 1.1 KB
Line 
1import grok
2from zope.component.interfaces import IFactory
3from zope.interface import implementedBy
4from waeup.sirp.interfaces import IHostelContainer, IHostel
5
6class HostelContainer(grok.Container):
7
8    grok.implements(IHostelContainer)
9    grok.require('waeup.manageUniversity')
10
11    # A simple counter for ids.
12    next_id = 0L
13
14    def addHostel(self, hostel):
15        if not IHostel.providedBy(hostel):
16            raise TypeError('HostelContainers contain only IHostel instances')
17        id = str(self.next_id)
18        self[id] = hostel
19        while self.next_id in self.keys():
20            # Look for next unused int...
21            self.next_id += 1
22        return id
23
24class HostelContainerFactory(grok.GlobalUtility):
25    """A factory for faculty containers.
26    """
27    grok.implements(IFactory)
28    grok.name(u'waeup.HostelContainer')
29    title = u"Create a new hostel container.",
30    description = u"This factory instantiates new hostel containers."
31
32    def __call__(self):
33        return HostelContainer()
34
35    def getInterfaces(self):
36        return implementedBy(HostelContainer)
Note: See TracBrowser for help on using the repository browser.