2017-05-15 08:42:15 +00:00
|
|
|
from .models import Submission
|
2017-07-04 12:59:25 +00:00
|
|
|
from account.models import User
|
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-05-15 08:42:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SubmissionModelSerializer(serializers.ModelSerializer):
|
|
|
|
info = serializers.JSONField()
|
2017-07-04 12:59:25 +00:00
|
|
|
statistic_info = serializers.JSONField()
|
2017-05-15 08:42:15 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Submission
|
2017-07-04 12:59:25 +00:00
|
|
|
|
2017-07-05 13:09:14 +00:00
|
|
|
|
|
|
|
# 不显示submission info详情的serializer
|
|
|
|
class SubmissionSafeSerializer(serializers.ModelSerializer):
|
|
|
|
username = serializers.SerializerMethodField()
|
|
|
|
statistic_info = serializers.JSONField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Submission
|
|
|
|
exclude = ('info', 'contest_id')
|
|
|
|
|
2017-07-04 12:59:25 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_username(obj):
|
|
|
|
return User.objects.get(id=obj.user_id).username
|
2017-07-05 13:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SubmissionListSerializer(SubmissionSafeSerializer):
|
|
|
|
username = serializers.SerializerMethodField()
|
|
|
|
statistic_info = serializers.JSONField()
|
|
|
|
show_link = serializers.SerializerMethodField()
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.user = kwargs.pop('user', None)
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Submission
|
|
|
|
exclude = ('info', 'contest_id', 'code')
|
|
|
|
|
|
|
|
def get_show_link(self, obj):
|
|
|
|
return obj.check_user_permission(self.user)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_username(obj):
|
|
|
|
return User.objects.get(id=obj.user_id).username
|