src/pyams_alchemy/engine.py
changeset 23 06e3617fe77d
parent 22 9491c1528b80
child 30 35db50b26375
equal deleted inserted replaced
22:9491c1528b80 23:06e3617fe77d
    28 
    28 
    29 # import interfaces
    29 # import interfaces
    30 from pyams_alchemy.interfaces import REQUEST_SESSION_KEY, IAlchemyEngineUtility
    30 from pyams_alchemy.interfaces import REQUEST_SESSION_KEY, IAlchemyEngineUtility
    31 from pyams_utils.interfaces.site import IOptionalUtility
    31 from pyams_utils.interfaces.site import IOptionalUtility
    32 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
    32 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
    33 from zope.schema.interfaces import IVocabularyFactory
       
    34 
    33 
    35 # import packages
    34 # import packages
    36 from persistent import Persistent
    35 from persistent import Persistent
    37 from persistent.dict import PersistentDict
    36 from persistent.dict import PersistentDict
    38 from pyams_utils.registry import query_utility
    37 from pyams_utils.registry import query_utility
    39 from pyams_utils.request import check_request, get_request_data, set_request_data
    38 from pyams_utils.request import check_request, get_request_data, set_request_data
       
    39 from pyams_utils.vocabulary import vocabulary_config
    40 from pyramid.events import subscriber
    40 from pyramid.events import subscriber
    41 from zope.componentvocabulary.vocabulary import UtilityVocabulary
    41 from zope.componentvocabulary.vocabulary import UtilityVocabulary
    42 from zope.container.contained import Contained
    42 from zope.container.contained import Contained
    43 from zope.interface import implementer, provider
    43 from zope.interface import implementer
    44 from zope.schema.fieldproperty import FieldProperty
    44 from zope.schema.fieldproperty import FieldProperty
    45 from zope.schema.vocabulary import getVocabularyRegistry
       
    46 from zope.sqlalchemy.datamanager import _SESSION_STATE, STATUS_READONLY, STATUS_ACTIVE, \
    45 from zope.sqlalchemy.datamanager import _SESSION_STATE, STATUS_READONLY, STATUS_ACTIVE, \
    47     ZopeTransactionExtension, join_transaction
    46     ZopeTransactionExtension, join_transaction
    48 
    47 
    49 
    48 
    50 CONNECTIONS_TIMESTAMP = {}
    49 CONNECTIONS_TIMESTAMP = {}
   243     else:
   242     else:
   244         session = engine
   243         session = engine
   245     return session
   244     return session
   246 
   245 
   247 
   246 
   248 @provider(IVocabularyFactory)
   247 @vocabulary_config(name='PyAMS SQLAlchemy engines')
   249 class EnginesVocabulary(UtilityVocabulary):
   248 class EnginesVocabulary(UtilityVocabulary):
   250     """SQLAlchemy engines vocabulary"""
   249     """SQLAlchemy engines vocabulary"""
   251 
   250 
   252     interface = IAlchemyEngineUtility
   251     interface = IAlchemyEngineUtility
   253     nameOnly = True
   252     nameOnly = True
   254 
       
   255 getVocabularyRegistry().register('PyAMS SQLAlchemy engines', EnginesVocabulary)