The most recent SDK (1.1.8) now allows hooks, and that seems to be the best way to hack datastore puts. Jens (http://blog.appenginefan.com/) has started to blog about use of the hook feature and gave two examples at our local App Engine meetup tonight. Stay tuned to his blog for a good explanation.
In the meantime, look at appengine.api.apiproxy_stub_map.py and you'll see some hook methods. You can register methods to run pre- or post- put. If you supply a hook at this level of the API, you can use your hack even when bypassing the Model API. On Jan 17, 11:15 am, James Ashley <[email protected]> wrote: > The "simple" answer seems to be "override the db class." That's > totally off the top of my head, and it may be completely unrealistic. > > Something like (totally untested and almost definitely wrong. Consider > it pseudo-code): > > class my_db(google.ext.db): > def put(self, *objects, **kwargs): > for o in objects: > o.pre_put() > super(google.ext.db, self).put(*objects, **kwargs) > > Then the models that were overriding put() could put that override > code in pre_put() instead (and change put() to just call that before > calling super().put()...). > > You'd have to juggle the nuances of things like post_put(), and any > side-effects. But it seems like a reasonable compromise. > > On Jan 14, 2:22 pm, boson <[email protected]> wrote: > > > That is a curious situation. I would like to know also if there is a > > way to inject code into the put-stream regardless of method called, as > > I have various put() overrides as well. > > > On Jan 13, 9:45 pm, Devel63 <[email protected]> wrote: > > > > I overrode the put method on a class derived from Model, primarily > > > because I wanted to do some accounting work when a new object was > > > saved (in the simplest case, just keeping track of a counter). It > > > does its work, then calls super. > > > > It works fine. > > > > Until I use db.put([ob1,obj2,obj3]) to save a bunch of these, and then > > > of course the individual object.put() functions are never called. > > > > Is there a best practice for this? I really liked having it in the > > > "put", because then no caller needed to know about it, and it just > > > took care of itself. Is the best thing to precede every "put" call > > > with an explicit "put_prep" call? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
