70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
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",)
|
|
|
|
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",
|
|
)
|