From 5e6ea7be2730b67027b6f547ae7e143ff8ade112 Mon Sep 17 00:00:00 2001 From: LoRiot Date: Sat, 22 Oct 2022 15:22:44 +0300 Subject: [PATCH] Add None type to project fields that don't exist --- handlers/projects/create.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/handlers/projects/create.py b/handlers/projects/create.py index 12da2c5..0b927d4 100644 --- a/handlers/projects/create.py +++ b/handlers/projects/create.py @@ -3,7 +3,6 @@ import re from aiogram import types from aiogram.dispatcher import FSMContext -from asyncpg import BitString from states.project import ProjectStates from services.repositories import Repos, ProjectRepo @@ -33,17 +32,17 @@ async def create_project( message: types.Message, repo: Repos, state: FSMContext ): await state.reset_state() - field_patterns = { + field_types = { "Название проекта": str, "Описание": str, "Контакты": str, - "Кол-во участников": int, "Статус": BitString, "Теги": str, + "Кол-во участников": int, "Статус": int, "Теги": str, "Категория": str } - field_values = [] + field_values = {name: None for name in field_types} - for pattern, field_type in field_patterns.items(): + for name, data_type in field_types.items(): try: - field_values.append( - field_type(re.findall(rf"(?<={pattern}: ).*", message.text)[0]) + field_values[name] = data_type( + re.findall(rf"(?<={name}: ).*", message.text)[0] ) except IndexError: pass @@ -51,5 +50,5 @@ async def create_project( logger.debug(field_values) await repo.get_repo(ProjectRepo).add( - *field_values, user_id=message.from_user.id + *field_values.values(), user_id=message.from_user.id )