it must have been late when I tried to do this

This commit is contained in:
jonaswinkler 2020-12-28 12:29:53 +01:00
parent e2bea3aee3
commit e228e18f04

View File

@ -236,6 +236,15 @@ class BulkEditSerializer(serializers.Serializer):
raise serializers.ValidationError(
f"Some documents in {name} don't exist or were specified twice.")
def _validate_tag_id_list(self, tags, name="tags"):
if not type(tags) == list:
raise serializers.ValidationError(f"{name} must be a list")
if not all([type(i) == int for i in tags]):
raise serializers.ValidationError(f"{name} must be a list of integers")
count = Tag.objects.filter(id__in=tags).count()
if not count == len(tags):
raise serializers.ValidationError(
f"Some tags in {name} don't exist or were specified twice.")
def validate_documents(self, documents):
self._validate_document_id_list(documents)
@ -296,12 +305,12 @@ class BulkEditSerializer(serializers.Serializer):
def _validate_parameters_modify_tags(self, parameters):
if "add_tags" in parameters:
self._validate_document_id_list(parameters['add_tags'], "add_tags")
self._validate_tag_id_list(parameters['add_tags'], "add_tags")
else:
raise serializers.ValidationError("add_tags not specified")
if "remove_tags" in parameters:
self._validate_document_id_list(parameters['remove_tags'], "remove_tags")
self._validate_tag_id_list(parameters['remove_tags'], "remove_tags")
else:
raise serializers.ValidationError("remove_tags not specified")