From 67e58c2dda17caa2b283b5f8164c17eaa2bb1c310c37d6539e8639fe9ad8f420 Mon Sep 17 00:00:00 2001 From: vladislav Date: Tue, 8 Sep 2026 07:49:52 -0400 Subject: [PATCH] fix --- tasks.ipynb | 32 +++++++++++++++++--------------- tasks.py | 30 ++++++++++++++++-------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/tasks.ipynb b/tasks.ipynb index 7ba26d4..560ae4d 100644 --- a/tasks.ipynb +++ b/tasks.ipynb @@ -69,20 +69,7 @@ "outputs": [], "source": [ "async def notify_in_profile(item: NotifyItem):\n", - " user = await users_collection.find_one({'_id': ObjectId(str(item.user_id))},{'email':1})\n", - " login_link = f'{FULL_DOMAIN}/login/{await token_create(str(user['_id']), url=f'/profile')}'\n", - " if PROD:\n", - " email_task.notify.delay(user['email'], {\n", - " 'text': item.text,\n", - " 'list': [[]],\n", - " 'primary': {\n", - " 'href': login_link,\n", - " 'text': 'Войти и посмотреть'\n", - " },\n", - " 'title': item.title,\n", - " 'login_link': login_link,\n", - " }, 'Уведомление', 'main.html')\n", - " return await notify_collection.update_one(\n", + " doc = await notify_collection.update_one(\n", " {\n", " \"user_id\": item.user_id,\n", " \"type\": item.type_item,\n", @@ -102,7 +89,22 @@ " }\n", " },\n", " upsert=True,\n", - " )\n" + " )\n", + " if doc.upserted_id:\n", + " user = await users_collection.find_one({'_id': ObjectId(str(item.user_id))},{'email':1})\n", + " login_link = f'{FULL_DOMAIN}/login/{await token_create(str(user['_id']), url=f'/profile')}'\n", + " if PROD:\n", + " email_task.notify.delay(user['email'], {\n", + " 'text': item.text,\n", + " 'list': [[]],\n", + " 'primary': {\n", + " 'href': login_link,\n", + " 'text': 'Войти и посмотреть'\n", + " },\n", + " 'title': item.title,\n", + " 'login_link': login_link,\n", + " }, 'Уведомление', 'main.html')\n", + " return doc\n" ], "display_name": ".venv" }, diff --git a/tasks.py b/tasks.py index bbdeddd..252a739 100644 --- a/tasks.py +++ b/tasks.py @@ -12,20 +12,7 @@ import asyncio async def notify_in_profile(item: NotifyItem): - user = await users_collection.find_one({'_id': ObjectId(str(item.user_id))},{'email':1}) - login_link = f'{FULL_DOMAIN}/login/{await token_create(str(user['_id']), url=f'/profile')}' - if PROD: - email_task.notify.delay(user['email'], { - 'text': item.text, - 'list': [[]], - 'primary': { - 'href': login_link, - 'text': 'Войти и посмотреть' - }, - 'title': item.title, - 'login_link': login_link, - }, 'Уведомление', 'main.html') - return await notify_collection.update_one( + doc = await notify_collection.update_one( { "user_id": item.user_id, "type": item.type_item, @@ -46,6 +33,21 @@ async def notify_in_profile(item: NotifyItem): }, upsert=True, ) + if doc.upserted_id: + user = await users_collection.find_one({'_id': ObjectId(str(item.user_id))},{'email':1}) + login_link = f'{FULL_DOMAIN}/login/{await token_create(str(user['_id']), url=f'/profile')}' + if PROD: + email_task.notify.delay(user['email'], { + 'text': item.text, + 'list': [[]], + 'primary': { + 'href': login_link, + 'text': 'Войти и посмотреть' + }, + 'title': item.title, + 'login_link': login_link, + }, 'Уведомление', 'main.html') + return doc async def email_new_post(new_post: Dict):