checker works

This commit is contained in:
Egor Matveev
2022-05-05 15:47:16 +03:00
parent 7028ac37b6
commit 5518c34636
25 changed files with 295 additions and 455 deletions

View File

@@ -5,10 +5,18 @@ from SprintLib.utils import get_bytes, write_bytes, delete_file
class FileStorageMixin:
@cached_property
_bytes = None
@property
def bytes(self):
if self._bytes is not None:
return self._bytes
return get_bytes(self.fs_id)
@bytes.setter
def bytes(self, value):
self._bytes = value
@cached_property
def text(self):
try:

View File

@@ -22,6 +22,8 @@ class Solution(models.Model):
set = models.ForeignKey(Set, null=True, blank=True, on_delete=models.SET_NULL)
extras = models.JSONField(default=dict)
_solutionfiles = None
class Meta:
indexes = [
models.Index(fields=['task', 'user', '-time_sent']),
@@ -29,6 +31,16 @@ class Solution(models.Model):
models.Index(fields=['set', '-time_sent']),
]
@property
def solutionfiles(self):
if self._solutionfiles is not None:
return self._solutionfiles
return SolutionFile.objects.filter(solution=self)
@solutionfiles.setter
def solutionfiles(self, value):
self._solutionfiles = value
@cached_property
def settask(self):
return SetTask.objects.filter(set=self.set, task=self.task).first()
@@ -83,10 +95,6 @@ class Solution(models.Model):
return "info"
return "danger"
@property
def volume_directory(self):
return "/sprint-data/worker/" + str(self.id)
def exec_command(self, command, working_directory="app", timeout=None):
return call(
f'docker exec -i solution_{self.id} sh -c "cd {working_directory} && {command}"',

View File

@@ -1,8 +1,8 @@
from cached_property import cached_property
from django.contrib.postgres.fields import ArrayField
from django.db import models
from django.contrib.auth.models import User
from django.db.models import JSONField
from django.utils import timezone
from Main.models.dump import Dump
from Main.models.extrafile import ExtraFile
@@ -22,6 +22,8 @@ class Task(models.Model):
allow_sharing = models.BooleanField(default=False)
changes = JSONField(default=list)
_extrafiles = None
def __str__(self):
return self.name
@@ -35,7 +37,32 @@ class Task(models.Model):
@property
def tests(self):
return ExtraFile.objects.filter(task=self, is_test=True).order_by('filename')
for file in sorted(self.extrafiles, key=lambda x: x.filename):
if file.filename.isnumeric() or file.filename.endswith('.a') and file.filename[:-2].isnumeric():
yield file
@property
def extrafiles(self):
if self._extrafiles is not None:
return self._extrafiles
return ExtraFile.objects.filter(task=self)
@extrafiles.setter
def extrafiles(self, value):
self._extrafiles = value
@property
def dockerfiles(self):
for file in self.extrafiles:
if file.filename.startswith('Dockerfile_'):
yield file
@cached_property
def checkerfile(self):
for file in self.extrafiles:
if file.filename == 'extrafile.py':
return file
return None
@property
def tests_count(self):
@@ -44,7 +71,7 @@ class Task(models.Model):
@property
def samples(self):
data = []
for test in self.tests.order_by("test_number"):
for test in self.tests:
if test.is_sample and test.readable:
data.append({"input": test.text, "output": test.answer.text})
count = 1

View File

@@ -20,7 +20,7 @@ class SendCodeView(BaseView):
"message": "Пользователя с таким именем не существует",
}
code = randrange(10000, 100000)
print(code)
print(f"Отправлен код для {username}", code)
user.userinfo.code = code
user.userinfo.save()
notify(user, "any", "Код для входа в сервис: " + str(code))