This commit is contained in:
vladislav 2026-09-01 21:21:21 -04:00
parent 7e1fec5bb4
commit 25cc63fe08
Signed by: Vladislav
GPG Key ID: D97C9E5E4860EE45
2 changed files with 46 additions and 2 deletions

View File

@ -1614,7 +1614,29 @@
"):\n",
" exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)})\n",
" if exhibition:\n",
" posts = await delivery_collection.find({'status': 'На выставке', \"exhibition_id\": exhibition_id}).to_list()\n",
" match_ = {\n",
" \"$or\": [\n",
" {\"sender._id\": user.get('_id')},\n",
" {\"user._id\": user.get('_id')},\n",
" {\"receiver._id\": user.get('_id')}\n",
" ],\n",
" 'prod': PROD,\n",
" }\n",
" if data.get('competition'):\n",
" match_.update({'competition_id': data.get('competition').get('_id')})\n",
" if data.get('exhibition_id'):\n",
" match_.update({'exhibition_id': data.get('exhibition_id')})\n",
" cursor = delivery_collection.aggregate([\n",
" {\"$match\": match_},\n",
" {\"$sort\": {\"_id\": -1}},\n",
" {\"$group\": {\n",
" \"_id\": \"$post_id\",\n",
" \"doc\": {\"$first\": \"$$ROOT\"}\n",
" }},\n",
" {\"$replaceRoot\": {\"newRoot\": \"$doc\"}},\n",
" {\"$sort\": {\"_id\": -1}},\n",
" ])\n",
" posts = [doc async for doc in cursor if doc.get('status') == 'На выставке']\n",
" return templates.TemplateResponse(\n",
" request=request, name=\"exhibition/index.html\", context={\"id\": 1, \"user\": user, \"exhibition\": exhibition, \"posts\": posts}\n",
" )\n",

24
main.py
View File

@ -1201,7 +1201,29 @@ async def exhibition_members(
):
exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)})
if exhibition:
posts = await delivery_collection.find({'status': 'На выставке', "exhibition_id": exhibition_id}).to_list()
match_ = {
"$or": [
{"sender._id": user.get('_id')},
{"user._id": user.get('_id')},
{"receiver._id": user.get('_id')}
],
'prod': PROD,
}
if data.get('competition'):
match_.update({'competition_id': data.get('competition').get('_id')})
if data.get('exhibition_id'):
match_.update({'exhibition_id': data.get('exhibition_id')})
cursor = delivery_collection.aggregate([
{"$match": match_},
{"$sort": {"_id": -1}},
{"$group": {
"_id": "$post_id",
"doc": {"$first": "$$ROOT"}
}},
{"$replaceRoot": {"newRoot": "$doc"}},
{"$sort": {"_id": -1}},
])
posts = [doc async for doc in cursor if doc.get('status') == 'На выставке']
return templates.TemplateResponse(
request=request, name="exhibition/index.html", context={"id": 1, "user": user, "exhibition": exhibition, "posts": posts}
)