fix
This commit is contained in:
parent
67e58c2dda
commit
01164bc9ac
51
tasks.ipynb
51
tasks.ipynb
@ -69,7 +69,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"async def notify_in_profile(item: NotifyItem):\n",
|
"async def notify_in_profile(item: NotifyItem):\n",
|
||||||
" doc = await notify_collection.update_one(\n",
|
" result = await notify_collection.update_one(\n",
|
||||||
" {\n",
|
" {\n",
|
||||||
" \"user_id\": item.user_id,\n",
|
" \"user_id\": item.user_id,\n",
|
||||||
" \"type\": item.type_item,\n",
|
" \"type\": item.type_item,\n",
|
||||||
@ -90,21 +90,42 @@
|
|||||||
" },\n",
|
" },\n",
|
||||||
" upsert=True,\n",
|
" upsert=True,\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" if doc.upserted_id:\n",
|
"\n",
|
||||||
" user = await users_collection.find_one({'_id': ObjectId(str(item.user_id))},{'email':1})\n",
|
" if result.upserted_id is None:\n",
|
||||||
" login_link = f'{FULL_DOMAIN}/login/{await token_create(str(user['_id']), url=f'/profile')}'\n",
|
" return result # Existing notification was updated; no email\n",
|
||||||
" if PROD:\n",
|
"\n",
|
||||||
" email_task.notify.delay(user['email'], {\n",
|
" user = await users_collection.find_one(\n",
|
||||||
" 'text': item.text,\n",
|
" {\"_id\": ObjectId(str(item.user_id))},\n",
|
||||||
" 'list': [[]],\n",
|
" {\"email\": 1},\n",
|
||||||
" 'primary': {\n",
|
" )\n",
|
||||||
" 'href': login_link,\n",
|
"\n",
|
||||||
" 'text': 'Войти и посмотреть'\n",
|
" if not user:\n",
|
||||||
|
" return result\n",
|
||||||
|
"\n",
|
||||||
|
" token = await token_create(\n",
|
||||||
|
" str(user[\"_id\"]),\n",
|
||||||
|
" url=\"/profile\",\n",
|
||||||
|
" )\n",
|
||||||
|
" login_link = f\"{FULL_DOMAIN}/login/{token}\"\n",
|
||||||
|
"\n",
|
||||||
|
" if PROD:\n",
|
||||||
|
" email_task.notify.delay(\n",
|
||||||
|
" user[\"email\"],\n",
|
||||||
|
" {\n",
|
||||||
|
" \"text\": item.text,\n",
|
||||||
|
" \"list\": [[]],\n",
|
||||||
|
" \"primary\": {\n",
|
||||||
|
" \"href\": login_link,\n",
|
||||||
|
" \"text\": \"Войти и посмотреть\",\n",
|
||||||
" },\n",
|
" },\n",
|
||||||
" 'title': item.title,\n",
|
" \"title\": item.title,\n",
|
||||||
" 'login_link': login_link,\n",
|
" \"login_link\": login_link,\n",
|
||||||
" }, 'Уведомление', 'main.html')\n",
|
" },\n",
|
||||||
" return doc\n"
|
" \"Уведомление\",\n",
|
||||||
|
" \"main.html\",\n",
|
||||||
|
" )\n",
|
||||||
|
"\n",
|
||||||
|
" return result\n"
|
||||||
],
|
],
|
||||||
"display_name": ".venv"
|
"display_name": ".venv"
|
||||||
},
|
},
|
||||||
|
|||||||
51
tasks.py
51
tasks.py
@ -12,7 +12,7 @@ import asyncio
|
|||||||
|
|
||||||
|
|
||||||
async def notify_in_profile(item: NotifyItem):
|
async def notify_in_profile(item: NotifyItem):
|
||||||
doc = await notify_collection.update_one(
|
result = await notify_collection.update_one(
|
||||||
{
|
{
|
||||||
"user_id": item.user_id,
|
"user_id": item.user_id,
|
||||||
"type": item.type_item,
|
"type": item.type_item,
|
||||||
@ -33,21 +33,42 @@ async def notify_in_profile(item: NotifyItem):
|
|||||||
},
|
},
|
||||||
upsert=True,
|
upsert=True,
|
||||||
)
|
)
|
||||||
if doc.upserted_id:
|
|
||||||
user = await users_collection.find_one({'_id': ObjectId(str(item.user_id))},{'email':1})
|
if result.upserted_id is None:
|
||||||
login_link = f'{FULL_DOMAIN}/login/{await token_create(str(user['_id']), url=f'/profile')}'
|
return result # Existing notification was updated; no email
|
||||||
if PROD:
|
|
||||||
email_task.notify.delay(user['email'], {
|
user = await users_collection.find_one(
|
||||||
'text': item.text,
|
{"_id": ObjectId(str(item.user_id))},
|
||||||
'list': [[]],
|
{"email": 1},
|
||||||
'primary': {
|
)
|
||||||
'href': login_link,
|
|
||||||
'text': 'Войти и посмотреть'
|
if not user:
|
||||||
|
return result
|
||||||
|
|
||||||
|
token = await token_create(
|
||||||
|
str(user["_id"]),
|
||||||
|
url="/profile",
|
||||||
|
)
|
||||||
|
login_link = f"{FULL_DOMAIN}/login/{token}"
|
||||||
|
|
||||||
|
if PROD:
|
||||||
|
email_task.notify.delay(
|
||||||
|
user["email"],
|
||||||
|
{
|
||||||
|
"text": item.text,
|
||||||
|
"list": [[]],
|
||||||
|
"primary": {
|
||||||
|
"href": login_link,
|
||||||
|
"text": "Войти и посмотреть",
|
||||||
},
|
},
|
||||||
'title': item.title,
|
"title": item.title,
|
||||||
'login_link': login_link,
|
"login_link": login_link,
|
||||||
}, 'Уведомление', 'main.html')
|
},
|
||||||
return doc
|
"Уведомление",
|
||||||
|
"main.html",
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def email_new_post(new_post: Dict):
|
async def email_new_post(new_post: Dict):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user