2023-12-05 20:07:31 +08:00
|
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
from rest_framework import viewsets, generics
|
|
|
|
from .models import EquipmentGroup
|
|
|
|
from . import serializers
|
|
|
|
from config.settings import DEBUG
|
|
|
|
from accounts.permissions import IsTechnician
|
2023-11-13 17:52:09 +08:00
|
|
|
|
2023-12-05 20:07:31 +08:00
|
|
|
# -- Equipment Viewsets
|
|
|
|
|
|
|
|
|
|
|
|
class EquipmentGroupViewSet(viewsets.ModelViewSet):
|
|
|
|
if (not DEBUG):
|
|
|
|
permission_classes = [IsAuthenticated, IsTechnician]
|
|
|
|
serializer_class = serializers.EquipmentGroupSerializer
|
|
|
|
queryset = EquipmentGroup.objects.all().order_by('id')
|
|
|
|
|
|
|
|
# Last changed equipment
|
|
|
|
|
|
|
|
|
|
|
|
class LastUpdatedEquipmentGroupViewSet(generics.ListAPIView):
|
|
|
|
if (not DEBUG):
|
|
|
|
permission_classes = [IsAuthenticated, IsTechnician]
|
|
|
|
serializer_class = serializers.EquipmentGroupSerializer
|
|
|
|
queryset = EquipmentGroup.objects.all().order_by('-date_added')
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return super().get_queryset()[:1]
|