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 = { new_doc = {
**existing, **existing,
"status": "Получено", "status": "Получено галерей" if 'partner' in current_user.get('roles', []) else "Получено художником",
"notify": notify.upserted_id, "notify": notify.upserted_id,
"received_at": datetime.utcnow(), "received_at": datetime.utcnow(),
"updated_at": datetime.utcnow(), "updated_at": datetime.utcnow(),

View File

@ -180,23 +180,42 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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", " cursor = delivery_collection.aggregate([\n",
" {\"$match\": {\n", " {\n",
" \"prod\": PROD, **_filter\n", " \"$match\": {\n",
" }},\n", " \"prod\": PROD,\n",
" **(_filter or {}),\n",
" }\n",
" },\n",
" {\"$sort\": {\"_id\": -1}},\n", " {\"$sort\": {\"_id\": -1}},\n",
" {\"$group\": {\n", " {\n",
" \"_id\": \"$post_id\",\n", " \"$group\": {\n",
" \"doc\": {\"$first\": \"$$ROOT\"}\n", " \"_id\": \"$post_id\",\n",
" }},\n", " \"doc\": {\"$first\": \"$$ROOT\"},\n",
" }\n",
" },\n",
" {\"$replaceRoot\": {\"newRoot\": \"$doc\"}},\n", " {\"$replaceRoot\": {\"newRoot\": \"$doc\"}},\n",
" {\"$sort\": {\"_id\": -1}},\n", " {\"$sort\": {\"_id\": -1}},\n",
" ])\n", " ])\n",
" if _status:\n", "\n",
" return (doc async for doc in cursor if doc.get('status') == _status)\n", " if _status is None:\n",
" else:\n", " return cursor\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" "display_name": ".venv"
}, },
@ -1689,7 +1708,7 @@
"):\n", "):\n",
" exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)})\n", " exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)})\n",
" if exhibition:\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", " \n",
" return templates.TemplateResponse(\n", " return templates.TemplateResponse(\n",
" request=request, name=\"exhibition/index.html\", context={\"id\": 1, \"user\": user, \"exhibition\": exhibition, \"posts\": posts, 'now': datetime.now()}\n", " request=request, name=\"exhibition/index.html\", context={\"id\": 1, \"user\": user, \"exhibition\": exhibition, \"posts\": posts, 'now': datetime.now()}\n",

43
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) 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([ cursor = delivery_collection.aggregate([
{"$match": { {
"prod": PROD, **_filter "$match": {
}}, "prod": PROD,
**(_filter or {}),
}
},
{"$sort": {"_id": -1}}, {"$sort": {"_id": -1}},
{"$group": { {
"_id": "$post_id", "$group": {
"doc": {"$first": "$$ROOT"} "_id": "$post_id",
}}, "doc": {"$first": "$$ROOT"},
}
},
{"$replaceRoot": {"newRoot": "$doc"}}, {"$replaceRoot": {"newRoot": "$doc"}},
{"$sort": {"_id": -1}}, {"$sort": {"_id": -1}},
]) ])
if _status:
return (doc async for doc in cursor if doc.get('status') == _status) if _status is None:
else:
return cursor 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]: async def get_latest_news() -> List[dict]:
cursor = news_collection.find({'publish_on_platform': True}).sort("_id", -1).limit(30) 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)}) exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)})
if exhibition: 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( return templates.TemplateResponse(
request=request, name="exhibition/index.html", context={"id": 1, "user": user, "exhibition": exhibition, "posts": posts, 'now': datetime.now()} 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"> <div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span> <span class="b_5dr47">{{doc.status}}</span>
</div> </div>
{% elif doc.status == 'Получено' %} {% elif Получено' in (doc.status or '') %}
<div class="b_thlt1"> <div class="b_thlt1">
<span class="b_5dr47">{{doc.status}}</span> <span class="b_5dr47">{{doc.status}}</span>
</div> </div>

View File

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

View File

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