mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 07:56:44 -06:00
Move backend type validation from serializer to model
This commit is contained in:
parent
409903d017
commit
6e58c480ee
@ -1,5 +1,3 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.choices import *
|
||||
@ -41,13 +39,6 @@ class DataSourceSerializer(NetBoxModelSerializer):
|
||||
'parameters', 'ignore_rules', 'created', 'last_updated', 'file_count',
|
||||
]
|
||||
|
||||
def clean(self):
|
||||
|
||||
if self.type and self.type not in get_data_backend_choices():
|
||||
raise ValidationError({
|
||||
'type': _("Unknown backend type: {type}".format(type=self.type))
|
||||
})
|
||||
|
||||
|
||||
class DataFileSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
|
@ -118,6 +118,12 @@ class DataSource(JobsMixin, PrimaryModel):
|
||||
|
||||
def clean(self):
|
||||
|
||||
# Validate data backend type
|
||||
if self.type and self.type not in registry['data_backends']:
|
||||
raise ValidationError({
|
||||
'type': _("Unknown backend type: {type}".format(type=self.type))
|
||||
})
|
||||
|
||||
# Ensure URL scheme matches selected type
|
||||
if self.backend_class.is_local and self.url_scheme not in ('file', ''):
|
||||
raise ValidationError({
|
||||
|
Loading…
Reference in New Issue
Block a user