From 8b7e8e117028c3abc96c23365a53cbe38bd239e2 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 14 Jul 2024 16:33:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ocab_core/main.py | 2 +- src/ocab_core/modules_system/loaders/base.py | 2 +- .../create_report_apps/__init__.py | 0 .../create_report_apps/create_report.py | 4 +- .../create_report_apps/info.json | 7 ++- .../create_report_apps/main.py | 0 .../external/create_report_apps/report.py | 59 +++++++++++++++++++ .../standard/create_report_apps/report.py | 53 ----------------- 8 files changed, 68 insertions(+), 59 deletions(-) rename src/ocab_modules/{standard => external}/create_report_apps/__init__.py (100%) rename src/ocab_modules/{standard => external}/create_report_apps/create_report.py (97%) rename src/ocab_modules/{standard => external}/create_report_apps/info.json (71%) rename src/ocab_modules/{standard => external}/create_report_apps/main.py (100%) create mode 100644 src/ocab_modules/external/create_report_apps/report.py delete mode 100644 src/ocab_modules/standard/create_report_apps/report.py diff --git a/src/ocab_core/main.py b/src/ocab_core/main.py index e92c9ab..e7269b0 100644 --- a/src/ocab_core/main.py +++ b/src/ocab_core/main.py @@ -20,7 +20,7 @@ bot_modules = [ FSLoader(f"{paths.modules_standard}/command_helper"), FSLoader(f"{paths.modules_standard}/info"), FSLoader(f"{paths.modules_standard}/filters"), - FSLoader(f"{paths.modules_standard}/create_report_apps"), + FSLoader(f"{paths.modules_external}/create_report_apps"), FSLoader(f"{paths.modules_standard}/admin"), FSLoader(f"{paths.modules_standard}/message_processing"), ] diff --git a/src/ocab_core/modules_system/loaders/base.py b/src/ocab_core/modules_system/loaders/base.py index cc7d579..166ede8 100644 --- a/src/ocab_core/modules_system/loaders/base.py +++ b/src/ocab_core/modules_system/loaders/base.py @@ -11,7 +11,7 @@ class ModuleInfo: name: str description: str version: str - author: str + author: str | list[str] privileged: bool dependencies: dict diff --git a/src/ocab_modules/standard/create_report_apps/__init__.py b/src/ocab_modules/external/create_report_apps/__init__.py similarity index 100% rename from src/ocab_modules/standard/create_report_apps/__init__.py rename to src/ocab_modules/external/create_report_apps/__init__.py diff --git a/src/ocab_modules/standard/create_report_apps/create_report.py b/src/ocab_modules/external/create_report_apps/create_report.py similarity index 97% rename from src/ocab_modules/standard/create_report_apps/create_report.py rename to src/ocab_modules/external/create_report_apps/create_report.py index 743fd80..4e672b9 100644 --- a/src/ocab_modules/standard/create_report_apps/create_report.py +++ b/src/ocab_modules/external/create_report_apps/create_report.py @@ -129,8 +129,8 @@ async def additional_info_entered(message: Message, state: FSMContext): data = await state.get_data() report = Report(data) - file_report = report.export(html=False).encode() + file_report = report.export().encode() - await message.answer(text=report.export(html=True), parse_mode=ParseMode.HTML) + await message.answer(text=report.export()) await message.answer_document(document=BufferedInputFile(file_report, "report.txt")) await state.clear() diff --git a/src/ocab_modules/standard/create_report_apps/info.json b/src/ocab_modules/external/create_report_apps/info.json similarity index 71% rename from src/ocab_modules/standard/create_report_apps/info.json rename to src/ocab_modules/external/create_report_apps/info.json index a672bdd..79fbd03 100644 --- a/src/ocab_modules/standard/create_report_apps/info.json +++ b/src/ocab_modules/external/create_report_apps/info.json @@ -1,8 +1,11 @@ { - "id": "standard.create_report_apps", + "id": "external.create_report_apps", "name": "Create Report Apps", "description": "Модуль для создания отчетов о ошибках в приложениях", - "author": "OCAB Team", + "author": [ + "OCAB Team", + "Maxim Slipenko" + ], "version": "1.0.0", "privileged": false, "dependencies": { diff --git a/src/ocab_modules/standard/create_report_apps/main.py b/src/ocab_modules/external/create_report_apps/main.py similarity index 100% rename from src/ocab_modules/standard/create_report_apps/main.py rename to src/ocab_modules/external/create_report_apps/main.py diff --git a/src/ocab_modules/external/create_report_apps/report.py b/src/ocab_modules/external/create_report_apps/report.py new file mode 100644 index 0000000..6880108 --- /dev/null +++ b/src/ocab_modules/external/create_report_apps/report.py @@ -0,0 +1,59 @@ +import aiogram + + +class ReportFormatter: + def __init__(self, html=True): + self.html = html + + def bold(self, string): + if self.html: + return f"{self.text(string)}" + return self.text(string) + + def text(self, string): + if self.html: + return aiogram.html.quote(string) + return string + + +class Report: + def __init__(self, data: dict): + self.data = data + + def export(self): + data = self.data + + report = f""" +Стенд с ошибкой: +============================== + +{data['system']} + +Пакет: +============================== + +{data['app']} + +Шаги, приводящие к ошибке: +============================== + +{data['problem_step_by_step']} + +Фактический результат: +============================== + +{data['actual']} + +Ожидаемый результат: +============================== + +{data['expected']} +""" + if data["additional"] != "": + report += f""" +Дополнительно: +============================== + +{data['additional']} +""" + return report diff --git a/src/ocab_modules/standard/create_report_apps/report.py b/src/ocab_modules/standard/create_report_apps/report.py deleted file mode 100644 index d90e21c..0000000 --- a/src/ocab_modules/standard/create_report_apps/report.py +++ /dev/null @@ -1,53 +0,0 @@ -import aiogram - - -class ReportFormatter: - def __init__(self, html=True): - self.html = html - - def bold(self, string): - if self.html: - return f"{self.text(string)}" - return self.text(string) - - def text(self, string): - if self.html: - return aiogram.html.quote(string) - return string - - -class Report: - def __init__(self, data: dict): - self.data = data - - def export(self, html=True): - data = self.data - f = ReportFormatter(html) - - report = f"""{f.bold("Стенд с ошибкой:")} - -{f.text(data['system'])} - -{f.bold("Версия программы:")} - -{f.text(data['app'])} - -{f.bold("Шаги, приводящие к ошибке:")} - -{f.text(data['problem_step_by_step'])} - -{f.bold("Результат:")} - -{f.text(data['actual'])} - -{f.bold("Ожидаемый результат:")} - -{f.text(data['expected'])} - """ - if data["additional"] != "": - report += f"""{f.bold("Дополнительно:")} - -{f.text(data['additional'])} - """ - - return report