-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eduard0803
committed
Dec 6, 2023
1 parent
3e0a060
commit e4f23fc
Showing
6 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from gestao.web.api.document.views import router | ||
|
||
__all__ = ["router"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import io | ||
|
||
from openpyxl import Workbook | ||
|
||
|
||
def generate_report_users_file(all_users_list: list, filter_list: list): | ||
template_data = { | ||
"fullName": [], | ||
"warName": [], | ||
"registration": [], | ||
"rg": [], | ||
"cpf": [], | ||
"placeOfBirth": [], | ||
"ufNatural": [], | ||
"civilState": [], | ||
"cep": [], | ||
"address": [], | ||
"number": [], | ||
"neighborhood": [], | ||
"city": [], | ||
"complement": [], | ||
"uf": [], | ||
"email": [], | ||
"cellphone": [], | ||
"phone": [], | ||
"gender": [], | ||
"motherName": [], | ||
"fatherName": [], | ||
"scolarity": [], | ||
"religion": [], | ||
"bloodType": [], | ||
"actualWorkSituation": [], | ||
"admissionDate": [], | ||
"jobRole": [], | ||
"bodyOfLaw": [], | ||
"lotation": [], | ||
"workPost": [], | ||
} | ||
|
||
for user in all_users_list: | ||
template_data["fullName"].append(user.fullName) | ||
template_data["warName"].append(user.warName) | ||
template_data["registration"].append(user.registration) | ||
template_data["rg"].append(user.rg) | ||
template_data["cpf"].append(user.cpf) | ||
template_data["placeOfBirth"].append(user.placeOfBirth) | ||
template_data["ufNatural"].append(user.ufNatural) | ||
template_data["civilState"].append(user.civilState) | ||
template_data["cep"].append(user.cep) | ||
template_data["address"].append(user.address) | ||
template_data["number"].append(user.number) | ||
template_data["neighborhood"].append(user.neighborhood) | ||
template_data["city"].append(user.city) | ||
template_data["complement"].append(user.complement) | ||
template_data["uf"].append(user.uf) | ||
template_data["email"].append(user.email) | ||
template_data["cellphone"].append(user.cellphone) | ||
template_data["phone"].append(user.phone) | ||
template_data["gender"].append(user.gender) | ||
template_data["motherName"].append(user.motherName) | ||
template_data["fatherName"].append(user.fatherName) | ||
template_data["scolarity"].append(user.scolarity) | ||
template_data["religion"].append(user.religion) | ||
template_data["bloodType"].append(user.bloodType) | ||
template_data["actualWorkSituation"].append(user.actualWorkSituation) | ||
template_data["admissionDate"].append(user.admissionDate) | ||
template_data["jobRole"].append(user.jobRole) | ||
template_data["bodyOfLaw"].append(user.bodyOfLaw) | ||
template_data["lotation"].append(user.lotation) | ||
template_data["workPost"].append(user.workPost) | ||
|
||
if len(filter_list) == 0: | ||
users_data = template_data | ||
else: | ||
users_data = { | ||
key: value for key, value in template_data.items() if key in filter_list | ||
} | ||
|
||
wb = Workbook() | ||
active_spreadsheet = wb.active | ||
|
||
columns = list(users_data.keys()) | ||
active_spreadsheet.append(columns) | ||
|
||
for line in zip(*users_data.values()): | ||
active_spreadsheet.append(line) | ||
|
||
file_stream = io.BytesIO() | ||
wb.save(file_stream) | ||
file_stream.seek(0) | ||
|
||
return file_stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import List | ||
|
||
from fastapi import APIRouter | ||
from fastapi.responses import StreamingResponse | ||
|
||
from gestao.db.models.user import User | ||
from gestao.web.api.document.utils import generate_report_users_file | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/report-users/") | ||
async def get_report_users(filter_list: List[str]): | ||
users_list = await User.objects.all() | ||
file_stream = generate_report_users_file(list(users_list), filter_list) | ||
return StreamingResponse( | ||
file_stream, | ||
media_type=( | ||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
from fastapi.routing import APIRouter | ||
|
||
from gestao.web.api import echo, login, monitoring, user | ||
from gestao.web.api import document, echo, login, monitoring, user | ||
|
||
api_router = APIRouter() | ||
api_router.include_router(monitoring.router) | ||
api_router.include_router(echo.router, prefix="/echo", tags=["echo"]) | ||
api_router.include_router(user.router, prefix="/users", tags=["users"]) | ||
api_router.include_router(login.router, prefix="/login", tags=["login"]) | ||
api_router.include_router( | ||
document.router, | ||
prefix="/documents", | ||
tags=["documents"], | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters