68 lines
2.1 KiB
Python
68 lines
2.1 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 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"]]
|