Skip to content

Commit

Permalink
🎨 [#315] removed custom version field and added uuid fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-maykin committed May 14, 2024
1 parent a93f1b3 commit 517c8d4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
29 changes: 21 additions & 8 deletions src/objects/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
11 changes: 0 additions & 11 deletions src/objects/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 5 additions & 27 deletions src/objects/token/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 517c8d4

Please sign in to comment.