# Path: privagal/core/models.py
# class Token(models.Model):
#     """
#     Heavily copied from rest_framework.authtoken.models.Token
#     """
#     key = models.CharField(_("Key"), max_length=40, primary_key=True)
#     created = models.DateTimeField(_("Created"), auto_now_add=True)
# 
#     objects = TokenManager()
# 
#     class Meta:
#         db_table = 'privagal_token'
#         get_latest_by = "created"
# 
#     def save(self, *args, **kwargs):
#         if not self.key:
#             self.key = Token.generate_key()
#         return super(Token, self).save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.key
# 
#     @classmethod
#     def generate_key(cls):
#         return binascii.hexlify(os.urandom(20)).decode()


from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from ..models import Token
# -*- coding: utf-8 -*-
from __future__ import unicode_literals




@receiver(post_save, sender=Token)
def token_save_reset_singleton(sender, instance=None, created=False, **kwargs):
    Token.objects.reset_singleton()


@receiver(post_delete, sender=Token)
def token_delete_reset_singleton(sender, instance=None, created=False, **kwargs):

# Path: privagal/core/models.py
# class Token(models.Model):
#     """
#     Heavily copied from rest_framework.authtoken.models.Token
#     """
#     key = models.CharField(_("Key"), max_length=40, primary_key=True)
#     created = models.DateTimeField(_("Created"), auto_now_add=True)
# 
#     objects = TokenManager()
# 
#     class Meta:
#         db_table = 'privagal_token'
#         get_latest_by = "created"
# 
#     def save(self, *args, **kwargs):
#         if not self.key:
#             self.key = Token.generate_key()
#         return super(Token, self).save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.key
# 
#     @classmethod
#     def generate_key(cls):
#         return binascii.hexlify(os.urandom(20)).decode()


# Path: privagal/core/signals/handlers.py
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from ..models import Token

# -*- coding: utf-8 -*-
from __future__ import unicode_literals




@receiver(post_save, sender=Token)
def token_save_reset_singleton(sender, instance=None, created=False, **kwargs):
    Token.objects.reset_singleton()


@receiver(post_delete, sender=Token)
def token_delete_reset_singleton(sender, instance=None, created=False, **kwargs):

    Token.objects.reset_singleton()