avoid throwing exception for model_policies that don't exist
[plstackapi.git] / planetstack / model_policy.py
1 from django.db.models.signals import post_save
2 from django.dispatch import receiver
3 import pdb
4 from core.models import *
5 import model_policies
6
7 @receiver(post_save)
8 def post_save_handler(sender, instance, **kwargs):
9         sender_name = sender.__name__
10         policy_name = 'model_policy_%s'%sender_name
11         
12         if (not kwargs['update_fields']):
13                 try:
14                         policy_handler = getattr(model_policies, policy_name, None)
15                         if policy_handler is not None:
16                                 policy_handler.handle(instance)
17                 except:
18                         pass