Hi,
I'm writing a capability for registering db_hook dynamically. The code
snippet follows the mail body.
It works well except my code can not distinguish newly created entity
from updated entity.
I'd like to know how can I know if the entity is created or just
updated. What is the most appropriate way?
Regards,
------------------------------------------------------------------------------------------
from google.appengine.api import apiproxy_stub_map
from google.appengine.api import datastore
from google.appengine.ext import db
post_save_hooks = {}
def register_post_save_hook(func, model):
global post_save_hooks
kind = model.kind()
func_list = post_save_hooks.get(kind, None)
if func_list is None:
func_list = []
func_list.append(func)
post_save_hooks[kind] = func_list
def execute_hooks(kind, key, entity):
func_list = post_save_hooks.get(kind, None)
if func_list is not None:
entity.key_.CopyFrom(key)
e = datastore.Entity._FromPb(entity)
instance = db.class_for_kind(kind).from_entity(e)
for func in func_list:
func(instance)
def db_hook(service, call, request, response):
if call == 'Put':
from kay.utils.db_hook import execute_hooks
for key, entity in zip(response.key_list(), request.entity_list()):
kind = model_name_from_key(key)
execute_hooks(kind, key, entity)
apiproxy_stub_map.apiproxy.GetPostCallHooks().Append(
'db_hook', db_hook, 'datastore_v3')
------------------------------------------------------------------------------------------
--
Takashi Matsuo
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---