Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/manual/migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Before updating to 4.0.0 all objecttypes from the ObjectTypes API instance need
This command will fetch all objecttypes and their versions from an objecttype service based on its identifier/slug (which can be found in the admin interface under ``Configuration > Services``)
and update existing objecttypes or create new ones if they have not been added to the objecttypes API.

.. note::

The minimum version of the Objecttypes API application required for this command is
3.4.0

.. code-block:: bash

src/manage.py import_objecttypes objecttypes-api
Expand Down
9 changes: 7 additions & 2 deletions src/objects/core/management/commands/import_objecttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from objects.core.models import ObjectType, ObjectTypeVersion
from objects.utils.client import get_objecttypes_client

MIN_OBJECTTYPES_VERSION = "3.4.0" # added boolean field linkable_to_zaken to ObjectType
# Minimum Objecttypes application version is 3.4.0, because that version added the
# version header to the responses
MIN_OBJECTTYPES_VERSION = "2.2.2"


class Command(BaseCommand):
Expand Down Expand Up @@ -85,6 +87,7 @@ def _bulk_create_or_update_objecttypes(self, data):
], # TODO remove service from unique_fields after objecttype migration since it will no longer be part of the ObjectType model.
update_fields=[
"is_imported",
"_name",
"name",
"name_plural",
"description",
Expand All @@ -101,7 +104,6 @@ def _bulk_create_or_update_objecttypes(self, data):
"created_at",
"modified_at",
"allow_geometry",
"linkable_to_zaken",
],
)

Expand Down Expand Up @@ -129,8 +131,11 @@ def _parse_objecttype_data(
for objecttype in objecttypes:
objecttype.pop("versions")
objecttype.pop("url")
# This attribute was added in 3.4.0 but removed in 3.4.1
objecttype.pop("linkableToZaken", None)
objecttype["service"] = service
objecttype["is_imported"] = True
objecttype["_name"] = objecttype["name"]
data.append(ObjectType(**underscoreize(objecttype)))
return data

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.2.8 on 2026-01-27 13:01

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0037_reference'),
]

operations = [
migrations.RemoveField(
model_name='objecttype',
name='linkable_to_zaken',
),
]
13 changes: 1 addition & 12 deletions src/objects/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,14 @@ class ObjectType(models.Model):
"`geometry` property will raise an error "
),
)
linkable_to_zaken = models.BooleanField(
_("linkable to zaken"),
default=False,
help_text=_(
# TODO Document: how and where these links should be created/maintained
"Objects of this type can have a link to 1 or more Zaken.\n"
"True indicates the lifetime of the object is linked to the lifetime "
"of linked zaken, i.e., when all linked Zaken to an object are "
"archived/destroyed, the object will also be archived/destroyed."
),
)

objects = ObjectTypeQuerySet.as_manager()

class Meta:
unique_together = ("service", "uuid")

def __str__(self):
return f"{self.service.label}: {self._name}"
return f"{self.service.label}: {self.name or self._name}"

@property
def url(self):
Expand Down
2 changes: 1 addition & 1 deletion src/objects/core/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
class ObjectTypeFactory(factory.django.DjangoModelFactory[ObjectType]):
service = factory.SubFactory(ServiceFactory)
uuid = factory.LazyFunction(uuid.uuid4)
_name = factory.Faker("word")

name = factory.Faker("word")
_name = factory.LazyAttribute(lambda x: x.name)
name_plural = factory.LazyAttribute(lambda x: f"{x.name}s")
description = factory.Faker("bs")

Expand Down
9 changes: 5 additions & 4 deletions src/objects/core/tests/test_import_objecttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def test_api_version_is_required(self):
self.m.head(self.url, status_code=200)

with self.assertRaisesMessage(
CommandError, "API version must be 3.4.0 or higher"
CommandError, "API version must be 2.2.2 or higher"
):
self._call_command()

def test_api_version_must_be_greater_than_constant(self):
self.m.head(self.url, status_code=200, headers={"api-version": "3.2.0"})
self.m.head(self.url, status_code=200, headers={"api-version": "2.1.0"})

with self.assertRaisesMessage(
CommandError, "API version must be 3.4.0 or higher"
CommandError, "API version must be 2.2.2 or higher"
):
self._call_command()

Expand Down Expand Up @@ -76,6 +76,7 @@ def test_new_objecttypes_are_created(self):
objecttype = ObjectType.objects.get(uuid=uuid1)
self.assertEqual(objecttype.is_imported, True)
self.assertEqual(objecttype.name, "Melding")
self.assertEqual(objecttype._name, "Melding")
self.assertEqual(objecttype.name_plural, "Meldingen")
self.assertEqual(objecttype.description, "")
self.assertEqual(objecttype.data_classification, "intern")
Expand All @@ -88,7 +89,6 @@ def test_new_objecttypes_are_created(self):
self.assertEqual(objecttype.provider_organization, "")
self.assertEqual(objecttype.documentation_url, "")
self.assertEqual(objecttype.labels, {})
self.assertEqual(objecttype.linkable_to_zaken, False)
self.assertEqual(str(objecttype.created_at), "2020-12-01")
self.assertEqual(str(objecttype.modified_at), "2020-12-01")
self.assertEqual(objecttype.allow_geometry, True)
Expand Down Expand Up @@ -140,6 +140,7 @@ def test_existing_objecttypes_are_updated(self):
objecttype = ObjectType.objects.get(uuid=objecttype1.uuid)
self.assertEqual(objecttype.is_imported, True)
self.assertEqual(objecttype.name, "Melding")
self.assertEqual(objecttype._name, "Melding")

version = ObjectTypeVersion.objects.get(object_type=objecttype, version=1)
self.assertEqual(
Expand Down
3 changes: 2 additions & 1 deletion src/objects/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def mock_objecttypes(uuid1, uuid2):
"providerOrganization": "",
"documentationUrl": "",
"labels": {},
"linkableToZaken": False,
"createdAt": "2020-12-01",
"modifiedAt": "2020-12-01",
"allowGeometry": True,
Expand All @@ -102,6 +101,8 @@ def mock_objecttypes(uuid1, uuid2):
"providerOrganization": "",
"documentationUrl": "",
"labels": {},
# command should be able to handle Objecttypes 3.4.0, which includes
# this attribute
"linkableToZaken": False,
"createdAt": "2020-12-01",
"modifiedAt": "2020-12-01",
Expand Down
Loading