You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
5.7 KiB
180 lines
5.7 KiB
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from .course import Course
|
|
from apps.account.models import User
|
|
|
|
|
|
class CourseLiveSession(models.Model):
|
|
course = models.ForeignKey(
|
|
Course,
|
|
on_delete=models.CASCADE,
|
|
related_name="live_sessions",
|
|
verbose_name=_("Course"),
|
|
help_text=_("Course that this live session belongs to."),
|
|
)
|
|
room_id = models.CharField(
|
|
max_length=255,
|
|
verbose_name=_("Room ID"),
|
|
help_text=_("Identifier of the PlugNMeet room."),
|
|
unique=True,
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
subject = models.CharField(
|
|
max_length=255,
|
|
verbose_name=_("Subject"),
|
|
help_text=_("Topic of the live session."),
|
|
)
|
|
started_at = models.DateTimeField(
|
|
verbose_name=_("Started At"),
|
|
help_text=_("Start time of the live session."),
|
|
)
|
|
ended_at = models.DateTimeField(
|
|
verbose_name=_("Ended At"),
|
|
help_text=_("End time of the live session."),
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created At"))
|
|
updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated At"))
|
|
|
|
def __str__(self):
|
|
return f"{self.course} - {self.subject}"
|
|
|
|
class Meta:
|
|
ordering = ("-started_at", "-id")
|
|
verbose_name = _("Course Live Session")
|
|
verbose_name_plural = _("Course Live Sessions")
|
|
indexes = [
|
|
models.Index(fields=["course", "started_at"]),
|
|
models.Index(fields=["course", "created_at"]),
|
|
models.Index(fields=["room_id"]),
|
|
]
|
|
|
|
|
|
USER_ROLE_CHOICES = (
|
|
("participant", "Participant"),
|
|
("moderator", "Moderator"),
|
|
("observer", "Observer"),
|
|
)
|
|
|
|
|
|
class LiveSessionUser(models.Model):
|
|
session = models.ForeignKey(
|
|
CourseLiveSession,
|
|
on_delete=models.CASCADE,
|
|
related_name="user_sessions",
|
|
verbose_name=_("Live Session"),
|
|
help_text=_("Live session that the user joined."),
|
|
)
|
|
user = models.ForeignKey(
|
|
User,
|
|
on_delete=models.CASCADE,
|
|
related_name="live_session_entries",
|
|
verbose_name=_("User"),
|
|
help_text=_("User participating in the live session."),
|
|
)
|
|
role = models.CharField(
|
|
max_length=50,
|
|
choices=USER_ROLE_CHOICES,
|
|
verbose_name=_("Role"),
|
|
help_text=_("Role of the user in the session"),
|
|
)
|
|
entered_at = models.DateTimeField(
|
|
verbose_name=_("Entered At"),
|
|
help_text=_("Time the user entered the session"),
|
|
)
|
|
exited_at = models.DateTimeField(
|
|
verbose_name=_("Exited At"),
|
|
help_text=_("Time the user exited the session"),
|
|
null=True,
|
|
blank=True,
|
|
default=None,
|
|
)
|
|
is_online = models.BooleanField(
|
|
default=True,
|
|
verbose_name=_("Is online"),
|
|
help_text=_("Is the user currently online?"),
|
|
)
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created At"))
|
|
updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated At"))
|
|
|
|
def __str__(self):
|
|
return f"{self.user} @ {self.session}"
|
|
|
|
class Meta:
|
|
verbose_name = _("User Session")
|
|
verbose_name_plural = _("User Sessions")
|
|
ordering = ("-entered_at", "-id")
|
|
indexes = [
|
|
models.Index(fields=["session", "user"]),
|
|
models.Index(fields=["session", "is_online"]),
|
|
models.Index(fields=["user", "is_online"]),
|
|
]
|
|
unique_together = ("session", "user", "entered_at")
|
|
|
|
|
|
RECORDING_TYPE_CHOICES = (
|
|
("voice", "Voice"),
|
|
("video", "Video"),
|
|
)
|
|
|
|
|
|
class LiveSessionRecording(models.Model):
|
|
session = models.ForeignKey(
|
|
CourseLiveSession,
|
|
on_delete=models.CASCADE,
|
|
related_name="recordings",
|
|
verbose_name=_("Live Session"),
|
|
help_text=_("Live session that this recording belongs to."),
|
|
)
|
|
title = models.CharField(
|
|
max_length=255,
|
|
verbose_name=_("Title"),
|
|
help_text=_("Title of the recording"),
|
|
)
|
|
file = models.FileField(
|
|
upload_to="recorded_sessions/",
|
|
verbose_name=_("Recording File"),
|
|
help_text=_("File of the recorded session"),
|
|
)
|
|
file_time = models.DurationField(
|
|
verbose_name=_("File Duration"),
|
|
help_text=_("Duration of the recording file"),
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
recording_type = models.CharField(
|
|
max_length=10,
|
|
choices=RECORDING_TYPE_CHOICES,
|
|
verbose_name=_("Recording Type"),
|
|
help_text=_("Type of the recording (voice or video)"),
|
|
)
|
|
thumbnail = models.ImageField(
|
|
upload_to="recording_thumbnails/",
|
|
verbose_name=_("Thumbnail"),
|
|
help_text=_("Thumbnail image for video recordings"),
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created At"), help_text=_("Time the recording was created"))
|
|
updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated At"), help_text=_("The datetime when the recording was last updated"))
|
|
is_active = models.BooleanField(
|
|
default=True,
|
|
verbose_name=_("Is Active"),
|
|
help_text=_("Whether this recording is active or not"),
|
|
)
|
|
|
|
def __str__(self):
|
|
meet_id = getattr(self.session, "meet_id", self.session_id)
|
|
return f"meet:<{meet_id}><{self.id}>{self.title} - {self.recording_type}"
|
|
|
|
class Meta:
|
|
verbose_name = _("Live Session Recording")
|
|
verbose_name_plural = _("Live Session Recordings")
|
|
ordering = ("-created_at", "-id")
|
|
indexes = [
|
|
models.Index(fields=["session", "is_active"]),
|
|
models.Index(fields=["session", "recording_type"]),
|
|
]
|