doorcontrol: Add action to Events admin to update all doors' events
This commit is contained in:
parent
96bcc80516
commit
7f0de3a16f
@ -30,6 +30,7 @@ INSTALLED_APPS = [
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django_admin_logs",
|
||||
"django_object_actions",
|
||||
"widget_tweaks",
|
||||
"markdownx",
|
||||
"recurrence",
|
||||
|
@ -1,6 +1,9 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from django_object_actions import DjangoObjectActions, action
|
||||
|
||||
from .models import Door, HIDEvent
|
||||
from .tasks.scrapehidevents import q_getMessagesAllDoors
|
||||
|
||||
|
||||
@admin.register(Door)
|
||||
@ -26,7 +29,7 @@ class IsRedFilter(admin.SimpleListFilter):
|
||||
|
||||
|
||||
@admin.register(HIDEvent)
|
||||
class HIDEventAdmin(admin.ModelAdmin):
|
||||
class HIDEventAdmin(DjangoObjectActions, admin.ModelAdmin):
|
||||
search_fields = ["forename", "surname", "cardholder_id"]
|
||||
list_display = ["timestamp", "door", "event_type", "description", "is_red"]
|
||||
list_filter = [
|
||||
@ -36,6 +39,7 @@ class HIDEventAdmin(admin.ModelAdmin):
|
||||
IsRedFilter,
|
||||
]
|
||||
readonly_fields = ["decoded_card_number"]
|
||||
changelist_actions = ("refresh_all_doors",)
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super().get_queryset(request).with_is_red().with_decoded_card_number()
|
||||
@ -52,3 +56,11 @@ class HIDEventAdmin(admin.ModelAdmin):
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
@action(label="Refresh All Doors")
|
||||
def refresh_all_doors(self, request, obj):
|
||||
q_getMessagesAllDoors()
|
||||
self.message_user(
|
||||
request,
|
||||
"Queued refresh, please wait a few seconds/minutes then refresh the page",
|
||||
)
|
||||
|
12
pdm.lock
12
pdm.lock
@ -5,7 +5,7 @@
|
||||
groups = ["default", "debug", "lint", "server", "typing"]
|
||||
strategy = ["cross_platform"]
|
||||
lock_version = "4.4"
|
||||
content_hash = "sha256:22f2fbe3d0a5c19621ffbd542f27ba8755345d4a427b541285c22d09e752f7c3"
|
||||
content_hash = "sha256:1e499716802e3248651a1d73c4f13251343cec8b019df0f34ffb12e83ec11e95"
|
||||
|
||||
[[package]]
|
||||
name = "asgiref"
|
||||
@ -354,6 +354,16 @@ files = [
|
||||
{file = "django_markdownx-4.0.2-py2.py3-none-any.whl", hash = "sha256:2fed9b6bbac798a6c24ba30e17ad775fab44f94774c820abd87aabc751f50a7e"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "django-object-actions"
|
||||
version = "4.2.0"
|
||||
requires_python = ">=3.7,<4.0"
|
||||
summary = "A Django app for adding object tools for models in the admin"
|
||||
files = [
|
||||
{file = "django_object_actions-4.2.0-py3-none-any.whl", hash = "sha256:ae0df9984c68a4f42f219a391b71fa0630fe44a2983b39b8064378ebddcff30c"},
|
||||
{file = "django_object_actions-4.2.0.tar.gz", hash = "sha256:e24befedf01b6fcdccbb03c33c0e2c855fd1a88f352a66dc7e2170ba31e80128"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "django-picklefield"
|
||||
version = "3.1"
|
||||
|
@ -25,6 +25,7 @@ dependencies = [
|
||||
"djangorestframework~=3.14",
|
||||
"django-q2~=1.5",
|
||||
"lxml~=4.9",
|
||||
"django-object-actions~=4.2",
|
||||
]
|
||||
requires-python = ">=3.9"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user