Skip to content

Commit

Permalink
🎨 [#183] removed un-needed update/create serialzier code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-maykin committed Apr 30, 2024
1 parent d02cf9b commit 2199b1a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ class InterneTaakAdmin(admin.ModelAdmin):
"actor",
"status",
)
readonly_fields = ("toegewezen_op",)
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import transaction
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from rest_framework import serializers
Expand Down Expand Up @@ -76,7 +75,7 @@ def validate(self, attrs):
if not status and self.instance:
status = self.instance.status

if attrs.get("afgehandeld_op") and status == Taakstatus.te_verwerken.value:
if attrs.get("afgehandeld_op") and status != Taakstatus.verwerkt:
raise serializers.ValidationError(
{
"afgehandeld_op": _(
Expand All @@ -92,22 +91,16 @@ def validate(self, attrs):
def create(self, validated_data):
actor_uuid = str(validated_data.pop("actor").get("uuid"))
klantcontact_uuid = str(validated_data.pop("klantcontact").get("uuid"))
afgehandeld_op = validated_data.pop("afgehandeld_op", timezone.now())

validated_data["actor"] = Actor.objects.get(uuid=actor_uuid)
validated_data["klantcontact"] = Klantcontact.objects.get(
uuid=klantcontact_uuid
)

if validated_data.get("status") == Taakstatus.verwerkt:
validated_data["afgehandeld_op"] = afgehandeld_op

return super().create(validated_data)

@transaction.atomic
def update(self, instance, validated_data):
afgehandeld_op = validated_data.pop("afgehandeld_op", timezone.now())

if "actor" in validated_data:
if actor := validated_data.pop("actor", None):
validated_data["actor"] = Actor.objects.get(uuid=str(actor.get("uuid")))
Expand All @@ -118,18 +111,6 @@ def update(self, instance, validated_data):
uuid=str(klantcontact.get("uuid"))
)

if (
not self.instance.afgehandeld_op
and validated_data.get("status") == Taakstatus.verwerkt
):
validated_data["afgehandeld_op"] = afgehandeld_op

if (
self.instance.afgehandeld_op
and validated_data.get("status") == Taakstatus.te_verwerken
):
validated_data["afgehandeld_op"] = None

return super().update(instance, validated_data)


Expand Down

0 comments on commit 2199b1a

Please sign in to comment.