Fixed front ann book and delete err handling

Button no longer pre-updates on err
File uploading fix
This commit is contained in:
2023-09-13 22:26:53 +03:00
parent a60ff39c43
commit 2b001579c5
4 changed files with 10 additions and 6 deletions

View File

@ -89,7 +89,7 @@ async def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form(
if f.tell() > 0:
f.seek(0)
destination = pathlib.Path("./uploads/" + str(hash(f)) + pathlib.Path(src.filename).suffix.lower())
async with destination.open('wb') as buffer:
with destination.open('wb') as buffer:
shutil.copyfileobj(f, buffer)
# изменяем название директории загруженного файла
@ -103,6 +103,8 @@ async def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form(
db.add(temp_ancmt) # добавляем в бд
await db.commit() # сохраняем изменения
await db.refresh(temp_ancmt) # обновляем состояние объекта
return {"Success": True}
except:
raise HTTPException(status_code=500, detail="problem with adding object to db")
@ -119,6 +121,8 @@ async def delete_from_db(announcement: pydantic_schemas.DelAnnouncement, db: Ann
try:
await db.delete(to_delete) # удаление из БД
await db.commit() # сохраняем изменения
return {"Success": True}
except:
raise HTTPException(status_code=500, detail="Problem with adding to database")