checkpoint

This commit is contained in:
Egor Matveev
2021-09-05 15:28:24 +03:00
parent 1307c16ec1
commit 807c52bf2b
30 changed files with 394 additions and 26 deletions

View File

@@ -1,27 +1,50 @@
from os import remove
from os.path import join, exists
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from Sprint.settings import DATA_ROOT
class ExtraFile(models.Model):
task = models.ForeignKey('Task', on_delete=models.CASCADE)
task = models.ForeignKey("Task", on_delete=models.CASCADE)
filename = models.TextField()
is_test = models.BooleanField(null=True)
is_sample = models.BooleanField(null=True)
readable = models.BooleanField(null=True)
test_number = models.IntegerField(null=True)
@property
def path(self):
return join(DATA_ROOT, 'extra_files', str(self.id))
return join(DATA_ROOT, "extra_files", str(self.id))
@property
def can_be_sample(self):
return (
self.is_test
and not self.filename.endswith(".a")
and len(
ExtraFile.objects.filter(task=self.task, filename=self.filename + ".a")
)
)
@property
def text(self):
return open(self.path, 'r').read()
return open(self.path, "r").read()
def delete(self, using=None, keep_parents=False):
if exists(self.path):
remove(self.path)
if self.is_test and self.filename.endswith('.a'):
try:
ef = ExtraFile.objects.get(task=self.task, filename=self.filename.rstrip('.a'), is_test=True)
ef.is_sample = False
ef.save()
except ObjectDoesNotExist:
pass
super().delete(using=using, keep_parents=keep_parents)
@property
def answer(self):
return ExtraFile.objects.get(task=self.task, is_test=True, filename=self.filename + '.a')