This commit is contained in:
vladislav 2026-09-01 11:15:50 -04:00
parent 58316d87ec
commit d84fb01ad8
Signed by: Vladislav
GPG Key ID: D97C9E5E4860EE45
4 changed files with 111 additions and 5 deletions

View File

@ -3225,6 +3225,23 @@
], ],
"display_name": ".venv" "display_name": ".venv"
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "8feec4b3",
"metadata": {},
"outputs": [],
"source": [
"@app.put(\"/api/post/{post_id}/sale\", response_model=dict)\n",
"async def sale_painting(\n",
" post_id: str,\n",
" current_user: Dict = Security(get_current_user, scopes=[\"create:posts\"])\n",
" ):\n",
" await posts_collection.update_one({'_id': ObjectId(post_id), 'user._id': current_user.get('_id')}, {'$set': {\"status\": \"Продано\"}})\n",
" return {'ok': True}"
],
"display_name": ".venv"
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -4951,7 +4968,7 @@
" d_posts = await delivery_collection.find({'post_id':{'$in':[str(i.get('_id')) for i in posts]}}).to_list()\n", " d_posts = await delivery_collection.find({'post_id':{'$in':[str(i.get('_id')) for i in posts]}}).to_list()\n",
" for post in posts:\n", " for post in posts:\n",
" for doc in d_posts:\n", " for doc in d_posts:\n",
" if str(post.get('_id')) == doc.get('post_id') and doc.get('receiver') and doc.get('receiver').get('_id') == str(user.get('_id')):\n", " if str(post.get('_id')) == doc.get('post_id') and post.get('status') != 'Продано' and doc.get('receiver') and doc.get('receiver').get('_id') == str(user.get('_id')):\n",
" post.update({'status':doc.get('status'), 'receiver': doc.get('receiver'), 'd_id':doc.get('_id')})\n", " post.update({'status':doc.get('status'), 'receiver': doc.get('receiver'), 'd_id':doc.get('_id')})\n",
" return templates.TemplateResponse(\n", " return templates.TemplateResponse(\n",
" request=request, name=\"profile/partner/exhibition catalog.html\", context={\"now\": datetime.now(), \"user\": user, \"galerists\": galerists, \"genres\": genres, \"living_places\": living_places, \"exhibition\": exhibition, \"posts\": posts}\n", " request=request, name=\"profile/partner/exhibition catalog.html\", context={\"now\": datetime.now(), \"user\": user, \"galerists\": galerists, \"genres\": genres, \"living_places\": living_places, \"exhibition\": exhibition, \"posts\": posts}\n",
@ -4978,7 +4995,7 @@
" d_posts = await delivery_collection.find({'post_id':{'$in':[str(i.get('_id')) for i in posts]}}).to_list()\n", " d_posts = await delivery_collection.find({'post_id':{'$in':[str(i.get('_id')) for i in posts]}}).to_list()\n",
" for post in posts:\n", " for post in posts:\n",
" for doc in d_posts:\n", " for doc in d_posts:\n",
" if str(post.get('_id')) == doc.get('post_id') and doc.get('receiver') and doc.get('receiver').get('_id') == str(user.get('_id')):\n", " if str(post.get('_id')) == doc.get('post_id') and post.get('status') != 'Продано' and doc.get('receiver') and doc.get('receiver').get('_id') == str(user.get('_id')):\n",
" post.update({'status':doc.get('status'), 'receiver': doc.get('receiver'), 'd_id':doc.get('_id')})\n", " post.update({'status':doc.get('status'), 'receiver': doc.get('receiver'), 'd_id':doc.get('_id')})\n",
" return templates.TemplateResponse(\n", " return templates.TemplateResponse(\n",
" request=request, name=\"profile/partner/exhibition.html\", context={\"now\": datetime.now(), \"user\": user, \"exhibition\": exhibition, \"posts\": posts}\n", " request=request, name=\"profile/partner/exhibition.html\", context={\"now\": datetime.now(), \"user\": user, \"exhibition\": exhibition, \"posts\": posts}\n",

12
main.py
View File

@ -2398,6 +2398,14 @@ async def post_painting(
raise HTTPException(status_code=500, detail=str(e)) raise HTTPException(status_code=500, detail=str(e))
@app.put("/api/post/{post_id}/sale", response_model=dict)
async def sale_painting(
post_id: str,
current_user: Dict = Security(get_current_user, scopes=["create:posts"])
):
await posts_collection.update_one({'_id': ObjectId(post_id), 'user._id': current_user.get('_id')}, {'$set': {"status": "Продано"}})
return {'ok': True}
@app.put("/api/post/{post_id}", response_model=dict) @app.put("/api/post/{post_id}", response_model=dict)
async def put_painting( async def put_painting(
background_tasks: BackgroundTasks, background_tasks: BackgroundTasks,
@ -3805,7 +3813,7 @@ async def profile_partner_exhibitions_catalog(
d_posts = await delivery_collection.find({'post_id':{'$in':[str(i.get('_id')) for i in posts]}}).to_list() d_posts = await delivery_collection.find({'post_id':{'$in':[str(i.get('_id')) for i in posts]}}).to_list()
for post in posts: for post in posts:
for doc in d_posts: for doc in d_posts:
if str(post.get('_id')) == doc.get('post_id') and doc.get('receiver') and doc.get('receiver').get('_id') == str(user.get('_id')): if str(post.get('_id')) == doc.get('post_id') and post.get('status') != 'Продано' and doc.get('receiver') and doc.get('receiver').get('_id') == str(user.get('_id')):
post.update({'status':doc.get('status'), 'receiver': doc.get('receiver'), 'd_id':doc.get('_id')}) post.update({'status':doc.get('status'), 'receiver': doc.get('receiver'), 'd_id':doc.get('_id')})
return templates.TemplateResponse( return templates.TemplateResponse(
request=request, name="profile/partner/exhibition catalog.html", context={"now": datetime.now(), "user": user, "galerists": galerists, "genres": genres, "living_places": living_places, "exhibition": exhibition, "posts": posts} request=request, name="profile/partner/exhibition catalog.html", context={"now": datetime.now(), "user": user, "galerists": galerists, "genres": genres, "living_places": living_places, "exhibition": exhibition, "posts": posts}
@ -3824,7 +3832,7 @@ async def profile_partner_exhibitions(
d_posts = await delivery_collection.find({'post_id':{'$in':[str(i.get('_id')) for i in posts]}}).to_list() d_posts = await delivery_collection.find({'post_id':{'$in':[str(i.get('_id')) for i in posts]}}).to_list()
for post in posts: for post in posts:
for doc in d_posts: for doc in d_posts:
if str(post.get('_id')) == doc.get('post_id') and doc.get('receiver') and doc.get('receiver').get('_id') == str(user.get('_id')): if str(post.get('_id')) == doc.get('post_id') and post.get('status') != 'Продано' and doc.get('receiver') and doc.get('receiver').get('_id') == str(user.get('_id')):
post.update({'status':doc.get('status'), 'receiver': doc.get('receiver'), 'd_id':doc.get('_id')}) post.update({'status':doc.get('status'), 'receiver': doc.get('receiver'), 'd_id':doc.get('_id')})
return templates.TemplateResponse( return templates.TemplateResponse(
request=request, name="profile/partner/exhibition.html", context={"now": datetime.now(), "user": user, "exhibition": exhibition, "posts": posts} request=request, name="profile/partner/exhibition.html", context={"now": datetime.now(), "user": user, "exhibition": exhibition, "posts": posts}

View File

@ -95,6 +95,15 @@
<header class="c_zjvne b_tt84a"> <header class="c_zjvne b_tt84a">
<h2 class="c_6kn8d b_uilob">{{post.title}}</h2> <h2 class="c_6kn8d b_uilob">{{post.title}}</h2>
</header> </header>
<label class="offer-label delivery-checkbox-label">
<input type="checkbox"
onchange="saledPaintings('{{doc._id}}')"
class="offer-checkbox delivery-checkbox send-checkbox"
data-id="{{doc._id}}"
data-sender="{{doc.sender._id}}"
data-receiver="{{doc.receiver._id}}">
<span>Продано</span>
</label>
<div class="b_xz6em" ><img class="b_ob59y" src="/a/{{post.user._id}}" crossorigin="anonymous" fetchpriority="high" loading="eager"> <div class="b_xz6em" ><img class="b_ob59y" src="/a/{{post.user._id}}" crossorigin="anonymous" fetchpriority="high" loading="eager">
<div class="c_9hjdk b_ffruz"> <div class="c_9hjdk b_ffruz">
<p class="b_qla2q">{{post.city or ''}}</p> <p class="b_qla2q">{{post.city or ''}}</p>
@ -109,7 +118,38 @@
{% endfor %} {% endfor %}
</div> </div>
<script>
function saledPaintings(postId) {
fetch(`/api/post/${postId}/sale`, {
method: 'PUT'
})
.then(response => {
if (response.ok) {
// Find and delete the parent figure
const postElement = document.querySelector(`figure[data-postId='${postId}']`);
showToast({
message: 'Сохранено!',
status: 'info',
duration: 1200
});
} else {
showToast({
message: 'Ошибка соединения с сервером!',
status: 'error',
duration: 2500
});
}
})
.catch(error => {
// Handle network errors
showToast({
message: 'Ошибка соединения с сервером!',
status: 'error',
duration: 2500
});
});
}
</script>
<script> <script>
(function(){ (function(){
const input = document.getElementById('memberSearch'); const input = document.getElementById('memberSearch');

View File

@ -75,6 +75,15 @@
<header class="c_m876y b_9xtz9"> <header class="c_m876y b_9xtz9">
<h3 class="c_hysjg b_8f3uh" id="preview_title">{{post.title}}</h3> <h3 class="c_hysjg b_8f3uh" id="preview_title">{{post.title}}</h3>
</header> </header>
<label class="offer-label delivery-checkbox-label">
<input type="checkbox"
onchange="saledPaintings('{{doc._id}}')"
class="offer-checkbox delivery-checkbox send-checkbox"
data-id="{{doc._id}}"
data-sender="{{doc.sender._id}}"
data-receiver="{{doc.receiver._id}}">
<span>Продано</span>
</label>
{% if post.status=='В каталоге' %} {% if post.status=='В каталоге' %}
<div class="l_green"><span>{{post.status}}</span></div> <div class="l_green"><span>{{post.status}}</span></div>
{% else %} {% else %}
@ -115,6 +124,38 @@
</div> </div>
</div> </div>
</section> </section>
<script>
function saledPaintings(postId) {
fetch(`/api/post/${postId}/sale`, {
method: 'PUT'
})
.then(response => {
if (response.ok) {
// Find and delete the parent figure
const postElement = document.querySelector(`figure[data-postId='${postId}']`);
showToast({
message: 'Сохранено!',
status: 'info',
duration: 1200
});
} else {
showToast({
message: 'Ошибка соединения с сервером!',
status: 'error',
duration: 2500
});
}
})
.catch(error => {
// Handle network errors
showToast({
message: 'Ошибка соединения с сервером!',
status: 'error',
duration: 2500
});
});
}
</script>
{# {#
<script> <script>
async function btnAccept(btn, itemId){ async function btnAccept(btn, itemId){