описание

This commit is contained in:
iriska-gri committed 2024-03-18 14:20:06 +03:00
1 parent be880402ea
commit 3b9e647ddc
1115 files changed
+90 -931

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
from itertools import groupby
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .serializers import *
from .models import *
from userauth.serializers import *
from userauth.models import *
# Create your views here.
class SafetyFileAPIView(APIView):
def get(self, request):
chapters = self.request.query_params.get('chapter_id', 1)
all_file = SafetyFile.objects.filter(chapter_id=chapters).order_by('chapter_id', 'category_id').all()
serializer_for_file = SafetyFileSerializer(instance=all_file, many=True)
data = []
for (chapter_id, chapter_name), row in groupby(serializer_for_file.data, lambda x: (x['chapter_id'], x['chapter_name'])):
chapter = {
'id': chapter_id,
'name': chapter_name,
'categories': []
}
data.append(chapter)
for (category_id, category_name), files in groupby(row, lambda x: (x['category_id'], x['category_name'])):
chapter['categories'].append({
'id': category_id,
'name': category_name,
'files': [file for file in files]
})
return Response(data)
class SafetyResponsebilityAPIView(APIView):
def get(self, request):
fireuser = OrderResponsibility.objects.get(id=54)
responsobility_users = OrderResponsibilitySerializer(fireuser)
return Response(responsobility_users.data)
class CommitteeFilesAPIView(APIView):
def get(self, request):
committee_files = Committee1.objects.get(id=106)
files = Committee1Serializer(committee_files)
return Response(files.data)