mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
First version of the cable list
This commit is contained in:
@@ -6,7 +6,7 @@ from io import BytesIO
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core import serializers
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Sum
|
||||
from django.http import Http404, HttpResponse, JsonResponse
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
@@ -81,6 +81,24 @@ class AssetList(LoginRequiredMixin, generic.ListView):
|
||||
return context
|
||||
|
||||
|
||||
class CableList(AssetList):
|
||||
template_name = 'cable_list.html'
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset().filter(is_cable=True)
|
||||
|
||||
if self.form.cleaned_data['cable_type']:
|
||||
queryset = queryset.filter(cable_type__in=self.form.cleaned_data['cable_type'])
|
||||
|
||||
return queryset
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "Cable List"
|
||||
context["total_length"] = self.get_queryset().aggregate(Sum('length'))['length__sum']
|
||||
return context
|
||||
|
||||
|
||||
class AssetIDUrlMixin:
|
||||
def get_object(self, queryset=None):
|
||||
pk = self.kwargs.get(self.pk_url_kwarg)
|
||||
|
||||
Reference in New Issue
Block a user