From d3d08ae1eda63ed417f78301830a39727e3cf3f745a5aff5b79307249a5bb5fe Mon Sep 17 00:00:00 2001 From: vladislav Date: Mon, 17 Aug 2026 15:27:56 -0400 Subject: [PATCH 1/9] feat --- tasks.ipynb | 1 + tasks.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tasks.ipynb b/tasks.ipynb index 4c05c16..8c7980c 100644 --- a/tasks.ipynb +++ b/tasks.ipynb @@ -712,6 +712,7 @@ " },{\n", " \"$set\":{\n", " \"sender\": user,\n", + " \"user\": user,\n", " \"receiver\": display_user(exhibition_owner),\n", " \"exhibition_id\": str(exhibition.get('_id')),\n", " \"address\": exhibition.get('address'),\n", diff --git a/tasks.py b/tasks.py index eda1c62..3fd5f8c 100644 --- a/tasks.py +++ b/tasks.py @@ -541,6 +541,7 @@ async def exhibition_send_invitations(exhibition_id): },{ "$set":{ "sender": user, + "user": user, "receiver": display_user(exhibition_owner), "exhibition_id": str(exhibition.get('_id')), "address": exhibition.get('address'), From 9cdaeaafe509651f54e9b19d8de976e310d9a4ae1ff09210c9aa510c06770928 Mon Sep 17 00:00:00 2001 From: vladislav Date: Mon, 17 Aug 2026 15:57:51 -0400 Subject: [PATCH 2/9] style --- templates/profile/partner/exhibition catalog.html | 4 ++-- templates/profile/partner/exhibition.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/profile/partner/exhibition catalog.html b/templates/profile/partner/exhibition catalog.html index bb22fde..ad7c86e 100644 --- a/templates/profile/partner/exhibition catalog.html +++ b/templates/profile/partner/exhibition catalog.html @@ -16,7 +16,7 @@
{{ profile_nav.profile_nav(user, 'exhibitions') }} @@ -49,7 +49,7 @@
- +
diff --git a/templates/profile/partner/exhibition.html b/templates/profile/partner/exhibition.html index 404c4f3..b7622b9 100644 --- a/templates/profile/partner/exhibition.html +++ b/templates/profile/partner/exhibition.html @@ -18,7 +18,7 @@ {{ profile_nav.profile_nav(user, 'exhibitions') }}
{% if now < exhibition.date_finish %} - + Каталог картин {% endif %} @@ -29,7 +29,7 @@ %} {% set uniq_count = ids | unique | list | length %} {% if uniq_count > 0 %} - {% endif %} From 42ec4d0ba9c5cc429537c5ca4d578a439cc6840e7d048142452afb99cc9d6751 Mon Sep 17 00:00:00 2001 From: vladislav Date: Mon, 24 Aug 2026 08:13:33 -0400 Subject: [PATCH 3/9] build --- build.ipynb | 177 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 121 insertions(+), 56 deletions(-) diff --git a/build.ipynb b/build.ipynb index 052e2b9..47abcc6 100644 --- a/build.ipynb +++ b/build.ipynb @@ -12,7 +12,8 @@ "outputs": [], "source": [ "!pip install -r requirements.txt" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -72,7 +73,8 @@ "EOF\n", "\n", "chmod +x .git/hooks/pre-commit\n" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -120,7 +122,8 @@ " load_env('env')\n", "except:\n", " load_env('env_example')" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -132,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "2809c42c", "metadata": {}, "outputs": [], @@ -161,7 +164,8 @@ " f.write('\\n\\n'.join(app))\n", "\n", "build()" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -195,7 +199,8 @@ "kubectl -n container-registry create secret generic registry-basic-auth \\\n", " --from-file=auth=/tmp/registry.htpasswd \\\n", " --dry-run=client -o yaml | kubectl apply -f -\n" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -209,7 +214,8 @@ "outputs": [], "source": [ "!kubectl create secret docker-registry regcred --docker-server=$REGISTRY_HOST --docker-username='user' --docker-password=$REGISTRY_PASS --docker-email=\"$(git config --global --get user.email)\"" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -224,7 +230,8 @@ "source": [ "!kubectl create namespace kultmost\n", "!kubectl create secret docker-registry regcred -n kultmost --docker-server=$REGISTRY_HOST --docker-username='user' --docker-password=$REGISTRY_PASS --docker-email=\"$(git config --global --get user.email)\"" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -238,7 +245,8 @@ "outputs": [], "source": [ "!docker login $REGISTRY_HOST -u 'user' -p $REGISTRY_PASS" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -260,7 +268,8 @@ "outputs": [], "source": [ "!docker pull $REGISTRY_HOST/python:3.13-alpine" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -274,7 +283,8 @@ "outputs": [], "source": [ "!docker pull $REGISTRY_HOST/python:3.13-slim" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -296,7 +306,8 @@ "outputs": [], "source": [ "!docker build -t $REGISTRY_HOST/api-tg:latest tg/." - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -310,7 +321,8 @@ "outputs": [], "source": [ "!docker push $REGISTRY_HOST/api-tg:latest" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -332,7 +344,8 @@ "outputs": [], "source": [ "!docker build -t $REGISTRY_HOST/avtopost-api:latest ." - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -346,7 +359,8 @@ "outputs": [], "source": [ "!docker image push $REGISTRY_HOST/avtopost-api:latest" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -360,7 +374,8 @@ "outputs": [], "source": [ "!kubectl rollout restart deployments/kultmost-api -n kultmost" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -382,7 +397,8 @@ "outputs": [], "source": [ "!kubectl rollout restart deployments/vk-celery -n kultmost" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -396,7 +412,8 @@ "outputs": [], "source": [ "!kubectl rollout restart deployments/email-celery -n kultmost" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -421,7 +438,8 @@ "docker pull gitea/gitea:1.22\n", "docker tag gitea/gitea:1.22 $REGISTRY_HOST/gitea/gitea:1.22\n", "docker push $REGISTRY_HOST/gitea/gitea:1.22" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -445,7 +463,8 @@ "docker tag busybox:1.36 $REGISTRY_HOST/busybox:1.36\n", "docker tag rabbitmq:3.11-management $REGISTRY_HOST/rabbitmq:3.11-management\n", "docker tag alpine:3.14 $REGISTRY_HOST/alpine:3.14" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -464,7 +483,8 @@ "docker push $REGISTRY_HOST/busybox:1.36\n", "docker push $REGISTRY_HOST/rabbitmq:3.11-management\n", "docker push $REGISTRY_HOST/alpine:3.14" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -486,7 +506,8 @@ "outputs": [], "source": [ "!docker build -t $REGISTRY_HOST/ssh-tunnel:2 tunnel/" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -500,7 +521,8 @@ "outputs": [], "source": [ "!docker push $REGISTRY_HOST/ssh-tunnel:2" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -514,7 +536,8 @@ "outputs": [], "source": [ "!kubectl create secret generic ssh-id-rsa --from-file=id_rsa=/home/user/.ssh/id_rsa -n kultmost" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -528,7 +551,8 @@ "outputs": [], "source": [ "!kubectl apply -n kultmost -f k8s/stunnel.yaml" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -550,7 +574,8 @@ "outputs": [], "source": [ "!envsubst < k8s/prod.yaml | kubectl apply -n kultmost -f -" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -564,7 +589,8 @@ "outputs": [], "source": [ "!envsubst < k8s/kultmost.yaml | kubectl apply -n kultmost -f -" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -578,7 +604,8 @@ "outputs": [], "source": [ "!envsubst < k8s/mq.yaml | kubectl apply -n kultmost -f -" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -592,7 +619,8 @@ "outputs": [], "source": [ "!envsubst < k8s/gitea.yaml | kubectl apply -n gitea -f -" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -606,7 +634,8 @@ "outputs": [], "source": [ "!kubectl get pod -n kultmost" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -631,7 +660,8 @@ "echo \"$INIT_SSH'bash -s' <<'SCRIPT'\"\n", "echo \"kubectl create secret docker-registry regcred --docker-server=$REGISTRY_HOST --docker-username='user' --docker-password=$REGISTRY_PASS --docker-email=\\\"$(git config --global --get user.email)\\\" && clear && history -c && history -w\"\n", "echo \"SCRIPT\"" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -654,7 +684,8 @@ "echo \"clear\"\n", "echo \"history -c\"\n", "echo \"history -w\"" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -684,7 +715,8 @@ "outputs": [], "source": [ "!rsync -avz -ogp --chown=www-data:www-data ./static/ kultmost:/var/www/static/" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -698,7 +730,8 @@ "outputs": [], "source": [ "!echo $(git branch --show-current)" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -712,7 +745,8 @@ "outputs": [], "source": [ "!rsync -avh --exclude-from=.rsyncignore --exclude=.venv/ . kultmost:/app/$(git branch --show-current)/" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -750,7 +784,8 @@ "EOF\n", "\n", "ssh kultmost 'systemctl daemon-reload && systemctl enable --now production.service && systemctl status --no-pager -l production.service'\n" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -780,7 +815,8 @@ "EOF\n", "\n", "ssh kultmost 'systemctl daemon-reload && systemctl enable --now fastapi.service && systemctl status --no-pager -l fastapi.service'\n" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -818,7 +854,8 @@ "EOF\n", "\n", "ssh kultmost 'systemctl daemon-reload && systemctl enable --now staging.service && systemctl status --no-pager -l staging.service'\n" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -854,7 +891,8 @@ "[Install]\n", "WantedBy=default.target\n", "EOF" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -884,7 +922,8 @@ "EOF\n", "\n", "ssh kultmost 'systemctl daemon-reload && systemctl enable --now staging.service && systemctl status --no-pager -l staging.service'\n" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -906,7 +945,8 @@ "outputs": [], "source": [ "!ssh kultmost 'systemctl restart production.service'" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -920,7 +960,8 @@ "outputs": [], "source": [ "!ssh kultmost 'systemctl status production.service'" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -934,7 +975,8 @@ "outputs": [], "source": [ "!ssh kultmost 'systemctl restart fastapi.service'" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -948,7 +990,8 @@ "outputs": [], "source": [ "!ssh kultmost 'systemctl status fastapi.service'" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -986,7 +1029,8 @@ "EOF\n", "\n", "ssh kultmost 'systemctl daemon-reload && systemctl enable --now vk-celery.service && systemctl status --no-pager -l vk-celery.service'\n" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -1000,7 +1044,8 @@ "outputs": [], "source": [ "!ssh kultmost 'systemctl restart vk-celery.service'" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -1014,7 +1059,8 @@ "outputs": [], "source": [ "!ssh kultmost 'systemctl status vk-celery.service'" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -1044,7 +1090,8 @@ "EOF\n", "\n", "ssh kultmost 'systemctl daemon-reload && systemctl enable --now email-celery.service && systemctl status --no-pager -l email-celery.service'\n" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -1058,7 +1105,8 @@ "outputs": [], "source": [ "!ssh kultmost 'systemctl restart email-celery.service'" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -1072,7 +1120,8 @@ "outputs": [], "source": [ "!ssh kultmost 'systemctl status email-celery.service'" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -1094,7 +1143,8 @@ "outputs": [], "source": [ "# !scp kultmost:/etc/nginx/sites-enabled/default nginx_conf " - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -1110,7 +1160,8 @@ "!scp nginx_conf kultmost:/tmp/default\n", "!ssh kultmost 'sudo mv /tmp/default /etc/nginx/sites-enabled/default'\n", "!ssh kultmost 'nginx -t'" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -1124,7 +1175,8 @@ "outputs": [], "source": [ "!ssh kultmost 'nginx -s reload'" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -1149,7 +1201,8 @@ "sudo usermod -a -G microk8s $USER\n", "newgrp microk8s\n", "microk8s status" - ] + ], + "display_name": ".venv" }, { "cell_type": "code", @@ -1165,7 +1218,8 @@ "curl -LO https://cert-manager.io/public-keys/cert-manager-keyring-2021-09-20-1020CF3C033D4F35BAE1C19E1226061C665DF13E.gpg\n", "helm install cert-manager oci://quay.io/jetstack/charts/cert-manager --version v1.20.2 --namespace cert-manager --create-namespace --verify --keyring ./cert-manager-keyring-2021-09-20-1020CF3C033D4F35BAE1C19E1226061C665DF13E.gpg --set crds.enabled=true\n", "microk8s helm install cert-manager oci://quay.io/jetstack/charts/cert-manager --version v1.20.2 --namespace cert-manager --create-namespace --verify --keyring ./cert-manager-keyring-2021-09-20-1020CF3C033D4F35BAE1C19E1226061C665DF13E.gpg --set crds.enabled=true" - ] + ], + "display_name": ".venv" }, { "cell_type": "markdown", @@ -1186,6 +1240,16 @@ }, "outputs": [], "source": [ + "// MIT License\n", + "\n", + "// Copyright (c) 2026 vladislav\n", + "\n", + "// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n", + "\n", + "// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n", + "\n", + "// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", + "\n", "m1 = figma.currentPage.children[0]\n", "HTML_TAGS = new Set(['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr']);\n", "\n", @@ -1386,7 +1450,8 @@ "\n", "sss = await element_create(pc, tablet, mob)\n", "sss.innerHTML" - ] + ], + "display_name": ".venv" } ], "metadata": { From 2d1f17d9d5e551faaad5940bcd1011de1234ec4b97e523684d0474ec2e2434a0 Mon Sep 17 00:00:00 2001 From: vladislav Date: Wed, 26 Aug 2026 10:58:58 -0400 Subject: [PATCH 4/9] feat --- main.ipynb | 53 +++++++++++++++++++++++++--- main.py | 42 ++++++++++++++++++++-- templates/competition/card.html | 1 + templates/competition/edit.html | 7 ++-- templates/form/competition_edit.html | 2 +- templates/profile/delivery_old.html | 7 ++-- 6 files changed, 96 insertions(+), 16 deletions(-) diff --git a/main.ipynb b/main.ipynb index ab076f3..6d16049 100644 --- a/main.ipynb +++ b/main.ipynb @@ -2903,7 +2903,7 @@ " competition = await competitions_col.find_one({'_id': ObjectId(competition_id)})\n", " data = json.dumps(competition, cls=MongoJSONEncoder, ensure_ascii=False)\n", " return templates.TemplateResponse(\n", - " request=request, name=\"form/competition_edit.html\", context={\"competition\": str(data), \"user\": user}\n", + " request=request, name=\"form/competition_edit.html\", context={\"competition\": str(data), \"competition_id\": competition_id, \"user\": user}\n", " )\n" ], "display_name": ".venv" @@ -4554,6 +4554,48 @@ "id": "6157e497", "metadata": {}, "outputs": [], + "source": [ + "# @app.get('/profile/delivery/{type_d}/{item_id}')\n", + "# async def profile_delivery_by_old(request: Request, type_d:str, item_id:str, user: Dict = Security(get_current_user)):\n", + "# cursor = delivery_collection.aggregate([\n", + "# {\"$match\": {\n", + "# \"$or\": [\n", + "# {\"sender._id\": user.get('_id')},\n", + "# {\"user._id\": user.get('_id')},\n", + "# {\"receiver._id\": user.get('_id')}\n", + "# ],\n", + "# f'{type_d}_id': ObjectId(item_id),\n", + "# 'prod': PROD,\n", + "# }},\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", + "\n", + "# data = [doc async for doc in cursor]\n", + "# data.sort(key=lambda doc: doc[\"_id\"].generation_time, reverse=True)\n", + "\n", + "# return templates.TemplateResponse(\n", + "# request=request,\n", + "# name=\"profile/delivery_old.html\",\n", + "# context={\n", + "# \"user\": user,\n", + "# \"data\": data,\n", + "# }\n", + "# )\n" + ], + "display_name": ".venv" + }, + { + "cell_type": "code", + "execution_count": null, + "id": "089ba597", + "metadata": {}, + "outputs": [], "source": [ "@app.get('/profile/delivery/competition/{competition_id}')\n", "async def profile_delivery_by_competition(request: Request, competition_id:str, user: Dict = Security(get_current_user)):\n", @@ -4564,7 +4606,6 @@ " {\"user._id\": user.get('_id')},\n", " {\"receiver._id\": user.get('_id')}\n", " ],\n", - " 'competition_id': ObjectId(competition_id),\n", " 'prod': PROD,\n", " }},\n", " {\"$sort\": {\"_id\": -1}},\n", @@ -4577,6 +4618,8 @@ " ])\n", "\n", " data = [doc async for doc in cursor]\n", + " data.sort(key=lambda doc: doc[\"_id\"].generation_time, reverse=True)\n", + "\n", " return templates.TemplateResponse(\n", " request=request,\n", " name=\"profile/delivery_old.html\",\n", @@ -4591,7 +4634,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d68edb20", + "id": "2148ef21", "metadata": {}, "outputs": [], "source": [ @@ -4617,6 +4660,8 @@ " ])\n", "\n", " data = [doc async for doc in cursor]\n", + " data.sort(key=lambda doc: doc[\"_id\"].generation_time, reverse=True)\n", + "\n", " return templates.TemplateResponse(\n", " request=request,\n", " name=\"profile/delivery_old.html\",\n", @@ -4624,7 +4669,7 @@ " \"user\": user,\n", " \"data\": data,\n", " }\n", - " )\n" + " )" ], "display_name": ".venv" }, diff --git a/main.py b/main.py index 0df7ac5..63c05e7 100644 --- a/main.py +++ b/main.py @@ -2162,7 +2162,7 @@ async def form_( competition = await competitions_col.find_one({'_id': ObjectId(competition_id)}) data = json.dumps(competition, cls=MongoJSONEncoder, ensure_ascii=False) return templates.TemplateResponse( - request=request, name="form/competition_edit.html", context={"competition": str(data), "user": user} + request=request, name="form/competition_edit.html", context={"competition": str(data), "competition_id": competition_id, "user": user} ) @@ -3459,6 +3459,40 @@ async def profile_delivery_history_post(request: Request, post_id:str, user: Dic ) +# @app.get('/profile/delivery/{type_d}/{item_id}') +# async def profile_delivery_by_old(request: Request, type_d:str, item_id:str, user: Dict = Security(get_current_user)): +# cursor = delivery_collection.aggregate([ +# {"$match": { +# "$or": [ +# {"sender._id": user.get('_id')}, +# {"user._id": user.get('_id')}, +# {"receiver._id": user.get('_id')} +# ], +# f'{type_d}_id': ObjectId(item_id), +# 'prod': PROD, +# }}, +# {"$sort": {"_id": -1}}, +# {"$group": { +# "_id": "$post_id", +# "doc": {"$first": "$$ROOT"} +# }}, +# {"$replaceRoot": {"newRoot": "$doc"}}, +# {"$sort": {"_id": -1}}, +# ]) + +# data = [doc async for doc in cursor] +# data.sort(key=lambda doc: doc["_id"].generation_time, reverse=True) + +# return templates.TemplateResponse( +# request=request, +# name="profile/delivery_old.html", +# context={ +# "user": user, +# "data": data, +# } +# ) + + @app.get('/profile/delivery/competition/{competition_id}') async def profile_delivery_by_competition(request: Request, competition_id:str, user: Dict = Security(get_current_user)): cursor = delivery_collection.aggregate([ @@ -3468,7 +3502,6 @@ async def profile_delivery_by_competition(request: Request, competition_id:str, {"user._id": user.get('_id')}, {"receiver._id": user.get('_id')} ], - 'competition_id': ObjectId(competition_id), 'prod': PROD, }}, {"$sort": {"_id": -1}}, @@ -3481,6 +3514,8 @@ async def profile_delivery_by_competition(request: Request, competition_id:str, ]) data = [doc async for doc in cursor] + data.sort(key=lambda doc: doc["_id"].generation_time, reverse=True) + return templates.TemplateResponse( request=request, name="profile/delivery_old.html", @@ -3513,6 +3548,8 @@ async def profile_delivery_by_exhibition(request: Request, exhibition_id:str, us ]) data = [doc async for doc in cursor] + data.sort(key=lambda doc: doc["_id"].generation_time, reverse=True) + return templates.TemplateResponse( request=request, name="profile/delivery_old.html", @@ -3522,7 +3559,6 @@ async def profile_delivery_by_exhibition(request: Request, exhibition_id:str, us } ) - @app.get( "/profile/delivery", response_class=HTMLResponse, diff --git a/templates/competition/card.html b/templates/competition/card.html index 404e231..795b156 100644 --- a/templates/competition/card.html +++ b/templates/competition/card.html @@ -31,6 +31,7 @@ {{ {-1:'Формируется',0:'Прием заявок',1:'Идет отбор',2:'Закончился'}[competition.get('status',-1)] }}
{% endif %} + До {{ (competition.date_finish.strftime('%d.%m.%Y')) if competition.date_finish else ''}}

{{ competition.title }}

diff --git a/templates/competition/edit.html b/templates/competition/edit.html index 823034a..8b0f687 100644 --- a/templates/competition/edit.html +++ b/templates/competition/edit.html @@ -1,7 +1,7 @@ {% import "competition/list.html" as competition %} {% import "components/checkbox.html" as checkbox %} -{% macro section(user, competition) -%} +{% macro section(user, competition, competition_id) -%}

Выбор

@@ -346,7 +346,7 @@ function bindLinkValidation({ -
From 28cf129e1112ec111a8692ea5d2a7d0c731057e6dfa70c59e9074916be2066af Mon Sep 17 00:00:00 2001 From: vladislav Date: Thu, 27 Aug 2026 08:39:48 -0400 Subject: [PATCH 6/9] feat --- delivery_router.py | 183 +++++++----- models.py | 10 +- templates/profile/delivery_old.html | 283 ++++++++++++------- templates/profile/invitation.html | 323 +++++++++++++++------- templates/profile/partner/exhibition.html | 11 +- 5 files changed, 531 insertions(+), 279 deletions(-) diff --git a/delivery_router.py b/delivery_router.py index c3ab5f9..e9bea1e 100644 --- a/delivery_router.py +++ b/delivery_router.py @@ -17,56 +17,69 @@ async def send_delivery( current_user: dict = Depends(get_current_user) ): """ - Создаёт новый документ отправки с обновлёнными статусом и полями. + Массовая отправка: создаёт новый документ для каждого выбранного item. """ - # Проверяем, что текущий пользователь — отправитель - if str(current_user["_id"]) != payload.sender: - raise HTTPException(status_code=403, detail="Не авторизован как отправитель") + results = [] + errors = [] - # Валидация delivery_id - try: - delivery_id = ObjectId(payload.item) - except Exception: - raise HTTPException(status_code=400, detail="Неверный delivery ID") + for entry in payload.items: + # Проверяем, что текущий пользователь — отправитель + if str(current_user["_id"]) != entry.sender: + errors.append({"item": entry.item, "error": "Не авторизован как отправитель"}) + continue - update_data = { - "status": "Ожидает получения", - "delivery_type": payload.delivery_type, - "sent_at": datetime.utcnow(), - "updated_at": datetime.utcnow() + # Валидация delivery_id + try: + delivery_id = ObjectId(entry.item) + except Exception: + errors.append({"item": entry.item, "error": "Неверный delivery ID"}) + continue + + update_data = { + "status": "Ожидает получения", + "delivery_type": payload.delivery_type, + "sent_at": datetime.utcnow(), + "updated_at": datetime.utcnow(), + } + + # Добавляем трек только для СДЭК + if payload.delivery_type == "СДЭК" and payload.track: + update_data["track"] = payload.track + + # Ищем существующую запись + existing = await delivery_collection.find_one( + {"_id": delivery_id, "sender._id": entry.sender}, + {"_id": 0} + ) + if not existing: + errors.append({"item": entry.item, "error": "Доставка не найдена или не для вас"}) + continue + + # Уведомление получателю + notify = await notify_in_profile(NotifyItem( + user_id=str(existing["receiver"]["_id"]), + type_item="delivery", + title="Доставка картин", + link="/profile/delivery", + text=f"{str(existing['sender']['username'])} — прислал вам картины." + )) + + new_doc = {**existing, **update_data, "notify": notify.upserted_id} + + result = await delivery_collection.insert_one(new_doc) + if result.inserted_id: + # TODO: send email + results.append({ + "item": entry.item, + "delivery_id": str(result.inserted_id) + }) + + return { + "status": "success" if not errors else "partial", + "processed": results, + "errors": errors } - # Добавляем трек только для СДЭК (если передан) - if payload.delivery_type == "СДЭК" and payload.track: - update_data["track"] = payload.track - - # Ищем существующую запись, чтобы создать новую на её основе - existing = await delivery_collection.find_one( - {"_id": delivery_id, "sender._id": payload.sender}, - {"_id": 0} - ) - - if not existing: - raise HTTPException(status_code=404, detail="Доставка не найдена или не для вас") - - # Собираем новый документ для вставки - notify = await notify_in_profile(NotifyItem( - user_id=str(existing['receiver']['_id']), - type_item='delivery', - title='Доставка картин', - link=f'/profile/delivery', - text=f'{str(existing['sender']['username'])} — прислал вам картины.' - )) - new_doc = {**existing, **update_data, 'notify':notify.upserted_id} - - # Вставляем новый документ - result = await delivery_collection.insert_one(new_doc) - if (iserted_id:=result.inserted_id): - pass - # send email - - return {"status": "success", "delivery_id": str(iserted_id)} - @router.post("/accept") async def accept_delivery( @@ -74,37 +87,59 @@ async def accept_delivery( current_user: dict = Depends(get_current_user) ): """ - Создаёт новый документ отправки со статусом 'Получено'. + Массовое получение: создаёт новый документ со статусом 'Получено' для каждого item. """ - try: - delivery_id = ObjectId(payload.item) - except Exception: - raise HTTPException(status_code=400, detail="Неверный delivery ID") + results = [] + errors = [] - # Берём исходный документ, чтобы вставить новый - existing = await delivery_collection.find_one( - {"_id": delivery_id, "receiver._id": current_user["_id"]}, - {"_id": 0} - ) + for item_id in payload.items: + try: + delivery_id = ObjectId(item_id) + except Exception: + errors.append({"item": item_id, "error": "Неверный delivery ID"}) + continue - if not existing: - raise HTTPException(status_code=404, detail="Доставка не найдена или не для вас") - notify = await notify_in_profile(NotifyItem( - user_id=str(existing['sender']['_id']), - type_item='delivery', - title='Доставка картин', - link=f'/profile/delivery', - text=f'Картина «{existing['title']}» получена — {str(existing['receiver']['username'])}.' - )) - new_doc = { - **existing, - "status": "Получено", - "notify": notify.upserted_id, - "received_at": datetime.utcnow(), - "updated_at": datetime.utcnow(), - } + existing = await delivery_collection.find_one( + {"_id": delivery_id, "receiver._id": current_user["_id"]}, + {"_id": 0} + ) + if not existing: + errors.append({"item": item_id, "error": "Доставка не найдена или не для вас"}) + continue - result = await delivery_collection.insert_one(new_doc) + # Уведомление отправителю + notify = await notify_in_profile(NotifyItem( + user_id=str(existing["sender"]["_id"]), + type_item="delivery", + title="Доставка картин", + link="/profile/delivery", + text=f"Картина «{existing['title']}» получена — {str(existing['receiver']['username'])}." + )) - await notify_collection.update_one({'_id': existing['notify']}, {'$set': {'read': False}}) - return {"status": "success", "delivery_id": str(result.inserted_id)} + new_doc = { + **existing, + "status": "Получено", + "notify": notify.upserted_id, + "received_at": datetime.utcnow(), + "updated_at": datetime.utcnow(), + } + + result = await delivery_collection.insert_one(new_doc) + + # Помечаем предыдущее уведомление как непрочитанное (если нужно) + if existing.get("notify"): + await notify_collection.update_one( + {"_id": existing["notify"]}, + {"$set": {"read": False}} + ) + + results.append({ + "item": item_id, + "delivery_id": str(result.inserted_id) + }) + + return { + "status": "success" if not errors else "partial", + "processed": results, + "errors": errors + } \ No newline at end of file diff --git a/models.py b/models.py index 0f71e19..09c00fe 100644 --- a/models.py +++ b/models.py @@ -14,16 +14,20 @@ class NotifyItem(BaseModel): type_item: str = "c" -class DeliverySendRequest(BaseModel): +class DeliverySendItem(BaseModel): + item: str sender: str too: str - item: str + + +class DeliverySendRequest(BaseModel): + items: List[DeliverySendItem] delivery_type: Literal["СДЭК", "Самостоятельно"] track: Optional[str] = Field(None, description="Трэк-номер для СДЭК") class DeliveryAcceptRequest(BaseModel): - item: str + items: List[str] class UserRegister(BaseModel): diff --git a/templates/profile/delivery_old.html b/templates/profile/delivery_old.html index 28f80a1..3efbb09 100644 --- a/templates/profile/delivery_old.html +++ b/templates/profile/delivery_old.html @@ -154,9 +154,10 @@ Получить выбранные - {% endif %} diff --git a/templates/profile/partner/exhibition.html b/templates/profile/partner/exhibition.html index b7622b9..02d1704 100644 --- a/templates/profile/partner/exhibition.html +++ b/templates/profile/partner/exhibition.html @@ -98,9 +98,10 @@ {% endif %} {% if post.status == 'Ожидает получения' %} - #} + Получить - + {% endif %} {% if post.status in ['Возврат художнику']%} @@ -114,8 +115,9 @@ +{# +#} + +