Ignore:
Timestamp:
3 Oct 2019, 10:09:25 (5 years ago)
Author:
Henrik Bettermann
Message:

Use factory to create beds and hostels.

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

Legend:

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

    r15254 r15633  
    2121import sys
    2222from zope.i18n import translate
    23 from zope.component import getUtility
     23from zope.component import getUtility, createObject
    2424from zope.catalog.interfaces import ICatalog
    2525from waeup.kofa.browser.layout import (
     
    273273    @action(_('Create hostel'))
    274274    def addHostel(self, **data):
    275         hostel = Hostel()
     275        hostel = container = createObject(u'waeup.Hostel')
    276276        self.applyData(hostel, **data)
    277277        hostel.hostel_id = data['hostel_name'].lower().replace(
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py

    r15417 r15633  
    2121import grok
    2222from zope.event import notify
    23 from zope.component import getUtility
     23from zope.component import getUtility, createObject
    2424from zope.component.interfaces import IFactory
    2525from datetime import datetime
     
    127127                                notify(grok.ObjectModifiedEvent(bed))
    128128                        else:
    129                             bed = Bed()
     129                            bed = createObject(u'waeup.Bed')
    130130                            bed.bed_id = uid
    131131                            bed.bed_type = bt
     
    309309        return implementedBy(Hostel)
    310310
     311class BedFactory(grok.GlobalUtility):
     312    """A factory for  beds.
     313
     314    We need this factory to ease customization.
     315    """
     316    grok.implements(IFactory)
     317    grok.name(u'waeup.Bed')
     318    title = u"Create a new bed.",
     319    description = u"This factory instantiates new bed instances."
     320
     321    def __call__(self, *args, **kw):
     322        return Bed()
     323
     324    def getInterfaces(self):
     325        return implementedBy(Bed)
     326
    311327
    312328@grok.subscribe(IBedTicket, grok.IObjectRemovedEvent)
Note: See TracChangeset for help on using the changeset viewer.