mirror of
https://github.com/koloideal/Quizzi.git
synced 2026-06-10 10:25:28 +03:00
commit
This commit is contained in:
@@ -53,11 +53,11 @@ async def get_tests_for_export(test_dao: FromDishka[TestDAO], **_kwargs):
|
|||||||
@inject
|
@inject
|
||||||
async def on_test_selected_for_export(
|
async def on_test_selected_for_export(
|
||||||
_callback: CallbackQuery,
|
_callback: CallbackQuery,
|
||||||
_widget: Select,
|
_widget: Select, # type: ignore[type-arg]
|
||||||
_manager: DialogManager,
|
_manager: DialogManager,
|
||||||
item_id: str,
|
item_id: str,
|
||||||
test_repo: FromDishka[TestRepository],
|
test_repo: FromDishka[TestRepository],
|
||||||
):
|
) -> None:
|
||||||
test_id = int(item_id)
|
test_id = int(item_id)
|
||||||
test, questions_with_options = await test_repo.get_full_test(test_id)
|
test, questions_with_options = await test_repo.get_full_test(test_id)
|
||||||
|
|
||||||
@@ -70,6 +70,7 @@ async def on_test_selected_for_export(
|
|||||||
"description": test.description,
|
"description": test.description,
|
||||||
"password": test.password,
|
"password": test.password,
|
||||||
"attempts": test.attempts,
|
"attempts": test.attempts,
|
||||||
|
"expires_at": test.expires_at.isoformat() if test.expires_at else None,
|
||||||
"for_group": test.for_group,
|
"for_group": test.for_group,
|
||||||
"questions": [],
|
"questions": [],
|
||||||
}
|
}
|
||||||
@@ -102,7 +103,7 @@ async def on_test_selected_for_export(
|
|||||||
assert _callback.message is not None
|
assert _callback.message is not None
|
||||||
await _callback.message.answer_document(
|
await _callback.message.answer_document(
|
||||||
document=BufferedInputFile(json_str.encode("utf-8"), filename=filename),
|
document=BufferedInputFile(json_str.encode("utf-8"), filename=filename),
|
||||||
caption=f"📤 <b>Экспорт теста</b>\n\n📝 {test.title}",
|
caption=f"📤 <b>Экспорт теста:</b> {test.title}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ templates_dialog = Dialog(
|
|||||||
id="test_select",
|
id="test_select",
|
||||||
item_id_getter=lambda x: x[1],
|
item_id_getter=lambda x: x[1],
|
||||||
items="tests",
|
items="tests",
|
||||||
on_click=on_test_selected_for_export,
|
on_click=on_test_selected_for_export, # type: ignore[arg-type]
|
||||||
),
|
),
|
||||||
id="tests_scroll",
|
id="tests_scroll",
|
||||||
width=1,
|
width=1,
|
||||||
|
|||||||
@@ -53,11 +53,11 @@ async def get_tests_for_export(test_dao: FromDishka[TestDAO], **_kwargs):
|
|||||||
@inject
|
@inject
|
||||||
async def on_test_selected_for_export(
|
async def on_test_selected_for_export(
|
||||||
_callback: CallbackQuery,
|
_callback: CallbackQuery,
|
||||||
_widget: Select,
|
_widget: Select, # type: ignore[type-arg]
|
||||||
_manager: DialogManager,
|
_manager: DialogManager,
|
||||||
item_id: str,
|
item_id: str,
|
||||||
test_repo: FromDishka[TestRepository],
|
test_repo: FromDishka[TestRepository],
|
||||||
):
|
) -> None:
|
||||||
test_id = int(item_id)
|
test_id = int(item_id)
|
||||||
test, questions_with_options = await test_repo.get_full_test(test_id)
|
test, questions_with_options = await test_repo.get_full_test(test_id)
|
||||||
|
|
||||||
@@ -65,17 +65,20 @@ async def on_test_selected_for_export(
|
|||||||
await _callback.answer("❌ Тест не найден")
|
await _callback.answer("❌ Тест не найден")
|
||||||
return
|
return
|
||||||
|
|
||||||
export_data = {
|
export_data: dict = {
|
||||||
"title": test.title,
|
"title": test.title,
|
||||||
"description": test.description,
|
"description": test.description,
|
||||||
"password": test.password,
|
"password": test.password,
|
||||||
"attempts": test.attempts,
|
"attempts": test.attempts,
|
||||||
|
"expires_at": test.expires_at.isoformat() if test.expires_at else None,
|
||||||
"for_group": test.for_group,
|
"for_group": test.for_group,
|
||||||
"questions": [],
|
"questions": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
questions_list: list = export_data["questions"]
|
||||||
|
|
||||||
for question, options in questions_with_options:
|
for question, options in questions_with_options:
|
||||||
question_data = {
|
question_data: dict = {
|
||||||
"text": question.text,
|
"text": question.text,
|
||||||
"question_type": question.question_type,
|
"question_type": question.question_type,
|
||||||
}
|
}
|
||||||
@@ -90,7 +93,7 @@ async def on_test_selected_for_export(
|
|||||||
for o in options
|
for o in options
|
||||||
]
|
]
|
||||||
|
|
||||||
export_data["questions"].append(question_data)
|
questions_list.append(question_data)
|
||||||
|
|
||||||
json_str = json.dumps(export_data, ensure_ascii=False, indent=2)
|
json_str = json.dumps(export_data, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
@@ -100,7 +103,7 @@ async def on_test_selected_for_export(
|
|||||||
assert _callback.message is not None
|
assert _callback.message is not None
|
||||||
await _callback.message.answer_document(
|
await _callback.message.answer_document(
|
||||||
document=BufferedInputFile(json_str.encode("utf-8"), filename=filename),
|
document=BufferedInputFile(json_str.encode("utf-8"), filename=filename),
|
||||||
caption=f"📤 <b>Экспорт теста</b>\n\n📝 {test.title}",
|
caption=f"📤 <b>Экспорт теста:</b> {test.title}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -123,7 +126,7 @@ templates_dialog = Dialog(
|
|||||||
id="test_select",
|
id="test_select",
|
||||||
item_id_getter=lambda x: x[1],
|
item_id_getter=lambda x: x[1],
|
||||||
items="tests",
|
items="tests",
|
||||||
on_click=on_test_selected_for_export,
|
on_click=on_test_selected_for_export, # type: ignore[arg-type]
|
||||||
),
|
),
|
||||||
id="tests_scroll",
|
id="tests_scroll",
|
||||||
width=1,
|
width=1,
|
||||||
|
|||||||
Reference in New Issue
Block a user