|
46 | 46 | PartijIdentificatorTypesValidator,
|
47 | 47 | PartijIdentificatorUniquenessValidator,
|
48 | 48 | )
|
| 49 | +from openklant.utils.decorators import handle_db_exceptions |
49 | 50 | from openklant.utils.serializers import get_field_instance_by_uuid, get_field_value
|
50 | 51 |
|
51 | 52 |
|
@@ -371,10 +372,7 @@ class Meta:
|
371 | 372 | "code_soort_object_id": {"required": True},
|
372 | 373 | "object_id": {"required": True},
|
373 | 374 | }
|
374 |
| - |
375 |
| - def validate(self, attrs): |
376 |
| - PartijIdentificatorTypesValidator(partij_identificator=attrs)() |
377 |
| - return super().validate(attrs) |
| 375 | + validators = [] |
378 | 376 |
|
379 | 377 |
|
380 | 378 | class PartijIdentificatorSerializer(
|
@@ -420,26 +418,40 @@ class Meta:
|
420 | 418 | }
|
421 | 419 |
|
422 | 420 | def validate(self, attrs):
|
423 |
| - instance = getattr(self, "instance", None) |
424 | 421 | partij_identificator = get_field_value(self, attrs, "partij_identificator")
|
425 |
| - |
426 | 422 | sub_identificator_van = get_field_instance_by_uuid(
|
427 | 423 | self, attrs, "sub_identificator_van", PartijIdentificator
|
428 | 424 | )
|
429 |
| - partij = get_field_instance_by_uuid(self, attrs, "partij", Partij) |
430 |
| - |
| 425 | + PartijIdentificatorTypesValidator()(partij_identificator) |
431 | 426 | PartijIdentificatorUniquenessValidator(
|
432 |
| - instance=instance, |
433 |
| - partij_identificator=partij_identificator, |
| 427 | + code_soort_object_id=partij_identificator["code_soort_object_id"], |
434 | 428 | sub_identificator_van=sub_identificator_van,
|
435 |
| - partij=partij, |
436 | 429 | )()
|
| 430 | + return super().validate(attrs) |
437 | 431 |
|
438 |
| - attrs["sub_identificator_van"] = get_field_instance_by_uuid( |
439 |
| - self, attrs, "sub_identificator_van", PartijIdentificator |
| 432 | + @handle_db_exceptions |
| 433 | + @transaction.atomic |
| 434 | + def update(self, instance, validated_data): |
| 435 | + validated_data["sub_identificator_van"] = get_field_instance_by_uuid( |
| 436 | + self, validated_data, "sub_identificator_van", PartijIdentificator |
440 | 437 | )
|
441 |
| - attrs["partij"] = get_field_instance_by_uuid(self, attrs, "partij", Partij) |
442 |
| - return super().validate(attrs) |
| 438 | + validated_data["partij"] = get_field_instance_by_uuid( |
| 439 | + self, validated_data, "partij", Partij |
| 440 | + ) |
| 441 | + |
| 442 | + return super().update(instance, validated_data) |
| 443 | + |
| 444 | + @handle_db_exceptions |
| 445 | + @transaction.atomic |
| 446 | + def create(self, validated_data): |
| 447 | + validated_data["sub_identificator_van"] = get_field_instance_by_uuid( |
| 448 | + self, validated_data, "sub_identificator_van", PartijIdentificator |
| 449 | + ) |
| 450 | + validated_data["partij"] = get_field_instance_by_uuid( |
| 451 | + self, validated_data, "partij", Partij |
| 452 | + ) |
| 453 | + |
| 454 | + return super().create(validated_data) |
443 | 455 |
|
444 | 456 |
|
445 | 457 | class PartijSerializer(NestedGegevensGroepMixin, PolymorphicSerializer):
|
|
0 commit comments