Merge branch 'I' into razrab
This commit is contained in:
commit
887214afbf
4 files changed
+144
-5
No files matched your search
BIN
Binary file not shown.
@@ -16,7 +16,7 @@
|
||||
class="bg-transparent py"
|
||||
density="compact"
|
||||
:prepend-avatar="imageSrc"
|
||||
title="Портал МиФНС по ЦОД № 2"
|
||||
title="Портал МИ ФНС по ЦОД № 2"
|
||||
variant="text"
|
||||
:to="'/'" />
|
||||
|
||||
|
||||
+143
-4
@@ -1,10 +1,18 @@
|
||||
import os
|
||||
from openpyxl import load_workbook
|
||||
import openpyxl
|
||||
from rest_framework.response import Response
|
||||
import datetime
|
||||
from datetime import date
|
||||
from .serializers import *
|
||||
from .models import *
|
||||
import pandas as pd
|
||||
from rest_framework.views import APIView
|
||||
from userauth.models import *
|
||||
from django.shortcuts import render
|
||||
from pandas.io.excel import ExcelWriter
|
||||
import openpyxl as oxl
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.styles import Font, Alignment, Side, Border
|
||||
|
||||
class GeneralVacationAPIView(APIView):
|
||||
def get(self, request):
|
||||
@@ -24,10 +32,141 @@ class GeneralVacationAPIView(APIView):
|
||||
return Response({"Отпуск": serializer_for_basecrit.data, "План-график": serializer_for_plan.data})
|
||||
|
||||
class DailyRoundUpAPIView(APIView):
|
||||
|
||||
def convert_width(self, width):
|
||||
"""
|
||||
Конвертируем ширину столбца Excel в ширину столбца openpyxl
|
||||
"""
|
||||
PIXELS_PER_CHAR = 7
|
||||
return (width) / PIXELS_PER_CHAR
|
||||
|
||||
def get(self, request):
|
||||
user = DictEmployee.objects.using('user_directory').values('login', 'fio')
|
||||
user = DictEmployee.objects.using('user_directory').filter(deleted=0).values('login', 'department', 'familyname', 'name', 'parentname')
|
||||
df = pd.DataFrame.from_records(user)
|
||||
print(df)
|
||||
df['tabel'] = df['login'].str.split('-', expand = True)[1]+df['login'].str.split('-', expand = True)[2]
|
||||
file_path = 'media/DailyRoundUp.xlsx'
|
||||
|
||||
thins = Side(border_style="thin")
|
||||
# l = pd.DataFrame(df[(df.department=='Руководство')][['tabel', 'familyname', 'name', 'parentname']])
|
||||
# l.to_excel(file_path, sheet_name="Список", index= False, header= False, startcol=2, startrow=8)
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "Список"
|
||||
ws['B2'] = 'Список сотрудников'
|
||||
ws['B3'] = 'МИ ФНС России по ЦОД № 2'
|
||||
ws['B4'] = 'по подразделениям'
|
||||
|
||||
ws['B6'] = 'Таб.'
|
||||
ws['C6'] = 'Фамилия'
|
||||
ws['D6'] = 'Имя'
|
||||
ws['E6'] = 'Очество'
|
||||
|
||||
for col in ws.iter_cols(min_row=6, max_row=6, min_col=2, max_col=5):
|
||||
for cell in col:
|
||||
cell.font = Font(name='Times New Roman', size=11, bold=True)
|
||||
cell.border = Border(top=thins, bottom=thins, left=thins, right=thins)
|
||||
|
||||
ws['G6'] = 'Отпуск'
|
||||
ws['I6'] = 'Болен'
|
||||
ws['K6'] = 'Удаленка'
|
||||
|
||||
for col in ws.iter_cols(min_row=6, max_row=6, min_col=2, max_col=5):
|
||||
for cell in col:
|
||||
cell.font = Font(name='Times New Roman', size=11, bold=True)
|
||||
cell.border = Border(top=thins, bottom=thins, left=thins, right=thins)
|
||||
|
||||
|
||||
ws['I1'] = 'На '+ date.today().strftime("%d.%m.%Y")
|
||||
|
||||
numb = 1
|
||||
|
||||
column_widths = [29, 53, 96, 96, 112, 28, 222, 29, 148, 28, 145, 33]
|
||||
for i, width in enumerate(column_widths):
|
||||
column_letter = openpyxl.utils.get_column_letter(i+1)
|
||||
ws.column_dimensions[column_letter].width = self.convert_width(width)
|
||||
|
||||
for col in ws.iter_cols(min_row=2, max_row=5, min_col=2, max_col=5):
|
||||
for cell in col:
|
||||
cell.font = Font(name='Times New Roman', size=12, bold=True)
|
||||
cell.alignment = Alignment(horizontal='center')
|
||||
|
||||
ws['I1'].font = Font(name='Times New Roman', size=14, bold=True)
|
||||
ws['I1'].alignment = Alignment(horizontal='left')
|
||||
|
||||
|
||||
for x in range(3):
|
||||
ws.merge_cells(start_row=2+x, start_column=2, end_row=2+x, end_column=6)
|
||||
|
||||
|
||||
k=7
|
||||
for i in df['department'].unique():
|
||||
ws.cell(row = k, column = 2).value = i
|
||||
ws.cell(row = k, column = 2).font = Font(name='Times New Roman', size=10, bold=True)
|
||||
ws.merge_cells(start_row=k, start_column=2, end_row=k, end_column=12)
|
||||
|
||||
l = pd.DataFrame(df[(df.department==i)][['tabel', 'familyname', 'name', 'parentname']])
|
||||
|
||||
|
||||
for x in range(len(l)):
|
||||
k=k+1
|
||||
|
||||
ws.cell(row = k, column = 1).value = numb
|
||||
ws.cell(row = k, column = 1).font = Font(name='Times New Roman', size=10, bold=True)
|
||||
|
||||
ws.cell(row = k, column = 2).value = l.iloc[x]['tabel']
|
||||
ws.cell(row = k, column = 3).value = l.iloc[x]['familyname']
|
||||
ws.cell(row = k, column = 4).value = l.iloc[x]['name']
|
||||
ws.cell(row = k, column = 5).value = l.iloc[x]['parentname']
|
||||
|
||||
|
||||
for v in range(4):
|
||||
ws.cell(row = k, column = 2+v).font = Font(name='Times New Roman', size=10)
|
||||
ws.cell(row = k, column = 2+v).border = Border(top=thins, bottom=thins, left=thins, right=thins)
|
||||
|
||||
numb=numb+1
|
||||
print(l.iloc[x]['name'])
|
||||
k=k+1
|
||||
print(k, '-------------------1')
|
||||
|
||||
|
||||
return Response('user')
|
||||
wb.save(file_path)
|
||||
|
||||
# file_path = 'media/DailyRoundUp.xlsx'
|
||||
|
||||
|
||||
return Response('')
|
||||
|
||||
# with ExcelWriter(file_path, mode="a" if os.path.exists(file_path) else "w" , if_sheet_exists='replace') as writer:
|
||||
# #
|
||||
# for i in df['department'].unique():
|
||||
# for i in df['department'].unique():
|
||||
# k = pd.DataFrame(df[(df.department==i)][['tabel', 'familyname', 'name', 'parentname']])
|
||||
# # k.to_excel(writer,header=None,index=None)
|
||||
# print(i)
|
||||
# print(k)
|
||||
# return Response('')
|
||||
#
|
||||
#
|
||||
# df.to_excel(table)
|
||||
|
||||
|
||||
# def all_books(request):
|
||||
# file_path = 'media/DailyRoundUp.xlsx'
|
||||
# workbook = load_workbook(filename=file_path)
|
||||
# worksheet = workbook.active
|
||||
|
||||
# books = []
|
||||
# skip_first_row = True
|
||||
# for row in worksheet.iter_rows(values_only=True, min_row=2 if skip_first_row else 1):
|
||||
# book = {
|
||||
# 'book_id': int(row[0]),
|
||||
# 'title': row[1],
|
||||
# 'author': row[2],
|
||||
# 'genre': row[3],
|
||||
# 'year': int(row[4]),
|
||||
# 'description': row[5],
|
||||
# 'cover': row[6]
|
||||
# }
|
||||
# books.append(book)
|
||||
|
||||
# return render(request, 'books.html', {'books': books})
|
||||
Binary file not shown.
Reference in new issue
Block a user