diff --git a/apps/participation/models.py b/apps/participation/models.py index f5b92b2..78db948 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -312,6 +312,15 @@ class Pool(models.Model): verbose_name_plural = _("pools") +def get_solution_filename(instance, filename): + return f"solutions/{instance.participation.team.trigram}_{instance.problem}" \ + + ("final" if instance.final_solution else "") + + +def get_random_synthesis_filename(instance, filename): + return "syntheses/" + get_random_string(64) + + class Solution(models.Model): participation = models.ForeignKey( Participation, @@ -331,14 +340,15 @@ class Solution(models.Model): file = models.FileField( verbose_name=_("file"), - upload_to="solutions/", + upload_to=get_solution_filename, unique=True, blank=True, default="", ) def __str__(self): - return repr(self) + return _("Solution of team {team} for problem {problem}")\ + .format(team=self.participation.team.name, problem=self.problem) class Meta: verbose_name = _("solution") @@ -369,7 +379,7 @@ class Synthesis(models.Model): file = models.FileField( verbose_name=_("file"), - upload_to="syntheses/", + upload_to=get_random_synthesis_filename, unique=True, blank=True, default="", diff --git a/apps/participation/templates/participation/participation_detail.html b/apps/participation/templates/participation/participation_detail.html index eafd4a5..4aae765 100644 --- a/apps/participation/templates/participation/participation_detail.html +++ b/apps/participation/templates/participation/participation_detail.html @@ -19,9 +19,7 @@