Commit d3efcd73 authored by Lukas Burgey's avatar Lukas Burgey

Move some receivers

parent 62712de5
# django senders need their arguments
# pylint: disable=unused-argument
import json
import logging
from json import dumps
from logging import getLogger
from django.contrib.auth.models import Group
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django_mysql.models import JSONField
from .broker_models import RabbitMQInstance
from .user_models import User
LOGGER = logging.getLogger(__name__)
LOGGER = getLogger(__name__)
STATE_CHOICES = (
......@@ -502,7 +498,7 @@ class DeploymentState(models.Model):
def publish_to_client(self):
# mitigating circular dependencies here
from .clientapi.serializers import DeploymentStateSerializer
msg = json.dumps(DeploymentStateSerializer(self).data)
msg = dumps(DeploymentStateSerializer(self).data)
if self.service is not None:
RabbitMQInstance.load().publish_by_service(
......@@ -521,7 +517,7 @@ class DeploymentState(models.Model):
def publish_to_user(self):
if self.user is not None:
from .frontend.views import user_state
msg = json.dumps({
msg = dumps({
'user_state': user_state(self.user),
})
RabbitMQInstance.load().publish_to_user(
......@@ -734,25 +730,3 @@ class DeploymentStateItem(models.Model):
self.key.name,
self.id,
)
#
# RECEIVERS
#
@receiver(post_save, sender=User)
def deactivate_user(sender, instance=None, created=False, **kwargs):
if created:
return
if not instance.is_active and instance.is_active_at_clients:
instance.deactivate()
@receiver(post_save, sender=User)
def activate_user(sender, instance=None, created=False, **kwargs):
if created:
return
if instance.is_active and not instance.is_active_at_clients:
instance.activate()
# for receivers:
# pylint: disable=unused-argument
import logging
from django.contrib.auth.models import AbstractUser, Group
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django_mysql.models import JSONField
from .auth.v1.models import OIDCConfig
......@@ -246,3 +250,21 @@ class User(AbstractUser):
user=self,
)
key.save()
@receiver(post_save, sender=User)
def deactivate_user(sender, instance=None, created=False, **kwargs):
if created:
return
if not instance.is_active and instance.is_active_at_clients:
instance.deactivate()
@receiver(post_save, sender=User)
def activate_user(sender, instance=None, created=False, **kwargs):
if created:
return
if instance.is_active and not instance.is_active_at_clients:
instance.activate()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment