15 May 16:36
Re: Pre-commit hooks
From: Roger Demetrescu <roger.demetrescu <at> gmail.com>
Subject: Re: Pre-commit hooks
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-15 14:36:52 GMT
Subject: Re: Pre-commit hooks
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-15 14:36:52 GMT
On 5/15/08, Yannick Gingras <ygingras <at> ygingras.net> wrote:
>
> Michael Bayer <mike_mp <at> zzzcomputing.com> writes:
>
> > easy enough to build yourself a generic MapperExtension that scans
> > incoming objects for a "_pre_commit()" method.
>
> Yeah indeed. I used this:
>
> ------------------------------
> class HookExtension(MapperExtension):
> """ Extention to add pre-commit hooks.
>
> Hooks will be called in Mapped classes if they define any of these
> methods:
> * _pre_insert()
> * _pre_delete()
> * _pre_update()
> """
> def before_insert(self, mapper, connection, instance):
> if getattr(instance, "_pre_insert", None):
> instance._pre_insert()
> return EXT_CONTINUE
[cut]
Any reason for not using hasattr ? Like...
def before_insert(self, mapper, connection, instance):
if hasattr(instance, "_pre_insert"):
instance._pre_insert()
return EXT_CONTINUE
Cheers,
Roger
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalchemy <at> googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
RSS Feed