104 lines
3.4 KiB
Python
104 lines
3.4 KiB
Python
import uuid
|
|
from enum import Enum
|
|
|
|
from django.db import models
|
|
from django_extensions.db.models import TimeStampedModel
|
|
|
|
from vbv_lernwelt.core.models import Organisation, User
|
|
from vbv_lernwelt.course.models import CourseSessionUser
|
|
|
|
|
|
class LearningMentor(models.Model):
|
|
mentor = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
course_session = models.ForeignKey("course.CourseSession", on_delete=models.CASCADE)
|
|
|
|
participants = models.ManyToManyField(
|
|
CourseSessionUser,
|
|
related_name="participants",
|
|
blank=True,
|
|
)
|
|
|
|
class Meta:
|
|
unique_together = [["mentor", "course_session"]]
|
|
verbose_name = "Lernbegleiter"
|
|
verbose_name_plural = "Lernbegleiter"
|
|
|
|
def __str__(self):
|
|
return f"{self.mentor} ({self.course_session.title})"
|
|
|
|
@property
|
|
def course_sessions(self):
|
|
return self.participants.values_list("course_session", flat=True).distinct()
|
|
|
|
|
|
class AgentParticipantRoleType(Enum):
|
|
LEARNING_MENTOR = "LEARNING_MENTOR" # Lernbegleiter
|
|
BERUFSBILDNER = "BERUFSBILDNER" # Lernbegleiter
|
|
|
|
|
|
class AgentParticipantRelation(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
agent = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
participant = models.ForeignKey(CourseSessionUser, on_delete=models.CASCADE)
|
|
|
|
role = models.CharField(
|
|
max_length=255,
|
|
choices=[(t.value, t.value) for t in AgentParticipantRoleType],
|
|
default=AgentParticipantRoleType.LEARNING_MENTOR.value,
|
|
)
|
|
|
|
class Meta:
|
|
unique_together = [("agent", "participant")]
|
|
|
|
|
|
class MentorInvitation(TimeStampedModel):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
email = models.EmailField()
|
|
participant = models.ForeignKey(CourseSessionUser, on_delete=models.CASCADE)
|
|
target_url = models.CharField(max_length=255, blank=True, default="")
|
|
|
|
def __str__(self):
|
|
return f"{self.email} ({self.participant})"
|
|
|
|
class Meta:
|
|
verbose_name = "Lernbegleiter Einladung"
|
|
verbose_name_plural = "Lernbegleiter Einladungen"
|
|
unique_together = [["email", "participant"]]
|
|
|
|
|
|
class OrganisationSupervisortRoleType(Enum):
|
|
AUSBILDUNGSVERANTWORTLICHER = "AUSBILDUNGSVERANTWORTLICHER"
|
|
BERUFSBILDNER = "BERUFSBILDNER"
|
|
|
|
|
|
class OrganisationSupervisor(models.Model):
|
|
supervisor = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE)
|
|
|
|
role = models.CharField(
|
|
max_length=255,
|
|
choices=[(t.value, t.value) for t in OrganisationSupervisortRoleType],
|
|
default=OrganisationSupervisortRoleType.AUSBILDUNGSVERANTWORTLICHER.value,
|
|
)
|
|
|
|
def save(self, *args, **kwargs):
|
|
if (
|
|
self.role
|
|
== OrganisationSupervisortRoleType.AUSBILDUNGSVERANTWORTLICHER.value
|
|
):
|
|
from vbv_lernwelt.learning_mentor.services import (
|
|
create_or_sync_ausbildungsverantwortlicher,
|
|
)
|
|
|
|
create_or_sync_ausbildungsverantwortlicher(
|
|
self.supervisor, self.organisation
|
|
)
|
|
elif self.role == OrganisationSupervisortRoleType.BERUFSBILDNER.value:
|
|
from vbv_lernwelt.learning_mentor.services import (
|
|
create_or_sync_berufsbildner,
|
|
)
|
|
|
|
create_or_sync_berufsbildner(self.supervisor, self.organisation)
|
|
super().save(*args, **kwargs)
|