Skip to content

Commit 20165bf

Browse files
triklozoidjombooth
andauthored
fix: LEAP-1887: Add project color validation (#7349)
Co-authored-by: Jo Booth <[email protected]> Co-authored-by: triklozoid <[email protected]>
1 parent 938385f commit 20165bf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

label_studio/projects/serializers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ def to_internal_value(self, data):
187187

188188
return data
189189

190+
def validate_color(self, value):
191+
# color : "#FF4C25"
192+
if value.startswith('#') and len(value) == 7:
193+
try:
194+
int(value[1:], 16)
195+
return value
196+
except ValueError:
197+
pass
198+
raise serializers.ValidationError('Color must be in "#RRGGBB" format')
199+
190200
class Meta:
191201
model = Project
192202
extra_kwargs = {

0 commit comments

Comments
 (0)