Dirty objects that depend on dirtied objects up to one level
authorSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 5 Nov 2014 04:57:48 +0000 (23:57 -0500)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 5 Nov 2014 04:57:48 +0000 (23:57 -0500)
planetstack/model_policy.py

index ba0cb99..1262d26 100644 (file)
@@ -2,17 +2,29 @@ from django.db.models.signals import post_save
 from django.dispatch import receiver
 import pdb
 from core.models import *
+from dependency_walker import *
 import model_policies
 
+def update_dep(d, o):
+       print "Updating %s (%s)"%(d,d.__class__.__name__)
+       if (d.updated < o.updated):
+               d.save(update_fields=['updated'])
+       
 @receiver(post_save)
 def post_save_handler(sender, instance, **kwargs):
        sender_name = sender.__name__
        policy_name = 'model_policy_%s'%sender_name
        
        if (not kwargs['update_fields']):
+               # Automatic dirtying
+               walk_inv_deps(update_dep, instance)
+
                try:
                        policy_handler = getattr(model_policies, policy_name, None)
                        if policy_handler is not None:
                                policy_handler.handle(instance)
+                       
+                       
                except:
                        pass
+