From da9f98ccb56dd83a09d856d48904f23d7ce1706d Mon Sep 17 00:00:00 2001 From: winet Date: Wed, 13 Mar 2024 00:44:15 +1000 Subject: [PATCH] transliteration of the csv file name --- app/blueprints/api/collections/routes.py | 5 +++-- requirements.txt | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/blueprints/api/collections/routes.py b/app/blueprints/api/collections/routes.py index 6df04b3..d9fabe0 100644 --- a/app/blueprints/api/collections/routes.py +++ b/app/blueprints/api/collections/routes.py @@ -5,6 +5,7 @@ import os from flask import Blueprint, render_template, request from loguru import logger +from transliterate import translit from app.models.collection import Collection from app.extensions import db @@ -53,7 +54,7 @@ def export_users_to_csv(id: int): if len(collection.users) <= 0: return "", 204 - filename = f"{collection.name} - {datetime.now()}.csv" + filename = f"{translit(collection.name, 'ru', reversed=True)} - {datetime.now()}.csv" fieldnames = collection.users[0].to_dict().keys() si = io.StringIO() @@ -63,4 +64,4 @@ def export_users_to_csv(id: int): writer.writeheader() writer.writerows(map(lambda user: user.to_dict(), collection.users)) - return si, 200, {'Content-Disposition': f'attachment; filename={filename}', 'Content-type': 'text/csv; charset=utf-8'} \ No newline at end of file + return si.getvalue(), 200, {'Content-Disposition': f'attachment; filename={filename}', 'Content-type': 'text/csv; charset=utf-8'} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 16475a5..1ffa1ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -37,6 +37,7 @@ six==1.16.0 SQLAlchemy==2.0.25 Telethon==1.33.1 TgCrypto==1.2.5 +transliterate==1.10.2 typing_extensions==4.9.0 tzdata==2023.4 vine==5.1.0