Upgrade to Django 3.2
This commit is contained in:
parent
c1f710c9ac
commit
409d2e3115
23 changed files with 1469 additions and 151 deletions
|
@ -28,7 +28,6 @@ from judge.models.problem import (
|
|||
ProblemTranslation,
|
||||
ProblemType,
|
||||
Solution,
|
||||
TranslatedProblemForeignKeyQuerySet,
|
||||
TranslatedProblemQuerySet,
|
||||
ProblemPointsVote,
|
||||
)
|
||||
|
|
|
@ -6,8 +6,7 @@ from django.contrib.contenttypes.fields import GenericRelation
|
|||
from django.core.cache import cache
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import CASCADE, F, Q, QuerySet, SET_NULL
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.db.models import CASCADE, F, FilteredRelation, Q, SET_NULL
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.urls import reverse
|
||||
from django.utils.functional import cached_property
|
||||
|
@ -17,7 +16,6 @@ from judge.fulltext import SearchQuerySet
|
|||
from judge.models.profile import Organization, Profile
|
||||
from judge.models.runtime import Language
|
||||
from judge.user_translations import gettext as user_gettext
|
||||
from judge.utils.raw_sql import RawSQLColumn, unique_together_left_join
|
||||
from judge.models.problem_data import (
|
||||
problem_data_storage,
|
||||
problem_directory_file_helper,
|
||||
|
@ -31,7 +29,6 @@ __all__ = [
|
|||
"License",
|
||||
"Solution",
|
||||
"TranslatedProblemQuerySet",
|
||||
"TranslatedProblemForeignKeyQuerySet",
|
||||
]
|
||||
|
||||
|
||||
|
@ -112,43 +109,18 @@ class TranslatedProblemQuerySet(SearchQuerySet):
|
|||
)
|
||||
|
||||
def add_i18n_name(self, language):
|
||||
queryset = self._clone()
|
||||
alias = unique_together_left_join(
|
||||
queryset, ProblemTranslation, "problem", "language", language
|
||||
)
|
||||
return queryset.annotate(
|
||||
return self.annotate(
|
||||
i18n_translation=FilteredRelation(
|
||||
"translations",
|
||||
condition=Q(translations__language=language),
|
||||
)
|
||||
).annotate(
|
||||
i18n_name=Coalesce(
|
||||
RawSQL("%s.name" % alias, ()),
|
||||
F("name"),
|
||||
output_field=models.CharField(),
|
||||
F("i18n_translation__name"), F("name"), output_field=models.CharField()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TranslatedProblemForeignKeyQuerySet(QuerySet):
|
||||
def add_problem_i18n_name(self, key, language, name_field=None):
|
||||
queryset = (
|
||||
self._clone() if name_field is None else self.annotate(_name=F(name_field))
|
||||
)
|
||||
alias = unique_together_left_join(
|
||||
queryset,
|
||||
ProblemTranslation,
|
||||
"problem",
|
||||
"language",
|
||||
language,
|
||||
parent_model=Problem,
|
||||
)
|
||||
# You must specify name_field if Problem is not yet joined into the QuerySet.
|
||||
kwargs = {
|
||||
key: Coalesce(
|
||||
RawSQL("%s.name" % alias, ()),
|
||||
F(name_field) if name_field else RawSQLColumn(Problem, "name"),
|
||||
output_field=models.CharField(),
|
||||
)
|
||||
}
|
||||
return queryset.annotate(**kwargs)
|
||||
|
||||
|
||||
class Problem(models.Model):
|
||||
code = models.CharField(
|
||||
max_length=20,
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.utils.functional import cached_property
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from judge.judgeapi import abort_submission, judge_submission
|
||||
from judge.models.problem import Problem, TranslatedProblemForeignKeyQuerySet
|
||||
from judge.models.problem import Problem
|
||||
from judge.models.profile import Profile
|
||||
from judge.models.runtime import Language
|
||||
from judge.utils.unicode import utf8bytes
|
||||
|
@ -120,8 +120,6 @@ class Submission(models.Model):
|
|||
related_name="+",
|
||||
)
|
||||
|
||||
objects = TranslatedProblemForeignKeyQuerySet.as_manager()
|
||||
|
||||
@classmethod
|
||||
def result_class_from_code(cls, result, case_points, case_total):
|
||||
if result == "AC":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue