Skip to content

Commit

Permalink
Add resubmit face detection photos to admin menu. (#3382)
Browse files Browse the repository at this point in the history
* Add resubmit face detection photos to admin menu.

* Add action to ReferenceFaceAdmin

* Apply suggestions from code review

---------

Co-authored-by: Dirk Doesburg <[email protected]>
  • Loading branch information
tvanonna and DeD1rk authored Oct 6, 2023
1 parent 6ae1f01 commit 0b30ea3
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion website/facedetection/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.contrib import admin
from django.contrib import admin, messages
from django.db.models.query import Prefetch
from django.urls import reverse
from django.utils.html import format_html
from django.utils.safestring import mark_safe

from facedetection.services import trigger_facedetection_lambda

from .models import (
FaceDetectionPhoto,
PhotoFaceEncoding,
Expand Down Expand Up @@ -44,11 +46,25 @@ class ReferenceFaceAdmin(admin.ModelAdmin):
list_filter = ["status", "marked_for_deletion_at"]
inlines = [ReferenceFaceEncodingInline]

actions = ["resubmit_reference_faces"]

def get_readonly_fields(self, request, obj=None):
if obj is None:
return ["created_at", "submitted_at", "status"]
return ["file", "user", "created_at", "submitted_at", "status"]

@admin.action(description="Resubmit reference faces for analysis.")
def resubmit_reference_faces(self, request, queryset) -> list[ReferenceFace]:
querylist = list(
queryset.filter(
status=FaceDetectionPhoto.Status.PROCESSING,
)
)
if querylist:
trigger_facedetection_lambda(querylist)
messages.success(request, "Resubmit successful.")
return querylist


class PhotoFaceEncodingInline(admin.TabularInline):
model = PhotoFaceEncoding
Expand Down Expand Up @@ -120,6 +136,8 @@ class FaceDetectionPhotoAdmin(admin.ModelAdmin):
list_filter = ["status", "submitted_at"]
inlines = [PhotoFaceEncodingInline]

actions = ["resubmit_face_detection_photos"]

def get_queryset(self, request):
return (
super()
Expand All @@ -131,3 +149,17 @@ def get_queryset(self, request):

def has_add_permission(self, request):
return False

@admin.action(description="Resubmits face detection photos for analysis.")
def resubmit_face_detection_photos(
self, request, queryset
) -> list[FaceDetectionPhoto]:
querylist = list(
queryset.filter(
status=FaceDetectionPhoto.Status.PROCESSING,
)
)
if querylist:
trigger_facedetection_lambda(querylist)
messages.success(request, "Resubmit successful.")
return querylist

0 comments on commit 0b30ea3

Please sign in to comment.