fix
This commit is contained in:
@@ -145,6 +145,8 @@ class ProblemAdminListSerializer(BaseProblemSerializer):
|
||||
|
||||
class ProblemSerializer(BaseProblemSerializer):
|
||||
template = serializers.SerializerMethodField("get_public_template")
|
||||
mermaid_code = serializers.SerializerMethodField()
|
||||
flowchart_data = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Problem
|
||||
@@ -156,6 +158,18 @@ class ProblemSerializer(BaseProblemSerializer):
|
||||
"answers",
|
||||
)
|
||||
|
||||
def get_mermaid_code(self, obj):
|
||||
# 当 allow_flowchart 为 True 时,不返回 mermaid_code
|
||||
if obj.allow_flowchart:
|
||||
return None
|
||||
return obj.mermaid_code
|
||||
|
||||
def get_flowchart_data(self, obj):
|
||||
# 当 allow_flowchart 为 True 时,不返回 flowchart_data
|
||||
if obj.allow_flowchart:
|
||||
return None
|
||||
return obj.flowchart_data
|
||||
|
||||
|
||||
class ProblemListSerializer(BaseProblemSerializer):
|
||||
class Meta:
|
||||
@@ -176,6 +190,8 @@ class ProblemListSerializer(BaseProblemSerializer):
|
||||
|
||||
class ProblemSafeSerializer(BaseProblemSerializer):
|
||||
template = serializers.SerializerMethodField("get_public_template")
|
||||
mermaid_code = serializers.SerializerMethodField()
|
||||
flowchart_data = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Problem
|
||||
@@ -191,6 +207,18 @@ class ProblemSafeSerializer(BaseProblemSerializer):
|
||||
"answers",
|
||||
)
|
||||
|
||||
def get_mermaid_code(self, obj):
|
||||
# 当 allow_flowchart 为 True 时,不返回 mermaid_code
|
||||
if obj.allow_flowchart:
|
||||
return None
|
||||
return obj.mermaid_code
|
||||
|
||||
def get_flowchart_data(self, obj):
|
||||
# 当 allow_flowchart 为 True 时,不返回 flowchart_data
|
||||
if obj.allow_flowchart:
|
||||
return None
|
||||
return obj.flowchart_data
|
||||
|
||||
class ContestProblemMakePublicSerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField()
|
||||
display_id = serializers.CharField(max_length=32)
|
||||
|
||||
Reference in New Issue
Block a user