Changeset 5414

Show
Ignore:
Timestamp:
09/12/08 00:24:44 (4 months ago)
Author:
mramm
Message:

Adding an ignore_commits decorator which can be used to postpone commits to the tg2 transaction boundary.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/setup.py

    r5085 r5414  
    2525    install_requires=[ 
    2626        'Babel', 
     27        'decorator', 
    2728        'Genshi', 
    2829        'Pylons>=0.9.7beta3', 
  • trunk/tg/decorators.py

    r5341 r5414  
    88import formencode 
    99from paste.util.mimeparse import best_match 
     10from decorator import decorator 
    1011 
    1112from webob.multidict import MultiDict 
     
    1314from tg.configuration import Bunch 
    1415# this can't be tg, as we are circular importing then! 
    15 from pylons import request 
     16from pylons import config, request 
    1617from pylons import tmpl_context as c 
    1718from util import partial 
     
    328329    return _d 
    329330 
    330  
     331@decorator 
     332def ignore_commits(func, *args, **kwargs): 
     333    #TODO: Test and document this. 
     334    s = config.get('DBSession', None) 
     335    assert hasattr(s, 'commit') 
     336    old_commit = s.commit 
     337    s.commit = s.flush 
     338    retval = func(*args, **kwargs) 
     339    s.commit = old_commit 
     340    return retval 
     341     
     342