File: ex_65_hooks-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 (31 lines) | stat: -rw-r--r-- 919 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
31
"""hooks/on_after_flush

This hook is completely similar to 'after-flush' signal, but is meant to be
defined in a separate class so that it's easier to propagate validation hooks
to a spawned child (RecordInMask) 

Open a mask right clicking on a record, change something and save. You'll see
that on_after_flush is called eather.

"""
from sqlkit.db.utils import get_differences

class Validation(object):

    def on_after_flush(self, table, obj, session):

        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 = SqlTable(model.Director, dbproxy=db,
             order_by='first_name', hooks=Validation(),)
t.reload()