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