source: main/waeup.ikoba/trunk/src/waeup/ikoba/app.py @ 14221

Last change on this file since 14221 was 12741, checked in by uli, 10 years ago

Merge changes from uli-payments back into trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.0 KB
RevLine 
[7193]1## $Id: app.py 12741 2015-03-12 05:29:43Z uli $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
[3521]18import grok
[6362]19from zope.authentication.interfaces import IAuthentication
[9217]20from zope.component import getUtility, getUtilitiesFor
[6137]21from zope.component.interfaces import ObjectEvent
[6362]22from zope.pluggableauth import PluggableAuthentication
[11949]23from waeup.ikoba.authentication import setup_authentication
24from waeup.ikoba.datacenter import DataCenter
25from waeup.ikoba.mandates.container import MandatesContainer
26from waeup.ikoba.interfaces import (
[11954]27    ICompany, IIkobaPluggable, IObjectUpgradeEvent, IJobManager,
[9217]28    VIRT_JOBS_CONTAINER_NAME)
[11949]29from waeup.ikoba.userscontainer import UsersContainer
30from waeup.ikoba.utils.logger import Logger
31from waeup.ikoba.utils.helpers import attrs_to_fields
32from waeup.ikoba.configuration import ConfigurationContainer
[4789]33
[11956]34from waeup.ikoba.customers.container import CustomersContainer
[12065]35from waeup.ikoba.products.container import ProductsContainer
[12207]36from waeup.ikoba.documents.container import DocumentsContainer
[12741]37from waeup.ikoba.payments.container import PaymentsContainer
[11956]38
[12065]39
[11954]40class Company(grok.Application, grok.Container, Logger):
41    """A company.
[4789]42    """
[11954]43    grok.implements(ICompany)
[6129]44
[4789]45    # Setup authentication for this app. Note: this is only
46    # initialized, when a new instance of this app is created.
47    grok.local_utility(
48        PluggableAuthentication, provides = IAuthentication,
[5054]49        setup = setup_authentication,)
[5345]50
[6592]51    def __init__(self, *args, **kw):
[11954]52        super(Company, self).__init__(*args, **kw)
[4789]53        self.setup()
[6592]54        return
[3521]55
[4789]56    def setup(self):
[5345]57        """Setup some hard-wired components.
58
[11947]59        Create local datacenter, containers for users and
[5345]60        the like.
61        """
[7172]62        self['users'] = UsersContainer()
[4789]63        self['datacenter'] = DataCenter()
[6907]64        self['configuration'] = ConfigurationContainer()
[8846]65        self['mandates'] = MandatesContainer()
[11956]66        self['customers'] = CustomersContainer()
[12065]67        self['products'] = ProductsContainer()
[12207]68        self['documents'] = DocumentsContainer()
[12741]69        self['payments'] = PaymentsContainer()
[5016]70        self._createPlugins()
71
72    def _createPlugins(self):
73        """Create instances of all plugins defined somewhere.
74        """
[11949]75        for name, plugin in getUtilitiesFor(IIkobaPluggable):
[5071]76            plugin.setup(self, name, self.logger)
77        return
[5421]78
[9217]79    def traverse(self, name):
80        if name == VIRT_JOBS_CONTAINER_NAME:
81            return getUtility(IJobManager)
82        return None
83
[5421]84    def updatePlugins(self):
85        """Lookup all plugins and call their `update()` method.
86        """
[6138]87        name = getattr(self, '__name__', '<Unnamed>')
88        self.logger.info('Fire upgrade event for site %s' % name)
89        grok.notify(ObjectUpgradeEvent(self))
90        self.logger.info('Done.')
91        self.logger.info('Now upgrading any plugins.')
[11949]92        for name, plugin in getUtilitiesFor(IIkobaPluggable):
[5421]93            plugin.update(self, name, self.logger)
[6138]94        self.logger.info('Plugin update finished.')
[5421]95        return
[12065]96
[11954]97attrs_to_fields(Company)
[4884]98
[12065]99
[6137]100class ObjectUpgradeEvent(ObjectEvent):
101    """An event fired, when datacenter storage moves.
102    """
103    grok.implements(IObjectUpgradeEvent)
[6578]104
[11954]105@grok.subscribe(Company, grok.IObjectAddedEvent)
106def handle_company_added(app, event):
107    """If a company is added, a message is logged.
[11477]108    """
[11954]109    app.logger.info('Company `%s` added.' % getattr(app, '__name__', None))
[6578]110    return
Note: See TracBrowser for help on using the repository browser.