Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ dmypy.json

.idea
.DS_Store
assets/

config.py
4 changes: 2 additions & 2 deletions templates/banner_add.html → templates/banner_action.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% extends "generic/base.html" %}

{% block title %}
Upload Banner - Nintendo Channel Admin
{{ action }} Banner - Nintendo Channel Admin
{% endblock %}

{% block content %}
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<h1 class="mb-6 text-2xl font-bold text-white">Upload New Banner</h1>
<h1 class="mb-6 text-2xl font-bold text-white">{{ action }} Banner</h1>
<div class="relative group mb-10">
<div class="relative bg-gray-800 rounded-lg shadow-lg overflow-hidden border border-gray-700 p-8">
<div class="flex items-center mb-6 pb-4 border-b border-gray-700">
Expand Down
5 changes: 5 additions & 0 deletions templates/banner_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ <h2 class="text-xl font-bold text-white">Banners</h2>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<div class="flex space-x-2">
<a href="{{ url_for('thegateway.edit_banner', banner_id=banner.id) }}"
class="inline-flex items-center px-3 py-1.5 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg transition duration-200 text-xs">
<img src="/static/icon/pencil.svg" alt="Edit" class="h-3.5 w-3.5 mr-1.5 invert" />
<span>Edit</span>
</a>
<a href="/thegateway/banners/{{ banner.id }}/remove"
class="inline-flex items-center px-3 py-1 rounded-md bg-red-700/30 text-red-300 hover:bg-red-600/50 hover:text-white transition-colors duration-200">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1.5" fill="none"
Expand Down
52 changes: 51 additions & 1 deletion thegateway/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import threading
import subprocess
import os
from werkzeug import exceptions
from flask_wtf.file import FileRequired


banner_generate_status = {
Expand All @@ -28,6 +30,13 @@
}


def save_banner_data(banner_id: int, thumbnail_data: bytes):
thumbnail_data = banner_encode(thumbnail_data)
thumbnail = open(f"./assets/banners/{banner_id}.img", "wb")
thumbnail.write(thumbnail_data)
thumbnail.close()


@thegateway_blueprint.route("/thegateway/banners/")
@oidc.require_login
def list_banners():
Expand All @@ -47,6 +56,7 @@ def list_banners():
@oidc.require_login
def add_banner():
form = BannerForm()
form.thumbnail.validators = [FileRequired()]
if form.validate_on_submit():
thumbnail = form.thumbnail.data
if thumbnail:
Expand Down Expand Up @@ -78,7 +88,47 @@ def add_banner():
else:
flash("Error uploading image!")

return render_template("banner_add.html", form=form)
return render_template("banner_action.html", form=form, action="Upload New")


@thegateway_blueprint.route("/thegateway/banners/<banner_id>/edit", methods=["GET", "POST"])
@oidc.require_login
def edit_banner(banner_id):
form = BannerForm()
form.upload.label.text = "Edit Banner"

banner = Banners.query.filter_by(id=banner_id).first()
if not banner:
return exceptions.NotFound()

if form.validate_on_submit():
thumbnail_data = None
if form.thumbnail.data:
thumbnail_data = form.thumbnail.data.read()
save_banner_data(banner_id, thumbnail_data)

banner.name_japanese = form.title_jpn.data
banner.name_english = form.title_en.data
banner.name_german = form.title_de.data
banner.name_french = form.title_fr.data
banner.name_spanish = form.title_es.data
banner.name_italian = form.title_it.data
banner.name_dutch = form.title_dutch.data
banner.name_ptbr = form.title_ptbr.data
db.session.commit()

return redirect(url_for("thegateway.list_banners"))
else:
form.title_jpn.data = banner.name_japanese
form.title_en.data = banner.name_english
form.title_de.data = banner.name_german
form.title_fr.data = banner.name_french
form.title_es.data = banner.name_spanish
form.title_it.data = banner.name_italian
form.title_dutch.data = banner.name_dutch
form.title_ptbr.data = banner.name_ptbr

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


@thegateway_blueprint.route(
Expand Down
2 changes: 1 addition & 1 deletion thegateway/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class BannerForm(FlaskForm):
title_ptbr = StringField(
"Title (Brazilian Portuguese)", validators=[DataRequired(), Length(max=102)]
)
thumbnail = FileField("Image", validators=[FileRequired()])
thumbnail = FileField("Image")
upload = SubmitField("Add")


Expand Down