Skip to content

Commit

Permalink
feat: Add field to upload room category image
Browse files Browse the repository at this point in the history
  • Loading branch information
noahpistilli committed Jul 1, 2024
1 parent 01f9f3c commit 239410d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions templates/room_action.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
{{ existing_image('parade banner', url_for('get_parade_banner', room_id=room_id)) }}
{% endif %}
{{ form.parade_banner(class_="block") }}

{{ form.category_logo.label(class_="label block") }}
{% if room_id %}
{{ existing_image('category logo', url_for('get_category_logo', room_id=room_id)) }}
{% endif %}
{{ form.category_logo(class_="block") }}
</p>
<p>{{ form.submit(class_="button is-success block") }}</p>
</form>
Expand Down
1 change: 1 addition & 0 deletions theunderground/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class RoomForm(FlaskForm):
)
room_logo = FileField("Room Logo")
parade_banner = FileField("Parade Banner")
category_logo = FileField("Category Logo")
has_mascot = BooleanField("Mascot Enabled")
intro_msg = StringField("Intro Message", validators=[DataRequired()])
mii_msg = StringField("Mii Message", validators=[DataRequired()])
Expand Down
14 changes: 13 additions & 1 deletion theunderground/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from werkzeug import exceptions

from asset_data import RoomLogoAsset, ParadeBannerAsset
from asset_data import RoomLogoAsset, ParadeBannerAsset, NormalCategoryAsset
from models import db, Rooms, RoomMiis
from theunderground.forms import RoomForm
from room import app, s3
Expand Down Expand Up @@ -44,6 +44,9 @@ def edit_room(room_id):
if form.parade_banner.data:
ParadeBannerAsset(room.room_id).encode(form.parade_banner)

if form.category_logo.data:
NormalCategoryAsset(room.room_id + 30000).encode(form.category_logo)

mii.mii_id = form.mii.data
mii.mii_msg = form.mii_msg.data
db.session.add(mii)
Expand Down Expand Up @@ -82,6 +85,7 @@ def create_room():
form = RoomForm()
form.parade_banner.flags.required = True
form.room_logo.flags.required = True
form.category_logo.flags.required = True

if form.validate_on_submit():
# First, add our room. Auto-increment will give us a
Expand All @@ -108,6 +112,7 @@ def create_room():
# Finally, handle room data - our room logo, and parade banner.
RoomLogoAsset(room.room_id).encode(form.room_logo)
ParadeBannerAsset(room.room_id).encode(form.parade_banner)
NormalCategoryAsset(room.room_id + 30000).encode(form.category_logo)

return redirect(url_for("list_room"))

Expand All @@ -122,6 +127,7 @@ def drop_room():
db.session.delete(Rooms.query.filter_by(room_id=room_id).first())
db.session.commit()
shutil.rmtree(f"./assets/special/{room_id}")
NormalCategoryAsset(room_id + 30000).delete()

if s3:
# Delete from S3
Expand All @@ -148,3 +154,9 @@ def get_parade_banner(room_id):
return redirect(f"{config.url1_cdn_url}/special/{room_id}/img/g1234.img")

return ParadeBannerAsset(room_id).send_file()


@app.route("/theunderground/rooms/<int:room_id>/category_logo.jpg")
@oidc.require_login
def get_category_logo(room_id):
return NormalCategoryAsset(room_id + 30000).send_file()

0 comments on commit 239410d

Please sign in to comment.