root / elixir / tags / 0.6.0 / elixir / events.py

Revision 352, 0.9 kB (checked in by ged, 4 years ago)

Added on_reconstitute event/method decorator. The decorator is directly
imported from SA. Only works for SA 0.5

Line 
1__all__ = [
2    'before_insert',
3    'after_insert',
4    'before_update',
5    'after_update',
6    'before_delete',
7    'after_delete',
8    'on_reconstitute'
9]
10
11def create_decorator(event_name):
12    def decorator(func):
13        if not hasattr(func, '_elixir_events'):
14            func._elixir_events = []
15        func._elixir_events.append(event_name)
16        return func
17    return decorator
18
19before_insert = create_decorator('before_insert')
20after_insert = create_decorator('after_insert')
21before_update = create_decorator('before_update')
22after_update = create_decorator('after_update')
23before_delete = create_decorator('before_delete')
24after_delete = create_decorator('after_delete')
25try:
26    from sqlalchemy.orm.attributes import on_reconstitute
27except ImportError:
28    def on_reconstitute(func):
29        raise Exception('The on_reconstitute method decorator is only '
30                        'available with SQLAlchemy 0.5 and later')
Note: See TracBrowser for help on using the browser.