1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-01-19 06:31:20 +00:00
nk20/apps/note/signals.py

31 lines
878 B
Python
Raw Normal View History

2020-02-18 21:30:26 +01:00
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
2019-07-19 15:00:44 +02:00
# SPDX-License-Identifier: GPL-3.0-or-later
2020-04-05 06:40:03 +02:00
def save_user_note(instance, raw, **_kwargs):
2019-07-19 15:00:44 +02:00
"""
Hook to create and save a note when an user is updated
"""
2020-02-20 22:10:10 +01:00
if raw:
# When provisionning data, do not try to autocreate
return
if instance.is_superuser or instance.profile.registration_valid:
2020-04-05 06:40:03 +02:00
# Create note only when the registration is validated
from note.models import NoteUser
NoteUser.objects.get_or_create(user=instance)
instance.note.save()
2019-07-19 15:00:44 +02:00
2020-04-12 02:43:22 +02:00
def save_club_note(instance, raw, **_kwargs):
2019-07-19 15:00:44 +02:00
"""
Hook to create and save a note when a club is updated
"""
2020-02-20 22:10:10 +01:00
if raw:
# When provisionning data, do not try to autocreate
return
2020-04-12 02:43:22 +02:00
from .models import NoteClub
NoteClub.objects.get_or_create(club=instance)
2019-07-19 15:00:44 +02:00
instance.note.save()