File: ex_56_signals-after-flush.py

package info (click to toggle)
sqlkit 0.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,184 kB
  • sloc: python: 17,477; sql: 166; makefile: 95; xml: 23; sh: 11
file content (30 lines) | stat: -rw-r--r-- 869 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""signals/after-flush

after-flush is triggered from withing SessionExtension as after_flush method.
It's emitted when flushing has occurred but state of the session still retains
all info on objects: session.dirty, session.new, session.deleted are available
and each object has info on it's history

Try changing some values and read the output
"""


t = SqlTable(model.Director, dbproxy=db, )

def after_flush_cb(sqlwidget, obj, session):
    from sqlkit.db.utils import get_differences

    for o in session.new:
        print "New object: %s" % o
    for o in session.dirty:
        print "Updated objects: %s" % o
        for field_name, old, new in get_differences(o):
            print "%s: %s ==> %s" % (field_name, old, new)
        
    for o in session.deleted:
        print "Deleted objects: %s" % o


t.connect('after-flush', after_flush_cb)
t.reload()