1- from copy import deepcopy
2-
31from django .core .exceptions import ValidationError
42from django .db import transaction
53from django .db .models import Q
97
108from openwisp_utils .api .serializers import ValidatedModelSerializer
119
12- from ...serializers import BaseSerializer , ValidatedDeviceIdSerializer
10+ from ...serializers import BaseSerializer
1311from .. import settings as app_settings
1412
1513Template = load_model ('config' , 'Template' )
@@ -106,7 +104,10 @@ def get_queryset(self):
106104 return queryset
107105
108106
109- class BaseConfigSerializer (ValidatedDeviceIdSerializer ):
107+ class BaseConfigSerializer (ValidatedModelSerializer ):
108+ # The device object is excluded from validation
109+ # because this serializer focuses on validating
110+ # config objects.
110111 exclude_validation = ['device' ]
111112
112113 class Meta :
@@ -127,22 +128,12 @@ def validate(self, data):
127128 config object pointing to an existing device,
128129 the validation will fail because a config object
129130 for this device already exists (due to one-to-one relationship).
130-
131- For new devices, the device hasn't been created yet,
132- so we have to exclude the `device` field from validation.
133131 """
134- # Existing device
135132 device = self .context .get ('device' )
136- # data.pop('device', None)
137- # import ipdb; ipdb.set_trace()
138133 if not self .instance and device :
139134 # Existing device with existing config
140- # Or it's an exsiting device with a new config
141135 if device ._has_config ():
142136 self .instance = device .config
143- # return super().validate(data)
144- # New device
145- # self.exclude_validation = ['device']
146137 return super ().validate (data )
147138
148139
@@ -216,10 +207,6 @@ def _update_config(self, device, config_data):
216207 except ValidationError as error :
217208 raise serializers .ValidationError ({'config' : error .messages })
218209
219- # def run_validation(self, *args, **kwargs):
220- # import ipdb; ipdb.set_trace()
221- # return super().run_validation(*args, **kwargs)
222-
223210
224211class DeviceListConfigSerializer (BaseConfigSerializer ):
225212 config = serializers .JSONField (
@@ -286,10 +273,6 @@ class DeviceDetailConfigSerializer(BaseConfigSerializer):
286273 )
287274 templates = FilterTemplatesByOrganization (many = True )
288275
289- # def validate(self, *args, **kwargs):
290- # import ipdb; ipdb.set_trace()
291- # return super().validate(*args, **kwargs)
292-
293276
294277class DeviceDetailSerializer (DeviceConfigSerializer ):
295278 config = DeviceDetailConfigSerializer (allow_null = True )
@@ -316,10 +299,6 @@ class Meta(BaseMeta):
316299 'modified' ,
317300 ]
318301
319- # def to_internal_value(self, *args, **kwargs):
320- # import ipdb; ipdb.set_trace()
321- # return super().to_internal_value(*args, **kwargs)
322-
323302 def update (self , instance , validated_data ):
324303 config_data = validated_data .pop ('config' , {})
325304 raw_data_for_signal_handlers = {
0 commit comments