diff --git a/asset_data.py b/asset_data.py index 6a6df4a7..5818a37e 100644 --- a/asset_data.py +++ b/asset_data.py @@ -2,6 +2,8 @@ from typing import Union from wtforms import FileField +import os + class RoomLogoAsset(Asset): """Used for a company logo within a room.""" @@ -85,6 +87,9 @@ def __init__(self, seq: int, is_theatre: bool): self.asset_dir = self.base_asset_dir / asset_dir self.asset_name = asset_name + def delete(self): + os.remove(self.asset_path()) + class PayMovieAsset(Asset): def __init__(self, seq: int): diff --git a/templates/poster_list.html b/templates/poster_list.html index b26bfc93..40d8c7a9 100644 --- a/templates/poster_list.html +++ b/templates/poster_list.html @@ -40,7 +40,7 @@

- + diff --git a/theunderground/posters.py b/theunderground/posters.py index ed9cf61b..63272066 100644 --- a/theunderground/posters.py +++ b/theunderground/posters.py @@ -1,6 +1,7 @@ from flask import render_template, flash, url_for, redirect from flask_login import login_required from theunderground.forms import PosterForm +from theunderground.operations import manage_delete_item from asset_data import PosterAsset from models import Posters, db from room import app @@ -44,6 +45,20 @@ def add_poster(): return render_template("poster_add.html", form=form) +@app.route("/theunderground/posters//remove", methods=["GET", "POST"]) +@login_required +def remove_poster(poster: int): + def drop_poster(): + db.session.delete(Posters.query.filter_by(poster_id=poster).first()) + db.session.commit() + + PosterAsset(poster, False).delete() + + return redirect(url_for("list_posters")) + + return manage_delete_item(poster, "poster", drop_poster) + + @app.route("/theunderground/posters//thumbnail.jpg") @login_required def get_poster(poster):