2018-12-10 13:05:27 +00:00
|
|
|
"""passbook core signals"""
|
2019-03-21 10:29:11 +00:00
|
|
|
from django.core.cache import cache
|
2018-12-10 13:05:27 +00:00
|
|
|
from django.core.signals import Signal
|
2019-03-21 10:29:11 +00:00
|
|
|
from django.db.models.signals import post_save
|
2019-02-26 14:40:58 +00:00
|
|
|
from django.dispatch import receiver
|
2019-10-01 09:24:10 +01:00
|
|
|
from structlog import get_logger
|
2018-12-10 13:05:27 +00:00
|
|
|
|
2019-10-04 09:08:53 +01:00
|
|
|
LOGGER = get_logger()
|
2019-03-21 10:29:11 +00:00
|
|
|
|
2018-12-10 13:05:27 +00:00
|
|
|
user_signed_up = Signal(providing_args=['request', 'user'])
|
2018-12-10 13:21:42 +00:00
|
|
|
invitation_created = Signal(providing_args=['request', 'invitation'])
|
|
|
|
invitation_used = Signal(providing_args=['request', 'invitation', 'user'])
|
2019-02-25 14:41:36 +00:00
|
|
|
password_changed = Signal(providing_args=['user', 'password'])
|
2019-02-26 14:40:58 +00:00
|
|
|
|
2019-03-21 10:29:11 +00:00
|
|
|
@receiver(post_save)
|
|
|
|
# pylint: disable=unused-argument
|
2019-10-07 15:33:48 +01:00
|
|
|
def invalidate_policy_cache(sender, instance, **_):
|
2019-03-21 10:29:11 +00:00
|
|
|
"""Invalidate Policy cache when policy is updated"""
|
|
|
|
from passbook.core.models import Policy
|
|
|
|
if isinstance(instance, Policy):
|
2019-10-04 09:21:33 +01:00
|
|
|
LOGGER.debug("Invalidating policy cache", policy=instance)
|
2019-03-21 10:29:11 +00:00
|
|
|
keys = cache.keys("%s#*" % instance.pk)
|
|
|
|
cache.delete_many(keys)
|
|
|
|
LOGGER.debug("Deleted %d keys", len(keys))
|