Oleg Broytmann wrote:
> BTW, the signals are not mentioned in the docs, not a single word, not in
> an example. Can you write a few words/sentences/paragraphs/examples about
> them?

Sure, although part of the reason I mentioned them is because I was
hoping someone would tell me what they were for :-) The mechanics of how
to use them are covered by comments in events.py, but it's not clear the
use cases for all of them, or for example why some signals pass
post_funcs, which seems useless to me.

But in any case, here's a quick stab at some docs, in the hopes that you
or whoever wrote signals.py can improve them:

Signals
-------

Signals are a mechanism to be notified when data or schema changes
happen through SQLObject. This may be useful for doing custom data
validation, logging changes, or XXXX (Oleg?). Some of what signals can
do is also possible by overriding methods, but signals may provide a
cleaner way, especially across classes not related by inheritance.

Example:

from sqlobject.events import listen, RowUpdateSignal, RowCreatedSignal
from model import Users

def update_listener(instance, kwargs):
    """keep "last_updated" field current"""
    import datetime
    # BAD method 1, causes infinite recursion?
    # instance should be read-only
    instance.last_updated = datetime.datetime.now()
    # GOOD method 2
    kwargs['last_updated'] = datetime.datetime.now()

def created_listener(kwargs, post_funcs):
    """"email me when new users added"""
    # email() implementation left as an exercise for the reader
    msg = "%s just was just added to the database!" % kwargs['name']
    email(msg)

listen(update_listener, Users, RowUpdateSignal)
listen(created_listener, Users, RowCreatedSignal)

<cut n paste from comments in event.py here?>

HTH -- Regards -- Andy

PS btw I think the comment for RowCreatedSignal is cut n pasted from
RowCreateSignal, and may not be correct.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to