diff --git a/apps/user/models.py b/apps/user/models.py index 0572e4d0..db34018e 100644 --- a/apps/user/models.py +++ b/apps/user/models.py @@ -1,4 +1,6 @@ from django.db import models +from django.db.models.signals import post_save +from django.dispatch import receiver from django.contrib.auth.models import AbstractUser, UserManager from django.contrib.postgres import fields as pgfields from django.utils.translation import gettext_lazy as _ @@ -59,16 +61,17 @@ class User(AbstractUser): user_data = dumps(user_data, ensure_ascii=False) return user_data - @receiver(post_save, sender=User) - def create_auth_token(sender, instance=None, created=False, **kwargs): - if ( - (instance.is_active or instance.fb_id) and - instance.role in [User.AUTHOR_ROLE, User.ADMIN_ROLE] and not - hasattr(instance, 'auth_token') - ): - Token.objects.create(user=instance) - elif ( - not (instance.is_active or instance.fb_id) or - instance.role not in [User.AUTHOR_ROLE, User.ADMIN_ROLE] - ) and hasattr(instance, 'auth_token'): - instance.auth_token.delete() + +@receiver(post_save, sender=User) +def create_auth_token(sender, instance=None, created=False, **kwargs): + if ( + (instance.is_active or instance.fb_id) and + instance.role in [User.AUTHOR_ROLE, User.ADMIN_ROLE] and not + hasattr(instance, 'auth_token') + ): + Token.objects.create(user=instance) + elif ( + not (instance.is_active or instance.fb_id) or + instance.role not in [User.AUTHOR_ROLE, User.ADMIN_ROLE] + ) and hasattr(instance, 'auth_token'): + instance.auth_token.delete()