Compare commits

..

No commits in common. "b582caebff772c6faf3a5c5fffbfbbcf66b0d562" and "bbd4d8d7003b80153d3486407f474491565bec1e" have entirely different histories.

2 changed files with 13 additions and 36 deletions

View File

@ -38,25 +38,6 @@
</div>
</div>
<div class="col-12 col-sm-auto dropdown d-grid">
<button type="button"
class="btn btn-outline-secondary btn-lg dropdown-toggle"
data-bs-toggle="dropdown"
data-bs-auto-close="outside"
aria-expanded="false">Doors</button>
<div class="dropdown-menu py-0">
<div class="dropdown-header">Use Ctrl/Shift to select multiple</div>
<select class="form-select"
aria-label="Door"
name="{{ filter.form.door.name }}"
id="id_door"
size="{{ filter.form.door.subwidgets|length }}"
multiple>
{% for widget in filter.form.door.subwidgets %}{{ widget }}{% endfor %}
</select>
</div>
</div>
<div class="col-12 col-sm-auto">
<div class="form-floating">
<input type="number"
@ -67,7 +48,6 @@
min="10"
max="200"
step="10"
size="10"
required>
<label for="itemsPerPage">Items Per Page</label>
</div>

View File

@ -16,7 +16,7 @@ from django_filters.views import BaseFilterView
from django_tables2 import SingleTableMixin
from django_tables2.export.views import ExportMixin
from .models import Door, HIDEvent
from .models import HIDEvent
REPORTS = []
@ -26,11 +26,8 @@ def register_report(cls: "BaseAccessReport"):
return cls
class AccessReportFilterSet(django_filters.FilterSet):
class DateTimeFilters(django_filters.FilterSet):
timestamp = django_filters.DateFromToRangeFilter()
door = django_filters.ModelMultipleChoiceFilter(
queryset=Door.objects.all(), distinct=False
)
class BaseAccessReport(
@ -44,7 +41,7 @@ class BaseAccessReport(
export_formats = ("csv", "xlsx", "ods")
filterset_class = AccessReportFilterSet
filterset_class = DateTimeFilters
_report_name = None
@ -165,7 +162,7 @@ class AccessPerUnitTime(BaseAccessReport):
"extra_columns": (("unit_time", unit_time_column),),
}
def get_table_data(self):
def get_queryset(self):
unit_time = self.kwargs["unit_time"]
if unit_time not in self.UNIT_TIMES:
raise BadRequest("unit time must be one of day, week, month, or year")
@ -175,7 +172,7 @@ class AccessPerUnitTime(BaseAccessReport):
]
return (
super()
.get_table_data()
.get_queryset()
.filter(event_type__in=granted_event_types)
.values(unit_time=Trunc("timestamp", unit_time))
.annotate(
@ -229,13 +226,13 @@ class DeniedAccess(BaseAccessReport):
_report_name = "Denied Access"
table_class = DeniedAccessTable
def get_table_data(self):
def get_queryset(self):
denied_event_types = [
t for t in HIDEvent.EventType if t.name.startswith("DENIED_ACCESS")
]
return (
super()
.get_table_data()
.get_queryset()
.filter(event_type__in=denied_event_types)
.with_decoded_card_number()
)
@ -254,10 +251,10 @@ class MostActiveMembers(BaseAccessReport):
_report_name = "Most Active Members"
table_class = MostActiveMembersTable
def get_table_data(self):
def get_queryset(self):
return (
super()
.get_table_data()
.get_queryset()
.values("cardholder_id", "forename", "surname")
.order_by()
.annotate(access_count=Count("cardholder_id"))
@ -279,10 +276,10 @@ class BusiestDayOfWeek(BaseAccessReport):
table_pagination = False
table_class = BusiestDayOfWeekTable
def get_table_data(self):
def get_queryset(self):
return (
super()
.get_table_data()
.get_queryset()
.values("timestamp__week_day")
.annotate(events=Count("timestamp"))
)
@ -299,10 +296,10 @@ class BusiestTimeOfDay(BaseAccessReport):
table_pagination = False
table_class = BusiestTimeOfDayTable
def get_table_data(self):
def get_queryset(self):
return (
super()
.get_table_data()
.get_queryset()
.values("timestamp__hour")
.annotate(events=Count("timestamp"))
)