2017-12-01 09:19:31 +00:00
|
|
|
from utils.api import UsernameSerializer, serializers
|
2017-01-26 04:33:00 +00:00
|
|
|
|
2017-01-29 09:04:56 +00:00
|
|
|
from .models import Contest, ContestAnnouncement, ContestRuleType
|
2017-08-01 08:52:48 +00:00
|
|
|
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()
|
2017-11-10 11:40:54 +00:00
|
|
|
allowed_ip_ranges = serializers.ListField(child=serializers.CharField(max_length=32), allow_empty=True)
|
2017-01-26 04:33:00 +00:00
|
|
|
|
|
|
|
|
2017-07-17 13:28:06 +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()
|
2017-11-10 11:40:54 +00:00
|
|
|
allowed_ip_ranges = serializers.ListField(child=serializers.CharField(max_length=32))
|
2017-07-17 13:28:06 +00:00
|
|
|
|
|
|
|
|
2017-07-18 03:18:18 +00:00
|
|
|
class ContestAdminSerializer(serializers.ModelSerializer):
|
2017-01-26 04:33:00 +00:00
|
|
|
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
|
|
|
|
2017-07-18 03:18:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = Contest
|
2017-12-01 09:19:31 +00:00
|
|
|
fields = "__all__"
|
2017-07-18 03:18:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContestSerializer(ContestAdminSerializer):
|
2017-01-26 04:33:00 +00:00
|
|
|
class Meta:
|
|
|
|
model = Contest
|
2017-11-10 11:40:54 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ContestAnnouncement
|
2017-12-01 09:19:31 +00:00
|
|
|
fields = "__all__"
|
2017-01-29 09:04:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CreateContestAnnouncementSerializer(serializers.Serializer):
|
2017-11-06 11:05:21 +00:00
|
|
|
contest_id = serializers.IntegerField()
|
2017-01-29 09:04:56 +00:00
|
|
|
title = serializers.CharField(max_length=128)
|
|
|
|
content = serializers.CharField()
|
2017-11-06 11:05:21 +00:00
|
|
|
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)
|
2017-07-17 13:28:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContestPasswordVerifySerializer(serializers.Serializer):
|
|
|
|
contest_id = serializers.IntegerField()
|
|
|
|
password = serializers.CharField(max_length=30, required=True)
|
2017-08-01 08:52:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ACMContestRankSerializer(serializers.ModelSerializer):
|
2017-11-29 06:06:32 +00:00
|
|
|
user = serializers.SerializerMethodField()
|
2017-08-01 08:52:48 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ACMContestRank
|
2017-12-01 09:19:31 +00:00
|
|
|
fields = "__all__"
|
2017-08-01 08:52:48 +00:00
|
|
|
|
2017-11-29 06:06:32 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-12-03 07:39:02 +00:00
|
|
|
self.is_contest_admin = kwargs.pop("is_contest_admin", False)
|
2017-11-29 06:06:32 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def get_user(self, obj):
|
2017-12-03 07:39:02 +00:00
|
|
|
return UsernameSerializer(obj.user, need_real_name=self.is_contest_admin).data
|
2017-11-29 06:06:32 +00:00
|
|
|
|
2017-08-01 08:52:48 +00:00
|
|
|
|
|
|
|
class OIContestRankSerializer(serializers.ModelSerializer):
|
2017-11-29 06:06:32 +00:00
|
|
|
user = serializers.SerializerMethodField()
|
2017-08-01 08:52:48 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = OIContestRank
|
2017-12-01 09:19:31 +00:00
|
|
|
fields = "__all__"
|
2017-11-29 06:06:32 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-12-03 07:39:02 +00:00
|
|
|
self.is_contest_admin = kwargs.pop("is_contest_admin", False)
|
2017-11-29 06:06:32 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def get_user(self, obj):
|
2017-12-03 07:39:02 +00:00
|
|
|
return UsernameSerializer(obj.user, need_real_name=self.is_contest_admin).data
|
|
|
|
|
|
|
|
|
|
|
|
class ACMContesHelperSerializer(serializers.Serializer):
|
|
|
|
contest_id = serializers.IntegerField()
|
|
|
|
problem_id = serializers.CharField()
|
|
|
|
rank_id = serializers.IntegerField()
|
|
|
|
checked = serializers.BooleanField()
|