OnlineJudge/contest/serializers.py

91 lines
3.0 KiB
Python
Raw Normal View History

2017-01-26 09:06:24 +00:00
from utils.api import DateTimeTZField, UsernameSerializer, serializers
2017-01-26 04:33:00 +00:00
2017-01-29 09:04:56 +00:00
from .models import Contest, ContestAnnouncement, ContestRuleType
from .models import ACMContestRank, OIContestRank
2017-01-26 04:33:00 +00:00
class CreateConetestSeriaizer(serializers.Serializer):
title = serializers.CharField(max_length=128)
description = serializers.CharField()
start_time = serializers.DateTimeField()
end_time = serializers.DateTimeField()
rule_type = serializers.ChoiceField(choices=[ContestRuleType.ACM, ContestRuleType.OI])
password = serializers.CharField(allow_blank=True, max_length=32)
visible = serializers.BooleanField()
real_time_rank = serializers.BooleanField()
allowed_ip_ranges = serializers.ListField(child=serializers.CharField(max_length=32), allow_empty=True)
2017-01-26 04:33:00 +00:00
class EditConetestSeriaizer(serializers.Serializer):
id = serializers.IntegerField()
title = serializers.CharField(max_length=128)
description = serializers.CharField()
start_time = serializers.DateTimeField()
end_time = serializers.DateTimeField()
password = serializers.CharField(allow_blank=True, allow_null=True, max_length=32)
visible = serializers.BooleanField()
real_time_rank = serializers.BooleanField()
allowed_ip_ranges = serializers.ListField(child=serializers.CharField(max_length=32))
class ContestAdminSerializer(serializers.ModelSerializer):
2017-01-26 04:33:00 +00:00
start_time = DateTimeTZField()
end_time = DateTimeTZField()
create_time = DateTimeTZField()
last_update_time = DateTimeTZField()
created_by = UsernameSerializer()
2017-01-26 05:45:39 +00:00
status = serializers.CharField()
contest_type = serializers.CharField()
2017-01-26 04:33:00 +00:00
class Meta:
model = Contest
class ContestSerializer(ContestAdminSerializer):
2017-01-26 04:33:00 +00:00
class Meta:
model = Contest
exclude = ("password", "visible", "allowed_ip_ranges")
2017-01-27 15:20:56 +00:00
2017-01-29 09:04:56 +00:00
class ContestAnnouncementSerializer(serializers.ModelSerializer):
created_by = UsernameSerializer()
create_time = DateTimeTZField()
class Meta:
model = ContestAnnouncement
class CreateContestAnnouncementSerializer(serializers.Serializer):
contest_id = serializers.IntegerField()
2017-01-29 09:04:56 +00:00
title = serializers.CharField(max_length=128)
content = serializers.CharField()
visible = serializers.BooleanField()
class EditContestAnnouncementSerializer(serializers.Serializer):
id = serializers.IntegerField()
title = serializers.CharField(max_length=128, required=False)
content = serializers.CharField(required=False, allow_blank=True)
visible = serializers.BooleanField(required=False)
class ContestPasswordVerifySerializer(serializers.Serializer):
contest_id = serializers.IntegerField()
password = serializers.CharField(max_length=30, required=True)
class ACMContestRankSerializer(serializers.ModelSerializer):
user = UsernameSerializer()
submission_info = serializers.JSONField()
class Meta:
model = ACMContestRank
class OIContestRankSerializer(serializers.ModelSerializer):
user = UsernameSerializer()
submission_info = serializers.JSONField()
class Meta:
model = OIContestRank