Compare commits

...

3 Commits

Author SHA1 Message Date
2de234870e Fix groupe deletion (removed orphans) 2023-10-26 23:38:09 +02:00
34cae34236 Forgot this one as well 2023-10-26 14:35:09 +02:00
83b033a779 Testing a simple API 2023-10-26 14:33:06 +02:00
6 changed files with 56 additions and 13 deletions

View File

@ -131,6 +131,12 @@ def create_album():
except db.IntegrityError:
pass
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": uuid
}
else:
return redirect(f"/albums/{uuid}")
flash(error)
@ -291,6 +297,12 @@ def add_partition(album_uuid):
except db.IntegrityError:
pass
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": partition_uuid
}
else:
flash(f"Partition {request.form['name']} ajoutée")
return redirect(f"/albums/{album.uuid}")

View File

@ -2,7 +2,7 @@ import os
from ..db import get_db
from .attachment import Attachment
class Album():
def __init__(self, uuid=None, id=None):
@ -116,6 +116,18 @@ class Album():
"""
)
for partition in partitions.fetchall():
data = db.execute(
"""
SELECT * FROM attachments
WHERE partition_uuid = ?
""",
(partition["uuid"],)
)
attachments = [Attachment(data=i) for i in data]
for attachment in attachments:
attachment.delete()
os.remove(f"partitioncloud/partitions/{partition['uuid']}.pdf")
if os.path.exists(f"partitioncloud/static/thumbnails/{partition['uuid']}.jpg"):
os.remove(f"partitioncloud/static/thumbnails/{partition['uuid']}.jpg")

View File

@ -54,9 +54,9 @@ class Groupe():
"""
SELECT id FROM album
LEFT JOIN groupe_contient_album
LEFT JOIN contient_user
ON groupe_contient_album.album_id=album.id
AND contient_user.album_id=album.id
LEFT JOIN contient_user
ON contient_user.album_id=album.id
WHERE user_id IS NULL AND groupe_id IS NULL
"""
).fetchall()

View File

@ -194,15 +194,16 @@ class User():
def quit_album(self, album_uuid):
db = get_db()
album = Album(uuid=album_uuid)
db.execute(
"""
DELETE FROM contient_user
JOIN album
ON album.id = album_id
WHERE user_id = ?
AND album_id = ?
AND album.uuid = ?
""",
(self.id, album.id)
(self.id, album_uuid)
)
db.commit()

View File

@ -89,6 +89,12 @@ def create_groupe():
except db.IntegrityError:
pass
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": uuid
}
else:
return redirect(f"/groupe/{uuid}")
flash(error)
@ -201,6 +207,12 @@ def create_album(groupe_uuid):
except db.IntegrityError:
pass
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": uuid
}
else:
return redirect(f"/groupe/{groupe.uuid}/{uuid}")
flash(error)

View File

@ -100,6 +100,12 @@ def add_attachment(uuid):
pass
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": attachment_uuid
}
else:
return redirect(f"/partition/{partition.uuid}/attachments")