2023-01-24 21:21:26 -05:00
|
|
|
from django.contrib import admin
|
|
|
|
|
2023-11-08 12:37:06 -05:00
|
|
|
from django_object_actions import DjangoObjectActions, action
|
|
|
|
|
2024-02-23 15:55:16 -05:00
|
|
|
from .forms import AttributeScheduleRuleForm, DoorAdminForm
|
2024-12-09 13:31:50 -05:00
|
|
|
from .models import (
|
|
|
|
ActiveEventInstructorRule,
|
|
|
|
AttributeScheduleRule,
|
|
|
|
Door,
|
|
|
|
FlagScheduleRule,
|
|
|
|
HIDEvent,
|
|
|
|
Schedule,
|
|
|
|
)
|
2023-11-08 12:37:06 -05:00
|
|
|
from .tasks.scrapehidevents import q_getMessagesAllDoors
|
2023-09-19 01:06:24 -04:00
|
|
|
|
|
|
|
|
2024-02-23 15:55:16 -05:00
|
|
|
class FlagScheduleRuleInline(admin.TabularInline):
|
|
|
|
model = FlagScheduleRule
|
|
|
|
autocomplete_fields = ["flag"]
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
|
|
|
class AttributeScheduleRuleInline(admin.TabularInline):
|
|
|
|
model = AttributeScheduleRule
|
|
|
|
form = AttributeScheduleRuleForm
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
2024-12-09 13:31:50 -05:00
|
|
|
class ActiveEventInstructorRuleInline(admin.TabularInline):
|
|
|
|
model = ActiveEventInstructorRule
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
2024-02-23 15:55:16 -05:00
|
|
|
@admin.register(Schedule)
|
|
|
|
class ScheduleAdmin(admin.ModelAdmin):
|
2024-12-09 13:31:50 -05:00
|
|
|
inlines = [
|
|
|
|
FlagScheduleRuleInline,
|
|
|
|
AttributeScheduleRuleInline,
|
|
|
|
ActiveEventInstructorRuleInline,
|
|
|
|
]
|
2024-02-23 15:55:16 -05:00
|
|
|
|
|
|
|
|
2023-09-19 01:06:24 -04:00
|
|
|
@admin.register(Door)
|
|
|
|
class DoorAdmin(admin.ModelAdmin):
|
2024-02-23 15:55:16 -05:00
|
|
|
form = DoorAdminForm
|
|
|
|
list_display = ["name", "access_field"]
|
2023-01-24 21:21:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(HIDEvent)
|
2023-11-08 12:37:06 -05:00
|
|
|
class HIDEventAdmin(DjangoObjectActions, admin.ModelAdmin):
|
2023-04-03 17:17:47 -04:00
|
|
|
search_fields = ["forename", "surname", "cardholder_id"]
|
2023-12-29 18:19:58 -05:00
|
|
|
date_hierarchy = "timestamp"
|
2023-12-04 12:01:12 -05:00
|
|
|
list_display = ["timestamp", "door", "event_type", "description", "_is_red"]
|
2023-04-03 17:16:48 -04:00
|
|
|
list_filter = [
|
2023-04-03 21:30:15 -04:00
|
|
|
"timestamp",
|
2023-09-19 01:06:24 -04:00
|
|
|
"door",
|
2023-04-03 17:16:48 -04:00
|
|
|
"event_type",
|
2023-12-04 12:01:12 -05:00
|
|
|
"is_red",
|
2023-04-03 17:16:48 -04:00
|
|
|
]
|
2023-04-03 23:15:12 -04:00
|
|
|
readonly_fields = ["decoded_card_number"]
|
2023-11-08 12:37:06 -05:00
|
|
|
changelist_actions = ("refresh_all_doors",)
|
2023-04-03 17:16:48 -04:00
|
|
|
|
|
|
|
@admin.display(boolean=True)
|
2023-12-04 12:01:12 -05:00
|
|
|
def _is_red(self, obj):
|
2023-04-03 17:16:48 -04:00
|
|
|
return obj.is_red
|
2023-01-24 21:21:26 -05:00
|
|
|
|
|
|
|
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
|
2023-11-08 12:37:06 -05:00
|
|
|
|
|
|
|
@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",
|
|
|
|
)
|