Skip to content

Commit

Permalink
update log level in device detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
silvioheinze committed Jan 8, 2025
1 parent 92b730c commit dc9b9da
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/devices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
from .models import Device, DeviceStatus, DeviceLogs
from .forms import DeviceForm, DeviceNotesForm

class DeviceListView(UserPassesTestMixin, ListView):
class DeviceListView(LoginRequiredMixin, UserPassesTestMixin, ListView):
model = Device
context_object_name = 'devices'
template_name = 'devices/list.html'
paginate_by = 25

def test_func(self):
# Only superusers can access this view
return self.request.user.is_authenticated and self.request.user.is_superuser

def get_queryset(self):
# Return the Device queryset ordered by 'id' in ascending order
return Device.objects.all().order_by('id')

# Optimize queryset by selecting related 'current_organization'
return Device.objects.select_related('current_organization').all().order_by('id')

class DeviceDetailView(LoginRequiredMixin, UserPassesTestMixin, DetailView):
model = Device
Expand Down Expand Up @@ -78,11 +79,11 @@ def get_context_data(self, **kwargs):

# Define a level to badge class mapping
context['level_badge_map'] = {
10: 'bg-secondary', # DEBUG
20: 'bg-info', # INFO
30: 'bg-warning', # WARNING
40: 'bg-danger', # ERROR
50: 'bg-dark', # CRITICAL
0: 'bg-secondary', # DEBUG
1: 'bg-info', # INFO
2: 'bg-warning', # WARNING
3: 'bg-danger', # ERROR
4: 'bg-dark', # CRITICAL
}

return context
Expand Down

0 comments on commit dc9b9da

Please sign in to comment.