cmsmanage/doorcontrol/admin.py

67 lines
1.8 KiB
Python
Raw Permalink Normal View History

from django.contrib import admin
from django_object_actions import DjangoObjectActions, action
from .forms import AttributeScheduleRuleForm, DoorAdminForm
from .models import AttributeScheduleRule, Door, FlagScheduleRule, HIDEvent, Schedule
from .tasks.scrapehidevents import q_getMessagesAllDoors
class FlagScheduleRuleInline(admin.TabularInline):
model = FlagScheduleRule
autocomplete_fields = ["flag"]
extra = 0
class AttributeScheduleRuleInline(admin.TabularInline):
model = AttributeScheduleRule
form = AttributeScheduleRuleForm
extra = 0
@admin.register(Schedule)
class ScheduleAdmin(admin.ModelAdmin):
inlines = [FlagScheduleRuleInline, AttributeScheduleRuleInline]
@admin.register(Door)
class DoorAdmin(admin.ModelAdmin):
form = DoorAdminForm
list_display = ["name", "access_field"]
@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",)
@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",
)