MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / validate

Method validate

apps/m3u/serializers.py:74–92  ·  view source on GitHub ↗

Custom validation to handle default profiles

(self, data)

Source from the content-addressed store, hash-verified

72 return super().create(validated_data)
73
74 def validate(self, data):
75 """Custom validation to handle default profiles"""
76 # For updates to existing instances
77 if self.instance and self.instance.is_default:
78 # For default profiles, search_pattern and replace_pattern are not required
79 # and we don't want to validate them since they shouldn't be changed
80 return data
81
82 # For non-default profiles or new profiles, ensure required fields are present
83 if not data.get('search_pattern'):
84 raise serializers.ValidationError({
85 'search_pattern': ['This field is required for non-default profiles.']
86 })
87 if not data.get('replace_pattern'):
88 raise serializers.ValidationError({
89 'replace_pattern': ['This field is required for non-default profiles.']
90 })
91
92 return data
93
94 def update(self, instance, validated_data):
95 if instance.is_default:

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected