51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
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)
|
|
class DoorAdmin(admin.ModelAdmin):
|
|
pass
|
|
|
|
|
|
@admin.register(HIDEvent)
|
|
class HIDEventAdmin(DjangoObjectActions, admin.ModelAdmin):
|
|
search_fields = ["forename", "surname", "cardholder_id"]
|
|
date_hierarchy = "timestamp"
|
|
list_display = ["timestamp", "door", "event_type", "description", "_is_red"]
|
|
list_filter = [
|
|
"timestamp",
|
|
"door",
|
|
"event_type",
|
|
"is_red",
|
|
]
|
|
readonly_fields = ["decoded_card_number"]
|
|
changelist_actions = ("refresh_all_doors",)
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).with_decoded_card_number()
|
|
|
|
@admin.display(boolean=True)
|
|
def _is_red(self, obj):
|
|
return obj.is_red
|
|
|
|
def has_add_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 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",
|
|
)
|