mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 03:57:09 +00:00
refactor
This commit is contained in:
@@ -7,4 +7,4 @@ class CompetitionsConfig(AppConfig):
|
||||
verbose_name = "Соревнование"
|
||||
|
||||
def ready(self):
|
||||
import apps.competition.signals
|
||||
pass
|
||||
|
||||
@@ -3,15 +3,23 @@ from django.dispatch import receiver
|
||||
|
||||
from apps.achievement.models import Achievement, UserAchievement
|
||||
from apps.competition.models import State
|
||||
from apps.user.models import User
|
||||
|
||||
|
||||
@receiver(post_save, sender=State)
|
||||
def assign_start_competition_achievement(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
if State.objects.filter(user=instance.user, state=State.StateChoices.STARTED.value).count() == 1 \
|
||||
and not State.objects.filter(user=instance.user, state=State.StateChoices.FINISHED.value).exists():
|
||||
start_competition_achievement = Achievement.objects.get(slug="start_competition")
|
||||
if (
|
||||
State.objects.filter(
|
||||
user=instance.user, state=State.StateChoices.STARTED.value
|
||||
).count()
|
||||
== 1
|
||||
and not State.objects.filter(
|
||||
user=instance.user, state=State.StateChoices.FINISHED.value
|
||||
).exists()
|
||||
):
|
||||
start_competition_achievement = Achievement.objects.get(
|
||||
slug="start_competition"
|
||||
)
|
||||
UserAchievement.objects.create(
|
||||
user=instance.user, achievement=start_competition_achievement
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ from apps.user.models import User, UserRole
|
||||
|
||||
faker = Faker("ru_RU")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Generate sample data for Users, Competitions, Tasks, Submissions, and States."
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import random
|
||||
import uuid
|
||||
from datetime import timedelta, datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from PIL.Image import Image
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from django.core.files.base import ContentFile, File
|
||||
@@ -13,9 +12,9 @@ from apps.competition.models import Competition, State
|
||||
from apps.review.models import Reviewer
|
||||
from apps.task.models import (
|
||||
CompetitionTask,
|
||||
CompetitionTaskAttachment,
|
||||
CompetitionTaskCriteria,
|
||||
CompetitionTaskSubmission,
|
||||
CompetitionTaskAttachment,
|
||||
)
|
||||
from apps.user.models import User, UserRole
|
||||
|
||||
@@ -47,11 +46,11 @@ dataset2 = ContentFile(
|
||||
|
||||
correct_answer_file = ContentFile(
|
||||
b"42",
|
||||
name=f"answer.txt",
|
||||
name="answer.txt",
|
||||
)
|
||||
correct2_answer_file = ContentFile(
|
||||
b"it is a dataset",
|
||||
name=f"answer.txt",
|
||||
name="answer.txt",
|
||||
)
|
||||
|
||||
now = timezone.now()
|
||||
@@ -666,7 +665,7 @@ class Command(BaseCommand):
|
||||
type=competition["type"],
|
||||
participation_type=competition["participation_type"],
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
print(competition)
|
||||
|
||||
if competition.get("image"):
|
||||
@@ -697,13 +696,18 @@ class Command(BaseCommand):
|
||||
points=task["points"],
|
||||
submission_reviewers_count=task[
|
||||
"submission_reviewers_count"
|
||||
] if task["type"] == CompetitionTask.CompetitionTaskType.REVIEW.value else None,
|
||||
correct_answer_file=task["correct_answer_file"] if task["type"] != CompetitionTask.CompetitionTaskType.REVIEW.value else None,
|
||||
]
|
||||
if task["type"]
|
||||
== CompetitionTask.CompetitionTaskType.REVIEW.value
|
||||
else None,
|
||||
correct_answer_file=task["correct_answer_file"]
|
||||
if task["type"]
|
||||
!= CompetitionTask.CompetitionTaskType.REVIEW.value
|
||||
else None,
|
||||
max_attempts=task.get("max_attempts"),
|
||||
)
|
||||
competitions[i]["tasks"][j]["obj"] = task_obj
|
||||
|
||||
|
||||
if task.get("attachment"):
|
||||
CompetitionTaskAttachment.objects.create(
|
||||
task=task_obj,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from sys import stdout
|
||||
from uuid import uuid4
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import Count, Q
|
||||
from django.core.validators import RegexValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
from mdeditor.fields import MDTextField
|
||||
|
||||
from apps.competition.models import Competition
|
||||
@@ -88,23 +87,27 @@ class CompetitionTask(BaseModel):
|
||||
# "type": "Если загружен файл правильного ответа, то тип проверки не может быть ручным"
|
||||
# })
|
||||
if not self.correct_answer_file and self.type != "review":
|
||||
raise ValidationError({
|
||||
"correct_answer_file": "Загрузите правильный ответ"
|
||||
})
|
||||
raise ValidationError(
|
||||
{"correct_answer_file": "Загрузите правильный ответ"}
|
||||
)
|
||||
|
||||
# if self.answer_file_path and not self.type == "checker":
|
||||
# raise ValidationError({
|
||||
# "type": "Укажите другой тип задания: этот не совместим с путем правильного ответа"
|
||||
# })
|
||||
if not self.answer_file_path and self.type == "checker":
|
||||
raise ValidationError({
|
||||
"answer_file_path": "Введите путь правильного ответа - это нужно для корректной работы чекера"
|
||||
})
|
||||
raise ValidationError(
|
||||
{
|
||||
"answer_file_path": "Введите путь правильного ответа - это нужно для корректной работы чекера"
|
||||
}
|
||||
)
|
||||
|
||||
if not self.reviewers and self.type == "review":
|
||||
raise ValidationError({
|
||||
"reviewers": "Загрузите ревьюверов - кто будет проверять задания, если не они?"
|
||||
})
|
||||
raise ValidationError(
|
||||
{
|
||||
"reviewers": "Загрузите ревьюверов - кто будет проверять задания, если не они?"
|
||||
}
|
||||
)
|
||||
# elif self.reviewers and not self.type == "review":
|
||||
# raise ValidationError({
|
||||
# "type": "Проверьте тип - вы ввели ревьюверов, но задание не является ручным"
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import base64
|
||||
import hashlib
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import httpx
|
||||
from celery import shared_task
|
||||
from django.conf import settings
|
||||
from django.core.files.base import ContentFile
|
||||
from urllib.parse import urlparse
|
||||
import base64
|
||||
|
||||
from apps.task.models import CompetitionTaskSubmission
|
||||
|
||||
|
||||
@@ -7,4 +7,4 @@ class UsersConfig(AppConfig):
|
||||
verbose_name = "контестанты"
|
||||
|
||||
def ready(self):
|
||||
import apps.user.signals
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user