This commit is contained in:
vladislav 2026-09-14 08:12:52 -04:00
parent b06a678fb2
commit 5f8a1bebf7
7 changed files with 74 additions and 36 deletions

View File

@ -125,7 +125,7 @@ async def accept_delivery(
new_doc = {
**existing,
"status": "Получено",
"status": "Получено галерей" if 'partner' in current_user.get('roles', []) else "Получено художником",
"notify": notify.upserted_id,
"received_at": datetime.utcnow(),
"updated_at": datetime.utcnow(),

View File

@ -180,23 +180,42 @@
"metadata": {},
"outputs": [],
"source": [
"def get_delivery_aggregate(_filter: dict = {}, _status: str = None):\n",
"from typing import Any, AsyncIterator\n",
"\n",
"\n",
"def get_delivery_aggregate(\n",
" _filter: dict[str, Any] | None = None,\n",
" _status: str | list[str] | None = None,\n",
"):\n",
" cursor = delivery_collection.aggregate([\n",
" {\"$match\": {\n",
" \"prod\": PROD, **_filter\n",
" }},\n",
" {\n",
" \"$match\": {\n",
" \"prod\": PROD,\n",
" **(_filter or {}),\n",
" }\n",
" },\n",
" {\"$sort\": {\"_id\": -1}},\n",
" {\"$group\": {\n",
" {\n",
" \"$group\": {\n",
" \"_id\": \"$post_id\",\n",
" \"doc\": {\"$first\": \"$$ROOT\"}\n",
" }},\n",
" \"doc\": {\"$first\": \"$$ROOT\"},\n",
" }\n",
" },\n",
" {\"$replaceRoot\": {\"newRoot\": \"$doc\"}},\n",
" {\"$sort\": {\"_id\": -1}},\n",
" ])\n",
" if _status:\n",
" return (doc async for doc in cursor if doc.get('status') == _status)\n",
" else:\n",
" return cursor\n"
"\n",
" if _status is None:\n",
" return cursor\n",
"\n",
" statuses = {_status} if isinstance(_status, str) else set(_status)\n",
"\n",
" async def filtered_cursor() -> AsyncIterator[dict[str, Any]]:\n",
" async for doc in cursor:\n",
" if doc.get(\"status\") in statuses:\n",
" yield doc\n",
"\n",
" return filtered_cursor()\n"
],
"display_name": ".venv"
},
@ -1689,7 +1708,7 @@
"):\n",
" exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)})\n",
" if exhibition:\n",
" posts = [doc async for doc in get_delivery_aggregate({\"exhibition_id\": exhibition_id}, 'На выставке')]\n",
" posts = [doc async for doc in get_delivery_aggregate({\"exhibition_id\": exhibition_id}, ['Получено', 'Получено галерей', 'Продано', 'На выставке'])]\n",
" \n",
" return templates.TemplateResponse(\n",
" request=request, name=\"exhibition/index.html\", context={\"id\": 1, \"user\": user, \"exhibition\": exhibition, \"posts\": posts, 'now': datetime.now()}\n",

41
main.py
View File

@ -81,24 +81,43 @@ def transliterate(text: str) -> str:
return ''.join(RUS_TO_LAT.get(ch, '' if ch not in string.ascii_letters else ch) for ch in text)
def get_delivery_aggregate(_filter: dict = {}, _status: str = None):
from typing import Any, AsyncIterator
def get_delivery_aggregate(
_filter: dict[str, Any] | None = None,
_status: str | list[str] | None = None,
):
cursor = delivery_collection.aggregate([
{"$match": {
"prod": PROD, **_filter
}},
{
"$match": {
"prod": PROD,
**(_filter or {}),
}
},
{"$sort": {"_id": -1}},
{"$group": {
{
"$group": {
"_id": "$post_id",
"doc": {"$first": "$$ROOT"}
}},
"doc": {"$first": "$$ROOT"},
}
},
{"$replaceRoot": {"newRoot": "$doc"}},
{"$sort": {"_id": -1}},
])
if _status:
return (doc async for doc in cursor if doc.get('status') == _status)
else:
if _status is None:
return cursor
statuses = {_status} if isinstance(_status, str) else set(_status)
async def filtered_cursor() -> AsyncIterator[dict[str, Any]]:
async for doc in cursor:
if doc.get("status") in statuses:
yield doc
return filtered_cursor()
async def get_latest_news() -> List[dict]:
cursor = news_collection.find({'publish_on_platform': True}).sort("_id", -1).limit(30)
@ -1260,7 +1279,7 @@ async def exhibition_members(
):
exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)})
if exhibition:
posts = [doc async for doc in get_delivery_aggregate({"exhibition_id": exhibition_id}, 'На выставке')]
posts = [doc async for doc in get_delivery_aggregate({"exhibition_id": exhibition_id}, ['Получено', 'Получено галерей', 'Продано', 'На выставке'])]
return templates.TemplateResponse(
request=request, name="exhibition/index.html", context={"id": 1, "user": user, "exhibition": exhibition, "posts": posts, 'now': datetime.now()}

View File

@ -17,7 +17,7 @@
<div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span>
</div>
{% elif doc.status == 'Получено' %}
{% elif Получено' in (doc.status or '') %}
<div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span>
</div>

View File

@ -33,7 +33,7 @@
<div class="b_thlt1">
<span class="b_5dr47">Запрос на отправку</span>
</div>
{% elif doc.status == 'Получено' %}
{% elif Получено' in (doc.status or '') %}
<div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span>
</div>

View File

@ -17,7 +17,7 @@
<div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span>
</div>
{% elif doc.status == 'Получено' %}
{% elif Получено' in (doc.status or '') %}
<div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span>
</div>

View File

@ -12,21 +12,21 @@
<figure class="c_4b1hy b_uu2ub" data-exhibition_id="{{doc.get('exhibition_id')}}" data-delivery-id="{{doc._id}}" data-sender="{{doc.sender._id}}" data-receiver="{{doc.receiver._id}}">
<img class="b_1fvkt" src="/b/posts/{{doc.img}}">
<figcaption class="c_3g8gh b_pvw5a" data-id="{{doc._id}}">
{% if doc.status == 'Ожидает отправки' %}
{% if (doc.status or '') == 'Ожидает отправки' %}
<div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span>
<span class="b_5dr47">{{(doc.status or '')}}</span>
</div>
{% elif doc.status == 'Получено' %}
{% elif 'Получено' in (doc.status or '') %}
<div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span>
<span class="b_5dr47">{{(doc.status or '')}}</span>
</div>
{% elif doc.status == 'Ожидает получения' %}
{% elif (doc.status or '') == 'Ожидает получения' %}
<div class="b_thlt1_2">
<span class="b_5dr47_2">{{doc.status}}</span>
<span class="b_5dr47_2">{{(doc.status or '')}}</span>
</div>
{% else %}
<div class="b_thlt1_2">
<span class="b_5dr47_2">{{doc.status}}</span>
<span class="b_5dr47_2">{{(doc.status or '')}}</span>
</div>
{% endif %}
<a class="b_6spaf" href="/profile/delivery/{{doc.post_id}}#main">Посмотреть историю</a>