Skip to content

Commit

Permalink
feat: Allow for editing of Posters
Browse files Browse the repository at this point in the history
  • Loading branch information
noahpistilli committed Jun 30, 2024
1 parent 153ac12 commit c5239fc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
8 changes: 6 additions & 2 deletions templates/poster_add.html → templates/poster_action.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "generic/base.html" %}

{% block title %}
Upload a Movie
{{ action }} a Movie
{% endblock %}

{% block content %}
Expand All @@ -17,7 +17,11 @@
{{ form.movie_id.label(class_="label") }} {{ form.movie_id(class_="input") }}
<br>
<br>
{{ 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) }}
</p>
<br>
<p>{{ form.upload(class_="button is-success") }}</p>
Expand Down
9 changes: 9 additions & 0 deletions templates/poster_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
<td>{{ poster.movie_id }}</td>
<td>
<div class="field has-addons">
<p class="control">
<a href="{{ url_for('edit_poster', poster_id=poster.poster_id) }}" class="button">
<span class="icon is-small">
<i class="fas fa-edit"></i>
</span>
<span>Edit Poster</span>
</a>
</p>

<p class="control">
<a href="{{ url_for('remove_poster', poster=poster.poster_id) }}" class="button is-danger">
<span class="icon is-small">
Expand Down
2 changes: 1 addition & 1 deletion theunderground/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")


Expand Down
42 changes: 41 additions & 1 deletion theunderground/posters.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand All @@ -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(
Expand All @@ -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/<poster_id>/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/<poster>/remove", methods=["GET", "POST"])
Expand Down

0 comments on commit c5239fc

Please sign in to comment.