src/pyams_sequence/site.py
changeset 0 980ffaa51a75
child 28 83dc4748dbbb
equal deleted inserted replaced
-1:000000000000 0:980ffaa51a75
       
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from pyams_sequence.interfaces import ISequentialIntIds, ISequentialIdInfo
       
    20 from pyams_utils.interfaces.site import ISiteGenerations
       
    21 from zope.site.interfaces import INewLocalSite
       
    22 
       
    23 # import packages
       
    24 from pyams_catalog.index import FieldIndexWithInterface
       
    25 from pyams_catalog.site import check_required_indexes
       
    26 from pyams_sequence.utility import SequentialIntIds
       
    27 from pyams_utils.registry import utility_config
       
    28 from pyams_utils.site import check_required_utilities
       
    29 from pyramid.events import subscriber
       
    30 
       
    31 
       
    32 REQUIRED_UTILITIES = ((ISequentialIntIds, '', SequentialIntIds, 'Sequential IDs'), )
       
    33 
       
    34 
       
    35 REQUIRED_INDEXES = (('oid', FieldIndexWithInterface, {'interface': ISequentialIdInfo,
       
    36                                                       'discriminator': 'hex_oid'}), )
       
    37 
       
    38 
       
    39 @subscriber(INewLocalSite)
       
    40 def handle_new_local_site(event):
       
    41     """Check for required utilities when a site is created"""
       
    42     site = event.manager.__parent__
       
    43     check_required_utilities(site, REQUIRED_UTILITIES)
       
    44     check_required_indexes(site, REQUIRED_INDEXES)
       
    45 
       
    46 
       
    47 @utility_config(name='PyAMS sequence', provides=ISiteGenerations)
       
    48 class SequenceGenerationsChecker(object):
       
    49     """PyAMS sequence generations checker"""
       
    50 
       
    51     generation = 1
       
    52 
       
    53     def evolve(self, site, current=None):
       
    54         """Check for required utilities"""
       
    55         check_required_utilities(site, REQUIRED_UTILITIES)
       
    56         check_required_indexes(site, REQUIRED_INDEXES)