update
This commit is contained in:
@@ -170,6 +170,11 @@ class ProblemSerializer(BaseProblemSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class ProblemListSerializer(BaseProblemSerializer):
|
class ProblemListSerializer(BaseProblemSerializer):
|
||||||
|
has_ast_rules = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
def get_has_ast_rules(self, obj):
|
||||||
|
return bool(obj.ast_rules)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Problem
|
model = Problem
|
||||||
fields = [
|
fields = [
|
||||||
@@ -184,6 +189,7 @@ class ProblemListSerializer(BaseProblemSerializer):
|
|||||||
"contest",
|
"contest",
|
||||||
"allow_flowchart",
|
"allow_flowchart",
|
||||||
"show_flowchart",
|
"show_flowchart",
|
||||||
|
"has_ast_rules",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import random
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.db.models import Count, Q
|
from django.db.models import BooleanField, Case, Count, Q, Value, When
|
||||||
from django.db.models.functions import ExtractYear
|
from django.db.models.functions import ExtractYear
|
||||||
|
|
||||||
from account.decorators import check_contest_permission
|
from account.decorators import check_contest_permission
|
||||||
@@ -128,10 +128,18 @@ class ProblemAPI(APIView):
|
|||||||
|
|
||||||
# 排序
|
# 排序
|
||||||
sort = request.GET.get("sort")
|
sort = request.GET.get("sort")
|
||||||
if sort and sort != "flowchart":
|
if sort == "flowchart":
|
||||||
problems = problems.order_by(sort)
|
|
||||||
if sort and sort == "flowchart":
|
|
||||||
problems = problems.order_by("-allow_flowchart", "-show_flowchart", "-create_time")
|
problems = problems.order_by("-allow_flowchart", "-show_flowchart", "-create_time")
|
||||||
|
elif sort == "ast":
|
||||||
|
problems = problems.annotate(
|
||||||
|
_has_ast=Case(
|
||||||
|
When(ast_rules__isnull=False, then=Value(True)),
|
||||||
|
default=Value(False),
|
||||||
|
output_field=BooleanField(),
|
||||||
|
)
|
||||||
|
).order_by("-_has_ast", "-create_time")
|
||||||
|
elif sort:
|
||||||
|
problems = problems.order_by(sort)
|
||||||
|
|
||||||
# 根据profile 为做过的题目添加标记
|
# 根据profile 为做过的题目添加标记
|
||||||
data = self.paginate_data(request, problems, ProblemListSerializer)
|
data = self.paginate_data(request, problems, ProblemListSerializer)
|
||||||
|
|||||||
Reference in New Issue
Block a user