Move `delete` code to signal
This commit is contained in:
parent
68938ba44b
commit
e87ab1da57
|
|
@ -0,0 +1,24 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import django
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
sys.path.append("../server")
|
||||||
|
|
||||||
|
os.environ.setdefault("IT_APP_ENVIRONMENT", "local")
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.base")
|
||||||
|
django.setup()
|
||||||
|
|
||||||
|
|
||||||
|
from vbv_lernwelt.core.models import User
|
||||||
|
|
||||||
|
# Get the user whose password you want to use as the reference
|
||||||
|
reference_user = User.objects.get(email='axel.manderbach@lernetz.ch')
|
||||||
|
reference_user.set_password('test')
|
||||||
|
reference_user.save()
|
||||||
|
|
||||||
|
# Update the password for all users
|
||||||
|
with transaction.atomic():
|
||||||
|
User.objects.update(password=reference_user.password)
|
||||||
|
|
@ -94,30 +94,10 @@ class OrganisationSupervisor(models.Model):
|
||||||
create_or_sync_ausbildungsverantwortlicher(
|
create_or_sync_ausbildungsverantwortlicher(
|
||||||
self.supervisor, self.organisation
|
self.supervisor, self.organisation
|
||||||
)
|
)
|
||||||
else:
|
elif self.role == OrganisationSupervisortRoleType.BERUFSBILDNER.value:
|
||||||
from vbv_lernwelt.learning_mentor.services import (
|
from vbv_lernwelt.learning_mentor.services import (
|
||||||
create_or_sync_berufsbildner,
|
create_or_sync_berufsbildner,
|
||||||
)
|
)
|
||||||
|
|
||||||
create_or_sync_berufsbildner(self.supervisor, self.organisation)
|
create_or_sync_berufsbildner(self.supervisor, self.organisation)
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
|
||||||
if (
|
|
||||||
self.role
|
|
||||||
== OrganisationSupervisortRoleType.AUSBILDUNGSVERANTWORTLICHER.value
|
|
||||||
):
|
|
||||||
from vbv_lernwelt.learning_mentor.services import (
|
|
||||||
delete_ausbildungsverantwortlicher_relation,
|
|
||||||
)
|
|
||||||
|
|
||||||
delete_ausbildungsverantwortlicher_relation(
|
|
||||||
self.supervisor, self.organisation
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
from vbv_lernwelt.learning_mentor.services import (
|
|
||||||
delete_berufsbildner_relation,
|
|
||||||
)
|
|
||||||
|
|
||||||
delete_berufsbildner_relation(self.supervisor, self.organisation)
|
|
||||||
super().delete(*args, **kwargs)
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,13 @@ def users_by_org(
|
||||||
|
|
||||||
|
|
||||||
def uk_cs_users_by_org(org: Organisation) -> set[CourseSessionUser]:
|
def uk_cs_users_by_org(org: Organisation) -> set[CourseSessionUser]:
|
||||||
return users_by_org(org, True, UK_COURSES, excluded_course_sessions=[4, 5, 6])
|
return users_by_org(
|
||||||
|
org,
|
||||||
|
is_uk=True,
|
||||||
|
courses=UK_COURSES,
|
||||||
|
# ignore "Demo" course sessions
|
||||||
|
excluded_course_sessions=[4, 5, 6],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def vv_cs_users_by_org(org: Organisation) -> set[CourseSessionUser]:
|
def vv_cs_users_by_org(org: Organisation) -> set[CourseSessionUser]:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
import structlog
|
||||||
|
from django.db.models.signals import pre_delete
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from vbv_lernwelt.learning_mentor.models import (
|
||||||
|
OrganisationSupervisor,
|
||||||
|
OrganisationSupervisortRoleType,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = structlog.get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# CourseSessionGroup
|
||||||
|
@receiver(
|
||||||
|
pre_delete,
|
||||||
|
sender=OrganisationSupervisor,
|
||||||
|
dispatch_uid="remove_org_supervisor_relations",
|
||||||
|
)
|
||||||
|
def remove_org_supervisor_relations(sender, instance: OrganisationSupervisor, **kwargs):
|
||||||
|
if (
|
||||||
|
instance.role
|
||||||
|
== OrganisationSupervisortRoleType.AUSBILDUNGSVERANTWORTLICHER.value
|
||||||
|
):
|
||||||
|
from vbv_lernwelt.learning_mentor.services import (
|
||||||
|
delete_ausbildungsverantwortlicher_relation,
|
||||||
|
)
|
||||||
|
|
||||||
|
delete_ausbildungsverantwortlicher_relation(
|
||||||
|
instance.supervisor, instance.organisation
|
||||||
|
)
|
||||||
|
elif instance.role == OrganisationSupervisortRoleType.BERUFSBILDNER.value:
|
||||||
|
from vbv_lernwelt.learning_mentor.services import (
|
||||||
|
delete_berufsbildner_relation,
|
||||||
|
)
|
||||||
|
|
||||||
|
delete_berufsbildner_relation(instance.supervisor, instance.organisation)
|
||||||
|
|
@ -32,11 +32,20 @@ class OrganisationSupervisorTestCase(APITestCase):
|
||||||
self.course_session = create_course_session(course=self.course, title="Test VV")
|
self.course_session = create_course_session(course=self.course, title="Test VV")
|
||||||
self.course_config = CourseConfiguration.objects.get(course=self.course)
|
self.course_config = CourseConfiguration.objects.get(course=self.course)
|
||||||
|
|
||||||
self.mobi = Organisation.objects.get_or_create(name_de="Die Mobiliar",
|
self.mobi = Organisation.objects.get_or_create(
|
||||||
defaults={"organisation_id": 100, "name_de": "Die Mobiliar", })[
|
name_de="Die Mobiliar",
|
||||||
0]
|
defaults={
|
||||||
self.baloise = Organisation.objects.get_or_create(name_de="Baloise",
|
"organisation_id": 100,
|
||||||
defaults={"organisation_id": 101, "name_de": "Baloise", })[0]
|
"name_de": "Die Mobiliar",
|
||||||
|
},
|
||||||
|
)[0]
|
||||||
|
self.baloise = Organisation.objects.get_or_create(
|
||||||
|
name_de="Baloise",
|
||||||
|
defaults={
|
||||||
|
"organisation_id": 101,
|
||||||
|
"name_de": "Baloise",
|
||||||
|
},
|
||||||
|
)[0]
|
||||||
|
|
||||||
self.supervisor = create_user("supervisor")
|
self.supervisor = create_user("supervisor")
|
||||||
self.participant_1 = add_course_session_user(
|
self.participant_1 = add_course_session_user(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue