описание
This commit is contained in:
1 parent
be880402ea
commit
3b9e647ddc
1115 files changed
+90
-931
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,13 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import SafetyFile
|
||||
# Register your models here.
|
||||
|
||||
|
||||
class SafetyFileAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'chapter_id', 'category_id', 'sign_date')
|
||||
list_editable = ('sign_date', 'category_id')
|
||||
list_filter = ('name', 'sign_date', 'category_id',)
|
||||
fields = ('name', 'url', 'chapter_id', 'category_id', 'sign_date')
|
||||
|
||||
admin.site.register(SafetyFile, SafetyFileAdmin)
|
||||
@@ -0,0 +1,7 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SafetyConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'safety'
|
||||
verbose_name = 'Раздел Безопасность'
|
||||
@@ -0,0 +1,50 @@
|
||||
from django.db import models
|
||||
from enum import Enum
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class EnumChoice(Enum):
|
||||
@classmethod
|
||||
def get_choices(cls):
|
||||
return [(enum_.name, enum_.value) for enum_ in cls]
|
||||
|
||||
class SafetyChapter(EnumChoice):
|
||||
fire_safety = "Пожарная безопасность"
|
||||
information_safety = "Информационная безопасность"
|
||||
occupational_safety = "Охрана труда"
|
||||
access_mode = "Пропускной и внутриобъектовый режим"
|
||||
civil_defense = "Гражданская оборона"
|
||||
state_secrets = "Защита гостайны"
|
||||
military_registration = "Мобилизационная подготовка и воинский учет"
|
||||
|
||||
class SafetyDocumentCategory(EnumChoice):
|
||||
regulations = "Нормативные документы"
|
||||
instructions = "Инструкции"
|
||||
orders = "Приказы"
|
||||
provisions = "Положения"
|
||||
educational_materials = "Учебные материалы"
|
||||
laws = "Законы"
|
||||
decrees = "Указы"
|
||||
resolutions = "Постановления"
|
||||
thematic_materials = "Тематические материалы"
|
||||
methodological_materials = "Методологические материалы"
|
||||
evacuation_plan = 'План эвакуации'
|
||||
|
||||
|
||||
# Общая модель для раздела "Безопасность"
|
||||
class SafetyFile(models.Model):
|
||||
name = models.CharField(verbose_name='Имя документа', max_length=255)
|
||||
url = models.FileField(verbose_name='Путь до файла',upload_to='safety')
|
||||
chapter_id = models.CharField(verbose_name='Раздел', max_length=255, blank=False, db_index=True, choices=SafetyChapter.get_choices())
|
||||
category_id = models.CharField(verbose_name='Категория документа', max_length=255, blank=False, db_index=True, choices=SafetyDocumentCategory.get_choices())
|
||||
sign_date = models.DateField(verbose_name='Дата документа')
|
||||
created_at = models.DateTimeField(verbose_name='Дата загрузки файла', auto_now_add=True)
|
||||
update_at = models.DateTimeField(verbose_name='Дата обновления файла', auto_now=True)
|
||||
|
||||
class Meta:
|
||||
|
||||
verbose_name = 'Документы раздела безопасности'
|
||||
verbose_name_plural = 'Документы раздела безопасности'
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
@@ -0,0 +1,10 @@
|
||||
from rest_framework import serializers
|
||||
from .models import *
|
||||
|
||||
class SafetyFileSerializer(serializers.ModelSerializer):
|
||||
chapter_name = serializers.CharField(source='get_chapter_id_display')
|
||||
category_name = serializers.CharField(source='get_category_id_display')
|
||||
|
||||
class Meta:
|
||||
model = SafetyFile
|
||||
fields = '__all__'
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,10 @@
|
||||
from django.urls import path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from .views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('files/', SafetyFileAPIView.as_view(), name='safety_files'),
|
||||
path('responsibility/', SafetyResponsebilityAPIView.as_view(), name='responsibility'),
|
||||
path('committee_files/', CommitteeFilesAPIView.as_view(), name='committee_files')
|
||||
]
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user