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

add ! admin panel - process deduplication set #101

Merged
merged 1 commit into from
Oct 21, 2024
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
17 changes: 16 additions & 1 deletion src/hope_dedup_engine/apps/api/admin/deduplicationset.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"))
6 changes: 3 additions & 3 deletions src/hope_dedup_engine/apps/api/admin/duplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/hope_dedup_engine/apps/api/admin/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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 %}
Loading