From 1677dd19645b00e52961c7cb95adbfa4fee322ab Mon Sep 17 00:00:00 2001 From: kovacspe Date: Sun, 19 May 2024 13:29:23 +0200 Subject: [PATCH] solution upload files --- competition/models.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/competition/models.py b/competition/models.py index 0a99732..ab49af6 100644 --- a/competition/models.py +++ b/competition/models.py @@ -1,5 +1,5 @@ import datetime -from typing import Optional +from typing import Iterable, Optional from django.conf import settings from django.contrib.sites.models import Site @@ -619,6 +619,14 @@ class Vote(models.IntegerChoices): POSITIVE = 1, 'pozitívny' +def get_solution_path(instance, filename): + return instance.get_solution_path() + + +def get_corrected_solution_path(instance, filename): + return instance.get_corrected_solution_path() + + class Solution(models.Model): """ Popisuje riešenie úlohy od užívateľa. Obsahuje nahraté aj opravné riešenie, body @@ -634,11 +642,11 @@ class Meta: solution = RestrictedFileField( content_types=['application/pdf'], storage=private_storage, - verbose_name='účastnícke riešenie', blank=True, upload_to='solutions/user_solutions') + verbose_name='účastnícke riešenie', blank=True, upload_to=get_solution_path) corrected_solution = RestrictedFileField( content_types=['application/pdf'], storage=private_storage, - verbose_name='opravené riešenie', blank=True, upload_to='solutions/corrected/') + verbose_name='opravené riešenie', blank=True, upload_to=get_corrected_solution_path) score = models.PositiveSmallIntegerField( verbose_name='body', null=True, blank=True) @@ -664,10 +672,16 @@ def get_solution_file_name(self): return f'{self.semester_registration.profile.user.get_full_name_camel_case()}'\ f'-{self.problem.id}-{self.semester_registration.id}.pdf' + def get_solution_file_path(self): + return f'solutions/user_solutions/{self.get_solution_file_path()}' + def get_corrected_solution_file_name(self): - return f'corrected/{self.semester_registration.profile.user.get_full_name_camel_case()}'\ + return f'{self.semester_registration.profile.user.get_full_name_camel_case()}'\ f'-{self.problem.id}-{self.semester_registration.id}_corrected.pdf' + def get_corrected_solution_file_path(self): + return f'solutions/corrected/{self.get_corrected_solution_file_path()}' + def can_user_modify(self, user): return self.problem.can_user_modify(user)