From c5239fcc433edb00bd622d56c584fd985dcab2ec Mon Sep 17 00:00:00 2001 From: Sketch <75850871+SketchMaster2001@users.noreply.github.com> Date: Sun, 30 Jun 2024 09:51:32 -0400 Subject: [PATCH] feat: Allow for editing of Posters --- .../{poster_add.html => poster_action.html} | 8 +++- templates/poster_list.html | 9 ++++ theunderground/forms.py | 2 +- theunderground/posters.py | 42 ++++++++++++++++++- 4 files changed, 57 insertions(+), 4 deletions(-) rename templates/{poster_add.html => poster_action.html} (72%) diff --git a/templates/poster_add.html b/templates/poster_action.html similarity index 72% rename from templates/poster_add.html rename to templates/poster_action.html index c0264257..79c34414 100644 --- a/templates/poster_add.html +++ b/templates/poster_action.html @@ -1,7 +1,7 @@ {% extends "generic/base.html" %} {% block title %} - Upload a Movie + {{ action }} a Movie {% endblock %} {% block content %} @@ -17,7 +17,11 @@ {{ form.movie_id.label(class_="label") }} {{ form.movie_id(class_="input") }}

- {{ form.poster.label(class_="label") }} {{ form.poster(size=32) }} + {{ form.poster.label(class_="label") }} + {% if poster_id %} + {{ existing_image('poster', url_for('get_poster', poster=poster_id)) }} + {% endif %} + {{ form.poster(size=32) }}


{{ form.upload(class_="button is-success") }}

diff --git a/templates/poster_list.html b/templates/poster_list.html index 256f3817..495603e0 100644 --- a/templates/poster_list.html +++ b/templates/poster_list.html @@ -30,6 +30,15 @@ {{ poster.movie_id }}
+

+ + + + + Edit Poster + +

+

diff --git a/theunderground/forms.py b/theunderground/forms.py index 0a630055..ad554584 100644 --- a/theunderground/forms.py +++ b/theunderground/forms.py @@ -193,7 +193,7 @@ class PosterForm(FlaskForm): title = StringField("Title", validators=[DataRequired(), Length(max=47)]) msg = StringField("Message", validators=[DataRequired(), Length(max=15)]) movie_id = IntegerField("Movie ID", validators=[DataRequired()]) - poster = FileField("Poster", validators=[FileRequired()]) + poster = FileField("Poster") upload = SubmitField("Create Poster!") diff --git a/theunderground/posters.py b/theunderground/posters.py index 92adf6d4..d4871a20 100644 --- a/theunderground/posters.py +++ b/theunderground/posters.py @@ -1,6 +1,7 @@ from io import BytesIO from flask import render_template, flash, url_for, redirect +from werkzeug import exceptions from theunderground.forms import PosterForm from theunderground.operations import manage_delete_item @@ -9,6 +10,7 @@ from models import Posters, db from room import app, s3 from url1.event_today import event_today +from flask_wtf.file import FileRequired import config @@ -30,6 +32,7 @@ def list_posters(): @oidc.require_login def add_poster(): form = PosterForm() + form.poster.validators = [FileRequired()] if form.validate_on_submit(): db_poster = Posters( @@ -52,7 +55,44 @@ def add_poster(): return redirect(url_for("list_posters")) - return render_template("poster_add.html", form=form) + return render_template("poster_action.html", form=form, action="Upload") + + +@app.route("/theunderground/movies/poster//edit", methods=["GET", "POST"]) +@oidc.require_login +def edit_poster(poster_id): + form = PosterForm() + + poster = Posters.query.filter_by(poster_id=poster_id).first() + if not poster: + return exceptions.NotFound() + + if form.validate_on_submit(): + poster.title = form.title.data + poster.msg = form.msg.data + poster.movie_id = form.movie_id.data + + if form.poster.data: + # Now upload poster + PosterAsset(poster_id, False).encode(form.poster) + + # Commit before uploading to s3 + db.session.commit() + if s3: + event_xml = event_today() + s3.upload_fileobj( + BytesIO(event_xml), config.r2_bucket_name, "event/today.xml" + ) + + return redirect(url_for("list_posters")) + else: + form.title.data = poster.title + form.msg.data = poster.msg + form.movie_id.data = poster.movie_id + + return render_template( + "poster_action.html", form=form, poster_id=poster_id, action="Edit" + ) @app.route("/theunderground/posters//remove", methods=["GET", "POST"])