from corres2math.lists import get_sympa_client from django.contrib.auth.models import User from .models import AdminRegistration, Registration def set_username(instance, **_): instance.username = instance.email def send_email_link(instance, **_): if instance.pk: old_instance = User.objects.get(pk=instance.pk) if old_instance.email != instance.email: registration = Registration.objects.get(user=instance) registration.email_confirmed = False registration.save() registration.user = instance registration.send_email_validation_link() if registration.participates and registration.team: get_sympa_client().unsubscribe(old_instance.email, f"equipe-{registration.team.trigram.lower()}", False) get_sympa_client().subscribe(instance.email, f"equipe-{registration.team.trigram.lower()}", False, f"{instance.first_name} {instance.last_name}") def create_admin_registration(instance, **_): if instance.is_superuser: AdminRegistration.objects.get_or_create(user=instance)