Рефакторинг всего раздела
This commit is contained in:
1 parent
a375c1e47f
commit
241966bb89
8 files changed
+79
-42
No files matched your search
@@ -8,24 +8,24 @@
|
||||
<!-- Безопасность -->
|
||||
<!-- {{ safetyData }} -->
|
||||
<v-row class="bg-red">
|
||||
<v-col cols="4" class="bg-orange" v-for="item in safetyData" :key="item.id">
|
||||
<v-card
|
||||
width="500"
|
||||
:title="item.name_chapter">
|
||||
<v-card-actions>
|
||||
<v-btn>{{ item.document_category }}</v-btn>
|
||||
<v-btn :icon="showMore[item.id] ? 'mdi-chevron-up' : 'mdi-chevron-down'" @click="showMore[item.id] = !showMore[item.id]"></v-btn>
|
||||
</v-card-actions>
|
||||
<v-expand-transition>
|
||||
<div v-show="showMore[item.id]">
|
||||
<v-divider></v-divider>
|
||||
<v-card-actions>
|
||||
<v-card-text>Название документа</v-card-text>
|
||||
<v-col>
|
||||
<v-card class="bg-orange" v-for="item in safetyData" :key="item.id">
|
||||
<v-card-title>{{ item.name }}</v-card-title>
|
||||
<v-card-actions v-for="category in item.categories" :key="category.id">
|
||||
<v-btn>{{ category.name }}</v-btn>
|
||||
<v-btn :icon="showMore[category.id] ? 'mdi-chevron-up' : 'mdi-chevron-down'" @click="showMore[category.id] = !showMore[category.id]"></v-btn>
|
||||
<v-expand-transition>
|
||||
<div v-show="showMore[category.id]">
|
||||
<!-- <v-divider></v-divider> -->
|
||||
<v-card-actions v-for="file in category.files" :key="file.id">
|
||||
<v-card-text>{{ file.name }}</v-card-text>
|
||||
<v-btn icon="mdi-eye" color="grey"></v-btn>
|
||||
<v-btn icon='mdi-cloud-download' color="grey"></v-btn>
|
||||
</v-card-actions>
|
||||
</div>
|
||||
</v-expand-transition>
|
||||
</v-card-actions>
|
||||
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
@@ -36,23 +36,25 @@ import { ref, onBeforeMount } from 'vue';
|
||||
import { pagecounter } from '@/utils/universal_functions'
|
||||
import { axiosApiInstance } from '@/utils/axios-api';
|
||||
|
||||
pagecounter()
|
||||
pagecounter();
|
||||
|
||||
const safetyData = ref([])
|
||||
const showMore = ref(true)
|
||||
const safetyData = ref([]);
|
||||
const showMore = ref(false);
|
||||
|
||||
onBeforeMount(() => {
|
||||
axiosApiInstance.get(`api/safety/files/`).then(result => {
|
||||
safetyData.value = result.data
|
||||
})
|
||||
})
|
||||
|
||||
console.log(safetyData.value);
|
||||
});
|
||||
|
||||
|
||||
showMore.value = safetyData.value.reduce((acc, value) => {
|
||||
acc[value.id] = false
|
||||
return acc
|
||||
}, {});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style></style>
|
||||
@@ -1,3 +0,0 @@
|
||||
class="text-white text-center text-lg-h5 h-100"
|
||||
align-content="center"
|
||||
justify="center"
|
||||
File renamed without changes.
@@ -1,3 +0,0 @@
|
||||
class="text-white text-center text-lg-h5 h-100"
|
||||
align-content="center"
|
||||
justify="center"
|
||||
+4
-5
@@ -4,11 +4,10 @@ from .models import SafetyFile
|
||||
# Register your models here.
|
||||
|
||||
|
||||
|
||||
class SafetyFileAdmin(admin.ModelAdmin):
|
||||
list_display = ('name_chapter', 'date_file', 'document_category', 'file_document')
|
||||
list_editable = ('date_file', 'document_category')
|
||||
list_filter = ('name_chapter', 'date_file', 'document_category', 'file_document')
|
||||
fields = ('name_chapter', 'date_file', 'document_category', 'file_document')
|
||||
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)
|
||||
+33
-12
@@ -1,22 +1,44 @@
|
||||
from django.db import models
|
||||
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]
|
||||
|
||||
CATEGORY_DOCUMENT = (
|
||||
('Нормативные документы', 'Нормативные документы'),
|
||||
('Инструкции', 'Инструкции'),
|
||||
('Учебные материалы', 'Учебные материалы'),
|
||||
)
|
||||
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 = "Методологические материалы"
|
||||
|
||||
|
||||
# Общая модель для раздела "Безопасность"
|
||||
class SafetyFile(models.Model):
|
||||
name_chapter = models.CharField(verbose_name='Название модуля', max_length=255, blank=False, db_index=True)
|
||||
date_file = models.DateField(verbose_name='Дата документа')
|
||||
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)
|
||||
document_category = models.CharField(verbose_name='Категория документа', max_length=255, choices=CATEGORY_DOCUMENT, default='Нормативные документы', blank=False)
|
||||
file_document = models.FileField(verbose_name='Имя документа', upload_to='safety')
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -24,5 +46,4 @@ class SafetyFile(models.Model):
|
||||
verbose_name_plural = 'Документы раздела безопасности'
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name_chapter)
|
||||
|
||||
return str(self.name)
|
||||
@@ -2,6 +2,9 @@ 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__'
|
||||
+19
-1
@@ -1,3 +1,5 @@
|
||||
from itertools import groupby
|
||||
|
||||
from django.shortcuts import render
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
@@ -10,5 +12,21 @@ class SafetyFileAPIView(APIView):
|
||||
|
||||
all_file = SafetyFile.objects.all()
|
||||
serializer_for_file = SafetyFileSerializer(instance=all_file, many=True)
|
||||
|
||||
data = []
|
||||
|
||||
return Response(serializer_for_file.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)
|
||||
Reference in new issue
Block a user