class CourseToAddSerializer(serializers.Serializer): id = serializers.IntegerField() name = serializers.CharField(max_length=20) s_year = serializers.CharField(max_length=4) short_description = serializers.CharField(max_length=40, required=False) is_exist = serializers.BooleanField() status = serializers.BooleanField()
class CreateEditWebsiteConfigSerializer(serializers.Serializer): website_base_url = serializers.CharField(max_length=128) website_name = serializers.CharField(max_length=64) website_name_shortcut = serializers.CharField(max_length=64) website_footer = serializers.CharField(max_length=1024 * 1024) allow_register = serializers.BooleanField() submission_list_show_all = serializers.BooleanField()
class CreateOrEditProblemSerializer(serializers.Serializer): _id = serializers.CharField(max_length=32, allow_blank=True, allow_null=True) title = serializers.CharField(max_length=128) description = serializers.CharField() input_description = serializers.CharField() output_description = serializers.CharField() samples = serializers.ListField(child=CreateSampleSerializer(), allow_empty=False) test_case_id = serializers.CharField(max_length=32) test_case_score = serializers.ListField( child=CreateTestCaseScoreSerializer(), allow_empty=False) time_limit = serializers.IntegerField(min_value=1, max_value=1000 * 60) memory_limit = serializers.IntegerField(min_value=1, max_value=1024) languages = serializers.MultipleChoiceField(choices=language_names) template = serializers.DictField(child=serializers.CharField(min_length=1)) rule_type = serializers.ChoiceField( choices=[ProblemRuleType.ACM, ProblemRuleType.OI]) spj = serializers.BooleanField() spj_language = serializers.ChoiceField(choices=spj_language_names, allow_blank=True, allow_null=True) spj_code = serializers.CharField(allow_blank=True, allow_null=True) spj_compile_ok = serializers.BooleanField(default=False) visible = serializers.BooleanField() difficulty = serializers.ChoiceField( choices=[Difficulty.LOW, Difficulty.MID, Difficulty.HIGH]) tags = serializers.ListField(child=serializers.CharField(max_length=32), allow_empty=False) hint = serializers.CharField(allow_blank=True, allow_null=True) source = serializers.CharField(max_length=256, allow_blank=True, allow_null=True)
class CreateOrEditProblemSerializer(serializers.Serializer): _id = serializers.CharField(max_length=32, allow_blank=True, allow_null=True) title = serializers.CharField(max_length=1024) description = serializers.CharField() input_description = serializers.CharField() output_description = serializers.CharField() samples = serializers.ListField(child=CreateSampleSerializer(), allow_empty=False) test_case_id = serializers.CharField(max_length=32) test_case_score = serializers.ListField( child=CreateTestCaseScoreSerializer(), allow_empty=True) time_limit = serializers.IntegerField(min_value=1, max_value=1000 * 60) memory_limit = serializers.IntegerField(min_value=1, max_value=1024) languages = LanguageNameMultiChoiceField() template = serializers.DictField(child=serializers.CharField(min_length=1)) rule_type = serializers.ChoiceField( choices=[ProblemRuleType.ACM, ProblemRuleType.OI]) total_score = serializers.IntegerField(min_value=0) io_mode = ProblemIOModeSerializer() spj = serializers.BooleanField() spj_language = SPJLanguageNameChoiceField(allow_blank=True, allow_null=True) spj_code = serializers.CharField(allow_blank=True, allow_null=True) spj_compile_ok = serializers.BooleanField(default=False) visible = serializers.BooleanField() difficulty = serializers.ChoiceField(choices=Difficulty.choices()) tags = serializers.ListField(child=serializers.CharField(max_length=32), allow_empty=False) hint = serializers.CharField(allow_blank=True, allow_null=True) source = serializers.CharField(max_length=256, allow_blank=True, allow_null=True) share_submission = serializers.BooleanField()
class CreateEditForumPostSerializer(serializers.Serializer): id = serializers.IntegerField() title = serializers.CharField(max_length=64) sort = serializers.IntegerField(min_value=0, max_value=20) content = serializers.CharField(max_length=1024 * 1024 * 8) is_top = serializers.BooleanField() is_nice = serializers.BooleanField() is_light = serializers.BooleanField()
class CreateEditWebsiteConfigSerializer(serializers.Serializer): website_base_url = serializers.CharField(max_length=128) website_name = serializers.CharField(max_length=64) website_name_shortcut = serializers.CharField(max_length=64) website_footer = serializers.CharField(max_length=1024 * 1024) allow_register = serializers.BooleanField() submission_list_show_all = serializers.BooleanField() forum_sort = serializers.ListField(allow_empty=False) allow_forum_post = serializers.BooleanField() allow_forum_reply = serializers.BooleanField()
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)
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 EditUserSerializer(serializers.Serializer): id = serializers.IntegerField() username = serializers.CharField(max_length=32) real_name = serializers.CharField(max_length=32, allow_blank=True, allow_null=True) password = serializers.CharField(min_length=6, allow_blank=True, required=False, default=None) email = serializers.EmailField(max_length=64) admin_type = serializers.ChoiceField(choices=(AdminType.REGULAR_USER, AdminType.ADMIN, AdminType.SUPER_ADMIN)) problem_permission = serializers.ChoiceField(choices=(ProblemPermission.NONE, ProblemPermission.OWN, ProblemPermission.ALL)) open_api = serializers.BooleanField() two_factor_auth = serializers.BooleanField() is_disabled = serializers.BooleanField()
class EditSMTPConfigSerializer(serializers.Serializer): server = serializers.CharField(max_length=128) port = serializers.IntegerField(default=25) email = serializers.CharField(max_length=256) password = serializers.CharField(max_length=128, required=False, allow_null=True, allow_blank=True) tls = serializers.BooleanField()
class ContestAdminSerializer(serializers.ModelSerializer): created_by = UsernameSerializer() status = serializers.CharField() contest_type = serializers.CharField() course = serializers.BooleanField() # 课程号 course_num = serializers.CharField() # 老师 teacher = serializers.CharField() class Meta: model = Contest fields = "__all__"
class ImportProblemSerializer(serializers.Serializer): display_id = serializers.CharField(max_length=128) title = serializers.CharField(max_length=128) description = FormatValueSerializer() input_description = FormatValueSerializer() output_description = FormatValueSerializer() hint = FormatValueSerializer() test_case_score = serializers.ListField(child=TestCaseScoreSerializer(), allow_null=True) time_limit = serializers.IntegerField(min_value=1, max_value=60000) memory_limit = serializers.IntegerField(min_value=1, max_value=10240) samples = serializers.ListField(child=CreateSampleSerializer()) template = serializers.DictField(child=TemplateSerializer()) languages = LanguageNameMultiChoiceField() spj = SPJSerializer(allow_null=True) rule_type = serializers.ChoiceField(choices=ProblemRuleType.choices()) source = serializers.CharField(max_length=200, allow_blank=True, allow_null=True) answers = serializers.ListField(child=AnswerSerializer()) tags = serializers.ListField(child=serializers.CharField()) visible = serializers.BooleanField(default=False)
class EditJudgeServerSerializer(serializers.Serializer): id = serializers.IntegerField() is_disabled = serializers.BooleanField()
class ShareSubmissionSerializer(serializers.Serializer): id = serializers.CharField() shared = 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 CreateContestAnnouncementSerializer(serializers.Serializer): contest_id = serializers.IntegerField() title = serializers.CharField(max_length=128) content = serializers.CharField() visible = serializers.BooleanField()
class ACMContesHelperSerializer(serializers.Serializer): contest_id = serializers.IntegerField() problem_id = serializers.CharField() rank_id = serializers.IntegerField() checked = serializers.BooleanField()
class AnswerContestQuestionSerializer(serializers.Serializer): qid = serializers.IntegerField() answer = serializers.CharField(max_length=512) is_public = serializers.BooleanField(default=False) is_solved = serializers.BooleanField(default=False)
class EditGroupUserSeriaizer(serializers.Serializer): group_id = serializers.IntegerField() user_id = serializers.IntegerField() user_type = serializers.BooleanField()
class GroupUserSeriaizer(serializers.Serializer): user_id = serializers.IntegerField() username = serializers.CharField() user_type = serializers.BooleanField()
class EditAnnouncementSerializer(serializers.Serializer): id = serializers.IntegerField() title = serializers.CharField(max_length=64) content = serializers.CharField(max_length=1024 * 1024 * 8) visible = serializers.BooleanField() istop = serializers.BooleanField()
class EditContestProblemSerializer(CreateOrEditProblemSerializer): id = serializers.IntegerField() contest_id = serializers.IntegerField() is_drag = serializers.BooleanField()
class CreateAnnouncementSerializer(serializers.Serializer): title = serializers.CharField(max_length=64) content = serializers.CharField(max_length=1024 * 1024 * 8) visible = serializers.BooleanField() istop = serializers.BooleanField()
class ExportProblemSerializer(serializers.ModelSerializer): display_id = serializers.SerializerMethodField() description = serializers.SerializerMethodField() input_description = serializers.SerializerMethodField() output_description = serializers.SerializerMethodField() test_case_score = serializers.SerializerMethodField() hint = serializers.SerializerMethodField() spj = serializers.SerializerMethodField() template = serializers.SerializerMethodField() model_solution = serializers.SerializerMethodField() manual_judge = serializers.BooleanField() source = serializers.SerializerMethodField() tags = serializers.SlugRelatedField(many=True, slug_field="name", read_only=True) def get_display_id(self, obj): return obj._id def _html_format_value(self, value): return {"format": "html", "value": value} def get_description(self, obj): return self._html_format_value(obj.description) def get_input_description(self, obj): return self._html_format_value(obj.input_description) def get_output_description(self, obj): return self._html_format_value(obj.output_description) def get_hint(self, obj): return self._html_format_value(obj.hint) def get_test_case_score(self, obj): return [{ "score": item["score"] if obj.rule_type == ProblemRuleType.OI else 100, "input_name": item["input_name"], "output_name": item["output_name"] } for item in obj.test_case_score] def get_spj(self, obj): return { "code": obj.spj_code, "language": obj.spj_language } if obj.spj else None def get_template(self, obj): ret = {} for k, v in obj.template.items(): ret[k] = parse_problem_template(v) return ret def get_model_solution(self, obj): return obj.model_solution def get_source(self, obj): return obj.source or f"{SysOptions.website_name} {SysOptions.website_base_url}" class Meta: model = Problem fields = ("display_id", "title", "description", "tags", "input_description", "output_description", "test_case_score", "hint", "time_limit", "memory_limit", "samples", "template", "model_solution", "manual_judge", "spj", "rule_type", "source", "template")