From 427cde380b554d49a99859661deac9309c6c559a Mon Sep 17 00:00:00 2001 From: Vitali Yanushchyk Date: Sun, 20 Oct 2024 11:59:41 -0300 Subject: [PATCH] add ! admin panel - process deduplication set --- .../apps/api/admin/deduplicationset.py | 17 ++++++++++++++++- .../apps/api/admin/duplicate.py | 6 +++--- src/hope_dedup_engine/apps/api/admin/image.py | 6 +++--- .../admin/api/deduplicationset/change_form.html | 8 ++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 src/hope_dedup_engine/web/templates/admin/api/deduplicationset/change_form.html diff --git a/src/hope_dedup_engine/apps/api/admin/deduplicationset.py b/src/hope_dedup_engine/apps/api/admin/deduplicationset.py index fd3761d1..494d3a2c 100644 --- a/src/hope_dedup_engine/apps/api/admin/deduplicationset.py +++ b/src/hope_dedup_engine/apps/api/admin/deduplicationset.py @@ -1,14 +1,19 @@ from django.contrib.admin import ModelAdmin, register +from django.http import HttpRequest, HttpResponseRedirect +from django.urls import reverse +from admin_extra_buttons.api import button +from admin_extra_buttons.mixins import ExtraButtonsMixin from adminfilters.dates import DateRangeFilter from adminfilters.filters import ChoicesFieldComboFilter, DjangoLookupFilter from adminfilters.mixin import AdminFiltersMixin from hope_dedup_engine.apps.api.models import DeduplicationSet +from hope_dedup_engine.apps.api.utils.process import start_processing @register(DeduplicationSet) -class DeduplicationSetAdmin(AdminFiltersMixin, ModelAdmin): +class DeduplicationSetAdmin(AdminFiltersMixin, ExtraButtonsMixin, ModelAdmin): list_display = ( "id", "name", @@ -35,6 +40,16 @@ class DeduplicationSetAdmin(AdminFiltersMixin, ModelAdmin): ("updated_at", DateRangeFilter), DjangoLookupFilter, ) + change_form_template = "admin/api/deduplicationset/change_form.html" def has_add_permission(self, request): return False + + @button(label="Process") + def process(self, request: HttpRequest, pk: str) -> HttpResponseRedirect: + dd = DeduplicationSet.objects.get(pk=pk) + start_processing(dd) + self.message_user( + request, f"Processing for deduplication set '{dd}' has been started." + ) + return HttpResponseRedirect(reverse("admin:api_deduplicationset_changelist")) diff --git a/src/hope_dedup_engine/apps/api/admin/duplicate.py b/src/hope_dedup_engine/apps/api/admin/duplicate.py index c6cfb641..4ab05214 100644 --- a/src/hope_dedup_engine/apps/api/admin/duplicate.py +++ b/src/hope_dedup_engine/apps/api/admin/duplicate.py @@ -28,8 +28,8 @@ class DuplicateAdmin(AdminFiltersMixin, ModelAdmin): def has_add_permission(self, request): return False - def has_delete_permission(self, request, obj=None): - return False - def has_change_permission(self, request, obj=None): return False + + def has_delete_permission(self, request, obj=None): + return obj is not None diff --git a/src/hope_dedup_engine/apps/api/admin/image.py b/src/hope_dedup_engine/apps/api/admin/image.py index cc9b1afa..8b721863 100644 --- a/src/hope_dedup_engine/apps/api/admin/image.py +++ b/src/hope_dedup_engine/apps/api/admin/image.py @@ -25,8 +25,8 @@ class ImageAdmin(AdminFiltersMixin, ModelAdmin): def has_add_permission(self, request): return False - def has_delete_permission(self, request, obj=None): - return False - def has_change_permission(self, request, obj=None): return False + + def has_delete_permission(self, request, obj=None): + return obj is not None diff --git a/src/hope_dedup_engine/web/templates/admin/api/deduplicationset/change_form.html b/src/hope_dedup_engine/web/templates/admin/api/deduplicationset/change_form.html new file mode 100644 index 00000000..acd63c38 --- /dev/null +++ b/src/hope_dedup_engine/web/templates/admin/api/deduplicationset/change_form.html @@ -0,0 +1,8 @@ +{% extends "admin/change_form.html" %} + +{% block object-tools-items %} + {{ block.super }} + {% include "admin_extra_buttons/includes/change_form_buttons.html" %} +{% endblock %} + +{% block pagination %}{% endblock %}