Sapan Bhatia | 0235e98 | 2014-09-03 13:14:40 -0400 | [diff] [blame] | 1 | from django.db.models.signals import post_save |
| 2 | from django.dispatch import receiver |
| 3 | import pdb |
Sapan Bhatia | fe9bc89 | 2014-09-15 03:48:11 -0400 | [diff] [blame] | 4 | from core.models import * |
| 5 | import model_policies |
Sapan Bhatia | 0235e98 | 2014-09-03 13:14:40 -0400 | [diff] [blame] | 6 | |
| 7 | @receiver(post_save) |
Scott Baker | 2ba3485 | 2014-09-30 14:53:45 -0700 | [diff] [blame] | 8 | def post_save_handler(sender, instance, **kwargs): |
Sapan Bhatia | 0235e98 | 2014-09-03 13:14:40 -0400 | [diff] [blame] | 9 | sender_name = sender.__name__ |
| 10 | policy_name = 'model_policy_%s'%sender_name |
Sapan Bhatia | 9a3af23 | 2014-09-15 04:04:32 -0400 | [diff] [blame] | 11 | |
| 12 | if (not kwargs['update_fields']): |
| 13 | try: |
Scott Baker | 6021fa8 | 2014-10-09 12:03:22 -0700 | [diff] [blame] | 14 | policy_handler = getattr(model_policies, policy_name, None) |
| 15 | if policy_handler is not None: |
| 16 | policy_handler.handle(instance) |
Sapan Bhatia | 9a3af23 | 2014-09-15 04:04:32 -0400 | [diff] [blame] | 17 | except: |
| 18 | pass |