Skip to content

Commit

Permalink
Add bst category support for API edit and describe
Browse files Browse the repository at this point in the history
  • Loading branch information
allholy committed Dec 19, 2024
1 parent e348540 commit d4326aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions apiv2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,12 @@ def validate_name(value):
return value


def validate_bst_category(value):
if value not in [key for key, name in Sound.BST_CATEGORY_CHOICES]:
raise serializers.ValidationError('Invalid BST category, should be a valid Broad Sound Taxonomy code.')
return value


def validate_tags(value):
tags = clean_and_split_tags(value)
if len(tags) < 3:
Expand Down Expand Up @@ -694,6 +700,8 @@ class SoundDescriptionSerializer(serializers.Serializer):
name = serializers.CharField(max_length=512, required=False,
help_text='Not required. Name you want to give to the sound (by default it will be '
'the original filename).')
bst_category = serializers.ChoiceField(required=False, allow_blank=True, choices=Sound.BST_CATEGORY_CHOICES,
help_text='Not required. Must be a valid Broad Sound Taxonomy category code.')
tags = serializers.CharField(max_length=512,
help_text='Separate tags with spaces. Join multi-word tags with dashes.')
description = serializers.CharField(help_text='Textual description of the sound.')
Expand Down Expand Up @@ -721,6 +729,9 @@ def validate_tags(self, value):

def validate_name(self, value):
return validate_name(value)

def validate_bst_category(self, value):
return validate_bst_category(value)

def validate_description(self, value):
return validate_description(value)
Expand All @@ -732,6 +743,8 @@ def validate_pack(self, value):
class EditSoundDescriptionSerializer(serializers.Serializer):
name = serializers.CharField(max_length=512, required=False,
help_text='Not required. New name you want to give to the sound.')
bst_category = serializers.ChoiceField(required=False, allow_blank=True, choices=Sound.BST_CATEGORY_CHOICES,
help_text='Not required. Must be a valid Broad Sound Taxonomy category code.')
tags = serializers.CharField(max_length=512, required=False,
help_text='Not required. Tags that should be assigned to the sound (note that '
'existing ones will be deleted). Separate tags with spaces. Join multi-word '
Expand All @@ -756,6 +769,9 @@ def validate_tags(self, value):

def validate_name(self, value):
return validate_name(value)

def validate_bst_category(self, value):
return validate_bst_category(value)

def validate_description(self, value):
return validate_description(value)
Expand All @@ -770,6 +786,8 @@ class UploadAndDescribeAudioFileSerializer(serializers.Serializer):
name = serializers.CharField(max_length=512, required=False,
help_text='Not required. Name you want to give to the sound (by default it will be '
'the original filename).')
bst_category = serializers.ChoiceField(required=False, allow_blank=True, choices=Sound.BST_CATEGORY_CHOICES,
help_text='Not required. Must be a valid Broad Sound Taxonomy category code.')
tags = serializers.CharField(max_length=512, required=False,
help_text='Only required if providing file description. Separate tags with spaces. '
'Join multi-word tags with dashes.')
Expand Down Expand Up @@ -809,15 +827,22 @@ def validate(self, data):
data['description'] = validate_description(self.initial_data.get('description', ''))
except serializers.ValidationError as e:
errors['description'] = e.detail

try:
data['name'] = validate_name(self.initial_data.get('name', ''))
except serializers.ValidationError as e:
errors['name'] = e.detail

try:
data['bst_category'] = validate_bst_category(self.initial_data.get('bst_category', ''))
except serializers.ValidationError as e:
errors['bst_category'] = e.detail

try:
data['tags'] = validate_tags(self.initial_data.get('tags', ''))
except serializers.ValidationError as e:
errors['tags'] = e.detail

try:
data['geotag'] = validate_geotag(self.initial_data.get('geotag', ''))
except serializers.ValidationError as e:
Expand Down
3 changes: 3 additions & 0 deletions apiv2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,9 @@ def post(self, request, *args, **kwargs):
if 'name' in serializer.data:
if serializer.data['name']:
sound.original_filename = serializer.data['name']
if 'bst_category' in serializer.data:
if serializer.data['bst_category']:
sound.bst_category = serializer.data['bst_category']
if 'description' in serializer.data:
if serializer.data['description']:
sound.description = serializer.data['description']
Expand Down

0 comments on commit d4326aa

Please sign in to comment.