From 517c8d42608943604d4d9cf01f93e764f7636005 Mon Sep 17 00:00:00 2001 From: bart-maykin Date: Thu, 25 Apr 2024 12:03:39 +0200 Subject: [PATCH] :art: [#315] removed custom version field and added uuid fields --- src/objects/core/admin.py | 29 +++++++++++++++++++++-------- src/objects/core/models.py | 11 ----------- src/objects/token/admin.py | 32 +++++--------------------------- 3 files changed, 26 insertions(+), 46 deletions(-) diff --git a/src/objects/core/admin.py b/src/objects/core/admin.py index 74d70823..57cb47a6 100644 --- a/src/objects/core/admin.py +++ b/src/objects/core/admin.py @@ -7,12 +7,11 @@ @admin.register(ObjectType) class ObjectTypeAdmin(admin.ModelAdmin): - list_display = ("_name", "uuid", "get_version") - readonly_fields = ("_name", "get_version") - - def get_version(self, obj): - if obj: - return obj.version + list_display = ( + "_name", + "uuid", + ) + readonly_fields = ("_name",) class ObjectRecordInline(admin.TabularInline): @@ -57,15 +56,29 @@ def get_corrected_by(self, obj): @admin.register(Object) class ObjectAdmin(admin.ModelAdmin): - list_display = ("id", "object_type", "current_record") + list_display = ( + "id", + "object_type", + "current_record", + "uuid", + "get_object_type_uuid", + ) search_fields = ("uuid", "records__data") inlines = (ObjectRecordInline,) list_filter = ("object_type",) + @admin.display(description="Object type UUID") + def get_object_type_uuid(self, obj): + return obj.object_type.uuid + def get_readonly_fields(self, request, obj=None): readonly_fields = super().get_readonly_fields(request, obj) if obj: - readonly_fields = ("uuid", "object_type") + readonly_fields + readonly_fields = ( + "uuid", + "get_object_type_uuid", + "object_type", + ) + readonly_fields return readonly_fields diff --git a/src/objects/core/models.py b/src/objects/core/models.py index 93835da6..8cf1255d 100644 --- a/src/objects/core/models.py +++ b/src/objects/core/models.py @@ -40,17 +40,6 @@ def url(self): # zds_client.get_operation_url() can be used here but it increases HTTP overhead return f"{self.service.api_root}objecttypes/{self.uuid}" - @property - def version(self): - client = self.service.build_client() - try: - object_type_data = client.retrieve("objecttype", url=self.url) - except (ClientError, ConnectionError, ValueError) as exc: - return None - - if recent_version := object_type_data["versions"][-1]: - return recent_version.split("/versions/")[-1] - def clean(self): client = self.service.build_client() try: diff --git a/src/objects/token/admin.py b/src/objects/token/admin.py index 0780aa9f..ac96058e 100644 --- a/src/objects/token/admin.py +++ b/src/objects/token/admin.py @@ -20,24 +20,12 @@ class PermissionAdmin(admin.ModelAdmin): "mode", "use_fields", "get_uuid", - "get_version", - ) - readonly_fields = ( - "get_uuid", - "get_version", ) + readonly_fields = ("get_uuid",) + @admin.display(description="Object type UUID") def get_uuid(self, obj): - if obj: - return obj.object_type.uuid - - def get_version(self, obj): - if obj: - if object_type := obj.object_type: - return object_type.version - - get_version.short_description = "Version" - get_uuid.short_description = "UUID" + return obj.object_type.uuid def get_object_fields(self): object_serializer = ObjectSerializer() @@ -133,21 +121,11 @@ class PermissionInline(EditInlineAdminMixin, admin.TabularInline): "use_fields", "fields", "get_uuid", - "get_version", ) + @admin.display(description="Object type UUID") def get_uuid(self, obj): - if obj: - if object_type := obj.object_type: - return object_type.uuid - - def get_version(self, obj): - if obj: - if object_type := obj.object_type: - return object_type.version - - get_version.short_description = "Version" - get_uuid.short_description = "UUID" + return obj.object_type.uuid @admin.register(TokenAuth)