mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-01-23 17:26:26 +01:00
Delete attachments when deleting a partition
This commit is contained in:
parent
f8670f4901
commit
3b08f2e08c
@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from ..db import get_db
|
||||
@ -29,5 +31,18 @@ class Attachment():
|
||||
self.filetype = data["filetype"]
|
||||
self.partition_uuid = data["partition_uuid"]
|
||||
|
||||
def delete(self):
|
||||
db = get_db()
|
||||
db.execute(
|
||||
"""
|
||||
DELETE FROM attachments
|
||||
WHERE uuid = ?
|
||||
""",
|
||||
(self.uuid,)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
os.remove(f"partitioncloud/attachments/{self.uuid}.{self.filetype}")
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.name}.{self.filetype}"
|
@ -31,6 +31,8 @@ class Partition():
|
||||
raise LookupError
|
||||
|
||||
def delete(self):
|
||||
self.load_attachments()
|
||||
|
||||
db = get_db()
|
||||
db.execute(
|
||||
"""
|
||||
@ -45,7 +47,7 @@ class Partition():
|
||||
if os.path.exists(f"partitioncloud/static/thumbnails/{self.uuid}.jpg"):
|
||||
os.remove(f"partitioncloud/static/thumbnails/{self.uuid}.jpg")
|
||||
|
||||
partitions = db.execute(
|
||||
db.execute(
|
||||
"""
|
||||
DELETE FROM partition
|
||||
WHERE uuid = ?
|
||||
@ -54,6 +56,9 @@ class Partition():
|
||||
)
|
||||
db.commit()
|
||||
|
||||
for attachment in self.attachments:
|
||||
attachment.delete()
|
||||
|
||||
def update(self, name=None, author="", body=""):
|
||||
if name is None:
|
||||
return Exception("name cannot be None")
|
||||
|
Loading…
Reference in New Issue
Block a user