2017-05-15 16:42:15 +08:00
|
|
|
from .models import Submission
|
2017-05-08 17:29:01 +08:00
|
|
|
from utils.api import serializers
|
2017-05-09 14:41:26 +08:00
|
|
|
from judge.languages import language_names
|
2017-05-08 17:29:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
class CreateSubmissionSerializer(serializers.Serializer):
|
|
|
|
problem_id = serializers.IntegerField()
|
2017-05-09 14:41:26 +08:00
|
|
|
language = serializers.ChoiceField(choices=language_names)
|
2017-05-08 17:29:01 +08:00
|
|
|
code = serializers.CharField(max_length=20000)
|
2017-08-01 16:52:48 +08:00
|
|
|
contest_id = serializers.IntegerField(required=False)
|
2017-10-27 18:36:29 +08:00
|
|
|
captcha = serializers.CharField(required=False)
|
2017-05-15 16:42:15 +08:00
|
|
|
|
|
|
|
|
2017-10-15 18:36:55 +08:00
|
|
|
class ShareSubmissionSerializer(serializers.Serializer):
|
|
|
|
id = serializers.CharField()
|
|
|
|
shared = serializers.BooleanField()
|
|
|
|
|
|
|
|
|
2017-05-15 16:42:15 +08:00
|
|
|
class SubmissionModelSerializer(serializers.ModelSerializer):
|
|
|
|
info = serializers.JSONField()
|
2017-07-04 20:59:25 +08:00
|
|
|
statistic_info = serializers.JSONField()
|
2017-05-15 16:42:15 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Submission
|
2017-07-04 20:59:25 +08:00
|
|
|
|
2017-07-05 21:09:14 +08:00
|
|
|
|
2017-09-24 09:48:17 +08:00
|
|
|
# 不显示submission info的serializer, 用于ACM rule_type
|
2017-10-15 18:36:55 +08:00
|
|
|
class SubmissionSafeModelSerializer(serializers.ModelSerializer):
|
2017-09-29 21:58:20 +08:00
|
|
|
problem = serializers.SlugRelatedField(read_only=True, slug_field="_id")
|
2017-07-05 21:09:14 +08:00
|
|
|
statistic_info = serializers.JSONField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Submission
|
2017-09-24 09:48:17 +08:00
|
|
|
exclude = ("info", "contest")
|
2017-07-05 21:09:14 +08:00
|
|
|
|
|
|
|
|
2017-08-01 16:52:48 +08:00
|
|
|
class SubmissionListSerializer(serializers.ModelSerializer):
|
2017-09-29 21:58:20 +08:00
|
|
|
problem = serializers.SlugRelatedField(read_only=True, slug_field="_id")
|
2017-07-05 21:09:14 +08:00
|
|
|
statistic_info = serializers.JSONField()
|
|
|
|
show_link = serializers.SerializerMethodField()
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-07-06 16:09:38 +08:00
|
|
|
self.user = kwargs.pop("user", None)
|
2017-07-05 21:09:14 +08:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Submission
|
2017-09-24 09:48:17 +08:00
|
|
|
exclude = ("info", "contest", "code")
|
2017-07-05 21:09:14 +08:00
|
|
|
|
|
|
|
def get_show_link(self, obj):
|
2017-08-29 19:26:38 +08:00
|
|
|
# 没传user或为匿名user
|
2017-10-15 18:36:55 +08:00
|
|
|
if self.user is None or not self.user.is_authenticated():
|
2017-07-06 16:09:38 +08:00
|
|
|
return False
|
2017-07-05 21:09:14 +08:00
|
|
|
return obj.check_user_permission(self.user)
|