Skip to content

Commit

Permalink
Allow for deletion for posters
Browse files Browse the repository at this point in the history
  • Loading branch information
noahpistilli committed Oct 2, 2023
1 parent 0bdf1f3 commit b78b82b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions asset_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion templates/poster_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</p>

<p class="control">
<a href="" class="button is-danger">
<a href="{{ url_for('remove_poster', poster=poster.poster_id) }}" class="button is-danger">
<span class="icon is-small">
<i class="fas fa-trash"></i>
</span>
Expand Down
15 changes: 15 additions & 0 deletions theunderground/posters.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -44,6 +45,20 @@ def add_poster():
return render_template("poster_add.html", form=form)


@app.route("/theunderground/posters/<poster>/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/<poster>/thumbnail.jpg")
@login_required
def get_poster(poster):
Expand Down

0 comments on commit b78b82b

Please sign in to comment.