fix
This commit is contained in:
@@ -156,6 +156,15 @@ class ProblemSerializer(BaseProblemSerializer):
|
||||
"answers",
|
||||
)
|
||||
|
||||
def to_representation(self, instance):
|
||||
data = super().to_representation(instance)
|
||||
# 如果 allow_flowchart=False,则不返回 flowchart 相关字段
|
||||
if not instance.allow_flowchart:
|
||||
flowchart_fields = ['mermaid_code', 'flowchart_data', 'flowchart_hint', 'show_flowchart']
|
||||
for field in flowchart_fields:
|
||||
data.pop(field, None)
|
||||
return data
|
||||
|
||||
|
||||
class ProblemListSerializer(BaseProblemSerializer):
|
||||
class Meta:
|
||||
@@ -173,6 +182,15 @@ class ProblemListSerializer(BaseProblemSerializer):
|
||||
"rule_type",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
data = super().to_representation(instance)
|
||||
# 如果 allow_flowchart=False,则不返回 flowchart 相关字段
|
||||
if not instance.allow_flowchart:
|
||||
flowchart_fields = ['mermaid_code', 'flowchart_data', 'flowchart_hint', 'show_flowchart']
|
||||
for field in flowchart_fields:
|
||||
data.pop(field, None)
|
||||
return data
|
||||
|
||||
|
||||
class ProblemSafeSerializer(BaseProblemSerializer):
|
||||
template = serializers.SerializerMethodField("get_public_template")
|
||||
@@ -191,6 +209,15 @@ class ProblemSafeSerializer(BaseProblemSerializer):
|
||||
"answers",
|
||||
)
|
||||
|
||||
def to_representation(self, instance):
|
||||
data = super().to_representation(instance)
|
||||
# 如果 allow_flowchart=False,则不返回 flowchart 相关字段
|
||||
if not instance.allow_flowchart:
|
||||
flowchart_fields = ['mermaid_code', 'flowchart_data', 'flowchart_hint', 'show_flowchart']
|
||||
for field in flowchart_fields:
|
||||
data.pop(field, None)
|
||||
return data
|
||||
|
||||
|
||||
class ContestProblemMakePublicSerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField()
|
||||
|
||||
Reference in New Issue
Block a user