I'm pretty sure the code on the GAE Hooks article ( http://code.google.com/appengine/articles/hooks.html) is wrong.
4th code snippet, shouldn't the very first line:
def path_appengine():
be moved to the bottom, just above this line:
apiproxy_stub_map.apiproxy.GetPreCallHooks().Append(....)
?
2010/1/15 Nickolas Daskalou <[email protected]>
> Thanks guys, both great suggestions.
>
> I'll try and get PreCallHook working because that would allow me to add a
> "pre_put()" method to my Models, and then using these PreCallHooks I can
> call pre_put() for each of the entities being put into the Datastore.
>
> Failing that, I'll create a new derived property for my Model and do as
> Devel63 said.
>
>
> 2010/1/15 Devel63 <[email protected]>
>
> Nick,
>>
>> I've been faced with your exact situation. I have to say I don't
>> understand PreCallHook, and maybe that would be the best approach, but
>> here's what I do know.
>>
>> Overriding "put" is a bad idea, and as you point out, the override
>> will not be called in a batch put.
>>
>> I found that the most elegant solution was to derive a new type of
>> db.Property, and override its get_value_for_datastore. Then GAE will
>> automatically do what you want regardless of how the entity is being
>> put.
>>
>>
>> On Jan 14, 1:51 am, Eric Ka Ka Ng <[email protected]> wrote:
>> > would a PreCallHook works for your case?
>> >
>> > http://code.google.com/appengine/articles/hooks.html
>> >
>> > - eric
>> >
>> > 2010/1/14 Nickolas Daskalou <[email protected]>:
>> >
>> > > I have a property of a Model that is a hash of another property of the
>> same
>> > > Model, eg:
>> >
>> > > class MyModel(db.Model):
>> > > something = db.StringProperty()
>> > > something_hash = db.StringProperty()
>> > > def generate_hash(self):
>> > > self.something_hash = sha1(self.something)
>> >
>> > > I want generate_hash() to be automatically called just before the
>> entity is
>> > > put() into the Datastore, without the developer having to explicitly
>> call
>> > > entity.generate_hash().
>> >
>> > > I know I can create a put() method that makes such a call and then
>> calls
>> > > put() on the superclass, but (a) is that the best way to do it, and
>> (b) if
>> > > the put() is part of a batch put (eg. via db.put(entities)), will the
>> put()
>> > > method of each model instance still be called?
>> >
>> > > Nick
>> >
>> > > --
>> > > 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]<google-appengine%[email protected]>
>> .
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/google-appengine?hl=en.
>>
>> --
>> 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]<google-appengine%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine?hl=en.
>>
>>
>>
>>
>
-- 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.
