def create_application(factory, container, name): """Creates an application and triggers the events from the application lifecycle. """ # Check the factory. assert IApplication.implementedBy(factory) # Check the availability of the name in the container. if name in container: raise KeyError(name) # Instanciate the application application = factory() # Trigger the creation event. notify(ObjectCreatedEvent(application)) # Persist the application. # This may raise a KeyError. container[name] = application # Trigger the initialization event. notify(ApplicationInitializedEvent(application)) return application
def create_application(factory, container, name): """Creates an application and triggers the events from the application lifecycle. """ # Check the factory. if not IApplication.implementedBy(factory): raise WrongType(factory) # Check the availability of the name in the container. if name in container: raise KeyError(name) # Instanciate the application application = factory() # Trigger the creation event. notify(ObjectCreatedEvent(application)) # Persist the application. # This may raise a KeyError. container[name] = application # Trigger the initialization event with the new application as a # current site. current = getSite() setSite(application) try: notify(ApplicationAddedEvent(application)) finally: setSite(current) return application