Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#315] Display UUID and version of any object type in the admin interface #332

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion src/objects/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
1 change: 0 additions & 1 deletion src/objects/accounts/migrations/0002_auto_20201012_1522.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("accounts", "0001_initial"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/accounts/migrations/0003_auto_20201223_1231.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("accounts", "0002_auto_20201012_1522"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/api/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def __call__(self, attrs):
try:
response = client.retrieve("objecttype", url=object_type.url)
except ClientError as exc:

msg = f"Object type can not be retrieved: {exc.args[0]}"
raise ValidationError(msg)

Expand Down
1 change: 1 addition & 0 deletions src/objects/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@admin.register(ObjectType)
class ObjectTypeAdmin(admin.ModelAdmin):
list_display = ("_name", "uuid", "_version")
readonly_fields = ("_name",)


Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0002_auto_20200518_1707.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0001_initial"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0003_objectrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0002_auto_20200518_1707"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0004_move_data_to_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def move_data_from_record(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0003_objectrecord"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0005_remove_object_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0004_move_data_to_record"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0006_auto_20200904_1402.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0005_remove_object_data"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0007_auto_20200904_1403.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0006_auto_20200904_1402"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0008_objectrecord_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0007_auto_20200904_1403"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0009_objectrecord_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0008_objectrecord_correct"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0010_move_version_to_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def move_version_from_record(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0009_objectrecord_version"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0011_remove_object_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0010_move_version_to_record"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0012_objectrecord_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0011_remove_object_version"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0013_generate_record_uuids.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def generate_record_uuids(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0012_objectrecord_uuid"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0014_auto_20200915_1740.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0013_generate_record_uuids"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0015_objectrecord_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0014_auto_20200915_1740"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0016_auto_20210111_1649.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0015_objectrecord_geometry"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0017_auto_20210111_1653.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0016_auto_20210111_1649"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0018_auto_20210113_1239.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0017_auto_20210111_1653"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0019_fill_record_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def fill_record_index(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0018_auto_20210113_1239"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0020_auto_20210118_1117.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0019_fill_record_index"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0021_auto_20201222_1745.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("zgw_consumers", "0011_remove_service_extra"),
("core", "0020_auto_20210118_1117"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def move_objecttypes_from_model(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0021_auto_20201222_1745"),
("zgw_consumers", "0011_remove_service_extra"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0022_move_object_types_to_separate_model"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0024_auto_20201222_1811.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0023_remove_object_object_type"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def remove_objects_with_empty_object_type(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0024_auto_20201222_1811"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0026_auto_20201222_1833.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0025_delete_objects_with_empty_object_type"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0027_auto_20211203_1209.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0026_auto_20201222_1833"),
]
Expand Down
21 changes: 21 additions & 0 deletions src/objects/core/migrations/0028_objecttype__version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.2.28 on 2023-06-06 10:21

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0027_auto_20211203_1209"),
]

operations = [
migrations.AddField(
model_name="objecttype",
name="_version",
field=models.IntegerField(
blank=True,
help_text="Cached version of the objecttype retrieved from the Objecttype API",
null=True,
),
),
]
10 changes: 10 additions & 0 deletions src/objects/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class ObjectType(models.Model):
max_length=100,
help_text=_("Cached name of the objecttype retrieved from the Objecttype API"),
)
_version = models.IntegerField(
help_text=_(
"Cached version of the objecttype retrieved from the Objecttype API"
),
null=True,
blank=True,
)

objects = ObjectTypeQuerySet.as_manager()

Expand All @@ -51,6 +58,9 @@ def clean(self):
if not self._name:
self._name = object_type_data["name"]

if not self._version:
self._version = object_type_data["version"]


class Object(models.Model):
uuid = models.UUIDField(
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def check_objecttype(object_type, version, data):
try:
response = client.retrieve("objectversion", url=objecttype_version_url)
except ClientError as exc:

msg = f"Object type version can not be retrieved: {exc.args[0]}"
raise ValidationError(msg)

Expand Down
38 changes: 35 additions & 3 deletions src/objects/token/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.admin.utils import unquote

from objects.api.serializers import ObjectSerializer
from objects.core.models import ObjectType
from objects.core.models import ObjectRecord, ObjectType
from objects.utils.admin import EditInlineAdminMixin
from objects.utils.serializers import build_spec, get_field_names

Expand All @@ -14,7 +14,23 @@

@admin.register(Permission)
class PermissionAdmin(admin.ModelAdmin):
list_display = ("token_auth", "object_type", "mode", "use_fields")
list_display = (
"token_auth",
"object_type",
"get_uuid",
"get_version",
"mode",
"use_fields",
)

def get_uuid(self, obj):
return obj.object_type.uuid

def get_version(self, obj):
return obj.object_type._version

get_version.short_description = "Version"
get_uuid.short_description = "UUID"

def get_object_fields(self):
object_serializer = ObjectSerializer()
Expand Down Expand Up @@ -104,7 +120,23 @@ def add_view(self, request, form_url="", extra_context=None):
class PermissionInline(EditInlineAdminMixin, admin.TabularInline):
model = Permission
fk_name = "token_auth"
fields = ("object_type", "mode", "use_fields", "fields")
fields = (
"object_type",
"get_uuid",
"get_version",
"mode",
"use_fields",
"fields",
)

def get_uuid(self, obj):
return obj.object_type.uuid

def get_version(self, obj):
return obj.object_type._version

get_version.short_description = "Version"
get_uuid.short_description = "UUID"


@admin.register(TokenAuth)
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0002_auto_20201223_1231.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0026_auto_20201222_1833"),
("token", "0001_initial"),
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0003_auto_20210312_1507.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("token", "0002_auto_20201223_1231"),
]
Expand Down
Loading