Skip to content

Commit

Permalink
🎨 [#76] change the vanaf fields default value from datetime.now() to …
Browse files Browse the repository at this point in the history
…registratiedatum which will be filed in by the model save method
  • Loading branch information
bart-maykin committed Nov 13, 2024
1 parent d1f131a commit 67d86b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 4.2.16 on 2024-11-13 12:13

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):
Expand All @@ -28,8 +27,9 @@ class Migration(migrations.Migration):
model_name="document",
name="vanaf",
field=models.DateTimeField(
default=django.utils.timezone.now,
blank=True,
help_text="System timestamp reflecting when the action will be active.",
null=True,
verbose_name="at time",
),
),
Expand Down
14 changes: 11 additions & 3 deletions src/woo_publications/publications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ class Document(models.Model):
vanaf = models.DateTimeField(
_("at time"),
help_text=_("System timestamp reflecting when the action will be active."),
default=timezone.now,
null=True,
blank=True,
)

# Documents API integration
Expand Down Expand Up @@ -334,6 +335,14 @@ def clean(self):
)
)

def save(self, *args, **kwargs) -> None:
if not self.vanaf:
if not self.registratiedatum:
self.registratiedatum = timezone.now()
self.vanaf = self.registratiedatum

super().save(*args, **kwargs)

@property
def documenthandelingen(self) -> document_actions:
"""
Expand All @@ -354,11 +363,10 @@ def documenthandelingen(self, value: document_actions) -> None:
"""
assert len(value) == 1
documenthandeling = value[0]

assert documenthandeling["soort_handeling"]
assert documenthandeling["vanaf"]

self.soort_handeling = documenthandeling["soort_handeling"]
# if vanaf is none then the save method will fill in the data based off the registratiedatum
self.vanaf = documenthandeling["vanaf"]

@property
Expand Down
6 changes: 4 additions & 2 deletions src/woo_publications/publications/typing.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from typing import TypedDict

from django.db.models import DateTimeField, ForeignKey
from django.db.models import ForeignKey

from black import datetime

from woo_publications.metadata.models import Organisation
from woo_publications.publications.constants import DocumentActionTypeOptions


class DocumentAction(TypedDict):
soort_handeling: DocumentActionTypeOptions
vanaf: DateTimeField
vanaf: datetime
was_geassocieerd_met: ForeignKey[Organisation] | None


Expand Down

0 comments on commit 67d86b1

Please sign in to comment.