mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-27 23:51:47 +00:00
去除不必要的serializer
This commit is contained in:
parent
e6834fa6f7
commit
ee89df9ff2
2
.gitignore
vendored
2
.gitignore
vendored
@ -53,6 +53,7 @@ db.db
|
||||
*.rdb
|
||||
#*.out
|
||||
*.sqlite3
|
||||
.python-version
|
||||
.DS_Store
|
||||
build.txt
|
||||
tmp/
|
||||
@ -69,3 +70,4 @@ data/public/upload/*
|
||||
!data/public/upload/.gitkeep
|
||||
data/public/avatar/*
|
||||
!data/public/avatar/default.png
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
3.6.2
|
@ -1,6 +1,6 @@
|
||||
from django import forms
|
||||
|
||||
from utils.api import DateTimeTZField, serializers, UsernameSerializer
|
||||
from utils.api import serializers, UsernameSerializer
|
||||
|
||||
from .models import AdminType, ProblemPermission, User, UserProfile
|
||||
|
||||
@ -50,8 +50,6 @@ class ImportUserSeralizer(serializers.Serializer):
|
||||
|
||||
class UserAdminSerializer(serializers.ModelSerializer):
|
||||
real_name = serializers.SerializerMethodField()
|
||||
create_time = DateTimeTZField()
|
||||
last_login = DateTimeTZField()
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
@ -63,9 +61,6 @@ class UserAdminSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
create_time = DateTimeTZField()
|
||||
last_login = DateTimeTZField()
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["id", "username", "email", "admin_type", "problem_permission",
|
||||
@ -74,22 +69,12 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
|
||||
class UserProfileSerializer(serializers.ModelSerializer):
|
||||
user = UserSerializer()
|
||||
acm_problems_status = serializers.JSONField()
|
||||
oi_problems_status = serializers.JSONField()
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class UserInfoSerializer(serializers.ModelSerializer):
|
||||
acm_problems_status = serializers.JSONField()
|
||||
oi_problems_status = serializers.JSONField()
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
|
||||
|
||||
class EditUserSerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField()
|
||||
username = serializers.CharField(max_length=32)
|
||||
@ -105,12 +90,12 @@ class EditUserSerializer(serializers.Serializer):
|
||||
|
||||
class EditUserProfileSerializer(serializers.Serializer):
|
||||
real_name = serializers.CharField(max_length=32, allow_null=True, required=False)
|
||||
avatar = serializers.CharField(max_length=256, allow_null=True, allow_blank=True, required=False)
|
||||
blog = serializers.URLField(max_length=256, allow_null=True, allow_blank=True, required=False)
|
||||
mood = serializers.CharField(max_length=256, allow_null=True, allow_blank=True, required=False)
|
||||
github = serializers.CharField(max_length=64, allow_null=True, allow_blank=True, required=False)
|
||||
school = serializers.CharField(max_length=64, allow_null=True, allow_blank=True, required=False)
|
||||
major = serializers.CharField(max_length=64, allow_null=True, allow_blank=True, required=False)
|
||||
avatar = serializers.CharField(max_length=256, allow_blank=True, required=False)
|
||||
blog = serializers.URLField(max_length=256, allow_blank=True, required=False)
|
||||
mood = serializers.CharField(max_length=256, allow_blank=True, required=False)
|
||||
github = serializers.CharField(max_length=64, allow_blank=True, required=False)
|
||||
school = serializers.CharField(max_length=64, allow_blank=True, required=False)
|
||||
major = serializers.CharField(max_length=64, allow_blank=True, required=False)
|
||||
|
||||
|
||||
class ApplyResetPasswordSerializer(serializers.Serializer):
|
||||
@ -142,3 +127,4 @@ class RankInfoSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
fields = "__all__"
|
||||
|
@ -1,5 +1,5 @@
|
||||
from utils.api import serializers
|
||||
from utils.api._serializers import DateTimeTZField, UsernameSerializer
|
||||
from utils.api._serializers import UsernameSerializer
|
||||
|
||||
from .models import Announcement
|
||||
|
||||
@ -11,12 +11,11 @@ class CreateAnnouncementSerializer(serializers.Serializer):
|
||||
|
||||
|
||||
class AnnouncementSerializer(serializers.ModelSerializer):
|
||||
create_time = DateTimeTZField()
|
||||
last_update_time = DateTimeTZField()
|
||||
created_by = UsernameSerializer()
|
||||
|
||||
class Meta:
|
||||
model = Announcement
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class EditAnnouncementSerializer(serializers.Serializer):
|
||||
|
@ -1,4 +1,4 @@
|
||||
from utils.api import DateTimeTZField, serializers
|
||||
from utils.api import serializers
|
||||
|
||||
from .models import JudgeServer
|
||||
|
||||
@ -29,8 +29,6 @@ class CreateEditWebsiteConfigSerializer(serializers.Serializer):
|
||||
|
||||
|
||||
class JudgeServerSerializer(serializers.ModelSerializer):
|
||||
create_time = DateTimeTZField()
|
||||
last_heartbeat = DateTimeTZField()
|
||||
status = serializers.CharField()
|
||||
|
||||
class Meta:
|
||||
|
@ -1,4 +1,4 @@
|
||||
from utils.api import DateTimeTZField, UsernameSerializer, serializers
|
||||
from utils.api import UsernameSerializer, serializers
|
||||
|
||||
from .models import Contest, ContestAnnouncement, ContestRuleType
|
||||
from .models import ACMContestRank, OIContestRank
|
||||
@ -29,16 +29,13 @@ class EditConetestSeriaizer(serializers.Serializer):
|
||||
|
||||
|
||||
class ContestAdminSerializer(serializers.ModelSerializer):
|
||||
start_time = DateTimeTZField()
|
||||
end_time = DateTimeTZField()
|
||||
create_time = DateTimeTZField()
|
||||
last_update_time = DateTimeTZField()
|
||||
created_by = UsernameSerializer()
|
||||
status = serializers.CharField()
|
||||
contest_type = serializers.CharField()
|
||||
|
||||
class Meta:
|
||||
model = Contest
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class ContestSerializer(ContestAdminSerializer):
|
||||
@ -49,10 +46,10 @@ class ContestSerializer(ContestAdminSerializer):
|
||||
|
||||
class ContestAnnouncementSerializer(serializers.ModelSerializer):
|
||||
created_by = UsernameSerializer()
|
||||
create_time = DateTimeTZField()
|
||||
|
||||
class Meta:
|
||||
model = ContestAnnouncement
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class CreateContestAnnouncementSerializer(serializers.Serializer):
|
||||
@ -76,10 +73,10 @@ class ContestPasswordVerifySerializer(serializers.Serializer):
|
||||
|
||||
class ACMContestRankSerializer(serializers.ModelSerializer):
|
||||
user = serializers.SerializerMethodField()
|
||||
submission_info = serializers.JSONField()
|
||||
|
||||
class Meta:
|
||||
model = ACMContestRank
|
||||
fields = "__all__"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.is_admin_role = kwargs.pop("is_admin_role", False)
|
||||
@ -91,10 +88,10 @@ class ACMContestRankSerializer(serializers.ModelSerializer):
|
||||
|
||||
class OIContestRankSerializer(serializers.ModelSerializer):
|
||||
user = serializers.SerializerMethodField()
|
||||
submission_info = serializers.JSONField()
|
||||
|
||||
class Meta:
|
||||
model = OIContestRank
|
||||
fields = "__all__"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.is_admin_role = kwargs.pop("is_admin_role", False)
|
||||
|
@ -3,7 +3,6 @@ from datetime import datetime, timedelta
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
from utils.api._serializers import DateTimeTZField
|
||||
from utils.api.tests import APITestCase
|
||||
|
||||
from .models import ContestAnnouncement, ContestRuleType, Contest
|
||||
@ -44,10 +43,9 @@ class ContestAdminAPITest(APITestCase):
|
||||
response = self.client.put(self.url, data=data)
|
||||
self.assertSuccess(response)
|
||||
response_data = response.data["data"]
|
||||
datetime_tz_field = DateTimeTZField()
|
||||
for k in data.keys():
|
||||
if isinstance(data[k], datetime):
|
||||
data[k] = datetime_tz_field.to_representation(data[k])
|
||||
continue
|
||||
self.assertEqual(response_data[k], data[k])
|
||||
|
||||
def test_get_contests(self):
|
||||
|
@ -1,7 +1,7 @@
|
||||
from django import forms
|
||||
|
||||
from judge.languages import language_names, spj_language_names
|
||||
from utils.api import DateTimeTZField, UsernameSerializer, serializers
|
||||
from utils.api import UsernameSerializer, serializers
|
||||
|
||||
from .models import Problem, ProblemRuleType, ProblemTag
|
||||
from .utils import parse_problem_template
|
||||
@ -87,15 +87,8 @@ class CompileSPJSerializer(serializers.Serializer):
|
||||
|
||||
|
||||
class BaseProblemSerializer(serializers.ModelSerializer):
|
||||
samples = serializers.JSONField()
|
||||
test_case_score = serializers.JSONField()
|
||||
languages = serializers.JSONField()
|
||||
template = serializers.JSONField()
|
||||
tags = serializers.SlugRelatedField(many=True, slug_field="name", read_only=True)
|
||||
create_time = DateTimeTZField()
|
||||
last_update_time = DateTimeTZField()
|
||||
created_by = UsernameSerializer()
|
||||
statistic_info = serializers.JSONField()
|
||||
|
||||
|
||||
class ProblemAdminSerializer(BaseProblemSerializer):
|
||||
@ -104,12 +97,6 @@ class ProblemAdminSerializer(BaseProblemSerializer):
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class ContestProblemAdminSerializer(BaseProblemSerializer):
|
||||
class Meta:
|
||||
model = Problem
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class ProblemSerializer(BaseProblemSerializer):
|
||||
template = serializers.SerializerMethodField()
|
||||
|
||||
@ -121,21 +108,16 @@ class ProblemSerializer(BaseProblemSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Problem
|
||||
exclude = ("contest", "test_case_score", "test_case_id", "visible", "is_public",
|
||||
"template", "spj_code", "spj_version", "spj_compile_ok")
|
||||
exclude = ("test_case_score", "test_case_id", "visible", "is_public",
|
||||
"spj_code", "spj_version", "spj_compile_ok")
|
||||
|
||||
|
||||
class ContestProblemSerializer(BaseProblemSerializer):
|
||||
class ProblemSafeSerializer(BaseProblemSerializer):
|
||||
class Meta:
|
||||
model = Problem
|
||||
exclude = ("test_case_score", "test_case_id", "visible", "is_public", "difficulty")
|
||||
|
||||
|
||||
class ContestProblemSafeSerializer(BaseProblemSerializer):
|
||||
class Meta:
|
||||
model = Problem
|
||||
exclude = ("test_case_score", "test_case_id", "visible", "is_public", "difficulty",
|
||||
"submission_number", "accepted_number", "statistic_info")
|
||||
exclude = ("test_case_score", "test_case_id", "visible", "is_public",
|
||||
"spj_code", "spj_version", "spj_compile_ok",
|
||||
"difficulty", "submission_number", "accepted_number", "statistic_info")
|
||||
|
||||
|
||||
class ContestProblemMakePublicSerializer(serializers.Serializer):
|
||||
|
@ -16,7 +16,7 @@ from utils.api import APIView, CSRFExemptAPIView, validate_serializer
|
||||
from utils.shortcuts import rand_str, natural_sort_key
|
||||
|
||||
from ..models import Problem, ProblemRuleType, ProblemTag
|
||||
from ..serializers import (CreateContestProblemSerializer, ContestProblemAdminSerializer, CompileSPJSerializer,
|
||||
from ..serializers import (CreateContestProblemSerializer, CompileSPJSerializer,
|
||||
CreateProblemSerializer, EditProblemSerializer, EditContestProblemSerializer,
|
||||
ProblemAdminSerializer, TestCaseUploadForm, ContestProblemMakePublicSerializer)
|
||||
|
||||
@ -320,7 +320,7 @@ class ContestProblemAPI(ProblemBase):
|
||||
except ProblemTag.DoesNotExist:
|
||||
tag = ProblemTag.objects.create(name=item)
|
||||
problem.tags.add(tag)
|
||||
return self.success(ContestProblemAdminSerializer(problem).data)
|
||||
return self.success(ProblemAdminSerializer(problem).data)
|
||||
|
||||
@problem_permission_required
|
||||
def get(self, request):
|
||||
@ -345,7 +345,7 @@ class ContestProblemAPI(ProblemBase):
|
||||
keyword = request.GET.get("keyword")
|
||||
if keyword:
|
||||
problems = problems.filter(title__contains=keyword)
|
||||
return self.success(self.paginate_data(request, problems, ContestProblemAdminSerializer))
|
||||
return self.success(self.paginate_data(request, problems, ProblemAdminSerializer))
|
||||
|
||||
@validate_serializer(EditContestProblemSerializer)
|
||||
@problem_permission_required
|
||||
|
@ -3,8 +3,7 @@ from django.db.models import Q, Count
|
||||
from utils.api import APIView
|
||||
from account.decorators import check_contest_permission
|
||||
from ..models import ProblemTag, Problem, ProblemRuleType
|
||||
from ..serializers import ProblemSerializer, TagSerializer
|
||||
from ..serializers import ContestProblemSerializer, ContestProblemSafeSerializer
|
||||
from ..serializers import ProblemSerializer, TagSerializer, ProblemSafeSerializer
|
||||
from contest.models import ContestRuleType
|
||||
|
||||
|
||||
@ -102,16 +101,16 @@ class ContestProblemAPI(APIView):
|
||||
except Problem.DoesNotExist:
|
||||
return self.error("Problem does not exist.")
|
||||
if self.contest.problem_details_permission(request.user):
|
||||
problem_data = ContestProblemSerializer(problem).data
|
||||
problem_data = ProblemSerializer(problem).data
|
||||
self._add_problem_status(request, [problem_data, ])
|
||||
else:
|
||||
problem_data = ContestProblemSafeSerializer(problem).data
|
||||
problem_data = ProblemSafeSerializer(problem).data
|
||||
return self.success(problem_data)
|
||||
|
||||
contest_problems = Problem.objects.select_related("created_by").filter(contest=self.contest, visible=True)
|
||||
if self.contest.problem_details_permission(request.user):
|
||||
data = ContestProblemSerializer(contest_problems, many=True).data
|
||||
data = ProblemSerializer(contest_problems, many=True).data
|
||||
self._add_problem_status(request, data)
|
||||
else:
|
||||
data = ContestProblemSafeSerializer(contest_problems, many=True).data
|
||||
data = ProblemSafeSerializer(contest_problems, many=True).data
|
||||
return self.success(data)
|
||||
|
@ -17,17 +17,15 @@ class ShareSubmissionSerializer(serializers.Serializer):
|
||||
|
||||
|
||||
class SubmissionModelSerializer(serializers.ModelSerializer):
|
||||
info = serializers.JSONField()
|
||||
statistic_info = serializers.JSONField()
|
||||
|
||||
class Meta:
|
||||
model = Submission
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
# 不显示submission info的serializer, 用于ACM rule_type
|
||||
class SubmissionSafeModelSerializer(serializers.ModelSerializer):
|
||||
problem = serializers.SlugRelatedField(read_only=True, slug_field="_id")
|
||||
statistic_info = serializers.JSONField()
|
||||
|
||||
class Meta:
|
||||
model = Submission
|
||||
@ -36,7 +34,6 @@ class SubmissionSafeModelSerializer(serializers.ModelSerializer):
|
||||
|
||||
class SubmissionListSerializer(serializers.ModelSerializer):
|
||||
problem = serializers.SlugRelatedField(read_only=True, slug_field="_id")
|
||||
statistic_info = serializers.JSONField()
|
||||
show_link = serializers.SerializerMethodField()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -1,12 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class DateTimeTZField(serializers.DateTimeField):
|
||||
def to_representation(self, value):
|
||||
# value = timezone.localtime(value)
|
||||
return super(DateTimeTZField, self).to_representation(value)
|
||||
|
||||
|
||||
class UsernameSerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField()
|
||||
username = serializers.CharField()
|
||||
|
Loading…
Reference in New Issue
Block a user