Skip to content

Commit

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

{% block title %}
Upload a Pay Poster
{{ action }} a Pay Poster
{% endblock %}

{% block content %}
Expand All @@ -17,7 +17,11 @@
{{ form.movie.label(class_="label") }} {{ form.movie(size=32) }}
<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_pay_poster', poster=poster_id)) }}
{% endif %}
{{ form.poster(size=32) }}
</p>
<br>
<p>{{ form.upload(class_="button is-success") }}</p>
Expand Down
2 changes: 1 addition & 1 deletion templates/pay_poster_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<td>
<div class="field has-addons">
<p class="control">
<a href="" class="button">
<a href="{{ url_for('edit_pay_poster', poster_id=poster.poster_id) }}" class="button">
<span class="icon is-small">
<i class="fas fa-edit"></i>
</span>
Expand Down
4 changes: 2 additions & 2 deletions theunderground/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ class PosterForm(FlaskForm):
class PayPosterForm(FlaskForm):
title = StringField("Title", validators=[DataRequired(), Length(max=47)])
msg = StringField("Message", validators=[DataRequired(), Length(max=15)])
poster = FileField("Poster", validators=[FileRequired()])
movie = FileField("Movie", validators=[FileRequired()])
poster = FileField("Poster")
movie = FileField("Movie")
upload = SubmitField("Create Poster!")


Expand Down
44 changes: 43 additions & 1 deletion theunderground/pay_posters.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from flask import render_template, flash, url_for, redirect
from werkzeug import exceptions

from theunderground.forms import PayPosterForm
from theunderground.operations import manage_delete_item
from theunderground.admin import oidc
from asset_data import PosterAsset, PayMovieAsset
from models import PayPosters, db
from room import app
from flask_wtf.file import FileRequired

import os

Expand All @@ -34,6 +36,10 @@ def list_pay_posters():
def add_pay_poster():
form = PayPosterForm()

# Add the file validators
form.poster.validators = [FileRequired()]
form.movie.validators = [FileRequired()]

if form.validate_on_submit():
db_poster = PayPosters(
msg=form.msg.data, title=form.title.data, type=1, aspect=False
Expand Down Expand Up @@ -62,7 +68,43 @@ def add_pay_poster():

return redirect(url_for("list_pay_posters"))

return render_template("pay_poster_add.html", form=form)
return render_template("pay_poster_action.html", form=form, action="Upload")


@app.route("/theunderground/payposters/<poster_id>/edit", methods=["GET", "POST"])
@oidc.require_login
def edit_pay_poster(poster_id):
form = PayPosterForm()

poster = PayPosters.query.filter_by(poster_id=poster_id).first()
if not poster:
return exceptions.NotFound()

if form.validate_on_submit():
poster.msg = form.msg.data
poster.title = form.title.data

# Encrypt movie
if form.movie.data:
cipher = AES.new(PAY_POSTER_KEY, AES.MODE_CBC, iv=PAY_POSTER_IV)
encrypted_movie = cipher.encrypt(
pad(form.movie.data.read(), AES.block_size)
)
PayMovieAsset(poster.poster_id).upload_movie(encrypted_movie)

if form.poster.data:
# Now upload poster
PosterAsset(poster.poster_id, True).encode(form.poster)

db.session.commit()
return redirect(url_for("list_pay_posters"))
else:
form.msg.data = poster.msg
form.title.data = poster.title

return render_template(
"pay_poster_action.html", form=form, action="Edit", poster_id=poster_id
)


@app.route("/theunderground/payposters/<poster>/remove", methods=["GET", "POST"])
Expand Down

0 comments on commit 153ac12

Please sign in to comment.