mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-07-05 07:54:08 +02:00
💚 Install libmagic in CI
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
import re
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import Index
|
||||
@ -63,10 +66,10 @@ class Participation(models.Model):
|
||||
verbose_name=_("problem number"),
|
||||
)
|
||||
|
||||
solution = models.ForeignKey(
|
||||
solution = models.OneToOneField(
|
||||
"participation.Video",
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="+",
|
||||
related_name="participation_solution",
|
||||
null=True,
|
||||
default=None,
|
||||
verbose_name=_("solution video"),
|
||||
@ -81,10 +84,10 @@ class Participation(models.Model):
|
||||
verbose_name=_("received participation"),
|
||||
)
|
||||
|
||||
synthesis = models.ForeignKey(
|
||||
synthesis = models.OneToOneField(
|
||||
"participation.Video",
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="+",
|
||||
related_name="participation_synthesis",
|
||||
null=True,
|
||||
default=None,
|
||||
verbose_name=_("synthesis video"),
|
||||
@ -99,12 +102,6 @@ class Participation(models.Model):
|
||||
|
||||
|
||||
class Video(models.Model):
|
||||
participation = models.ForeignKey(
|
||||
"participation.Participation",
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_("participation"),
|
||||
)
|
||||
|
||||
link = models.URLField(
|
||||
verbose_name=_("link"),
|
||||
help_text=_("The full video link."),
|
||||
@ -117,6 +114,24 @@ class Video(models.Model):
|
||||
help_text=_("The video got the validation of the administrators."),
|
||||
)
|
||||
|
||||
@property
|
||||
def participation(self):
|
||||
try:
|
||||
return self.participation_solution
|
||||
except ObjectDoesNotExist:
|
||||
return self.participation_synthesis
|
||||
|
||||
@property
|
||||
def platform(self):
|
||||
if "youtube.com" in self.link or "youtu.be" in self.link:
|
||||
return "youtube"
|
||||
return "unknown"
|
||||
|
||||
@property
|
||||
def youtube_code(self):
|
||||
return re.compile("(https?://|)(www\\.|)(youtube\\.com/watch\\?v=|youtu\\.be/)([a-zA-Z0-9-_]*)?.*?")\
|
||||
.match("https://www.youtube.com/watch?v=73nsrixx7eI").group(4)
|
||||
|
||||
def __str__(self):
|
||||
return _("Video of team {name} ({trigram})")\
|
||||
.format(name=self.participation.team.name, trigram=self.participation.team.trigram)
|
||||
|
Reference in New Issue
Block a user