add hole field to art submission form

master
Aevann 2024-04-09 18:20:21 +02:00
parent 6d6ff1a5cc
commit e5e5402037
4 changed files with 50 additions and 1 deletions

View File

@ -3,6 +3,7 @@ function approve_art(t, id) {
{
"comment": document.getElementById(`${id}-comment`).value,
"author": document.getElementById(`${id}-author`).value,
"hole": document.getElementById(`${id}-hole`).value,
},
() => {
document.getElementById(`${id}-art`).remove()

View File

@ -4,6 +4,7 @@ from sqlalchemy import Column, ForeignKey
from sqlalchemy.sql.sqltypes import *
from files.classes import Base
from files.helpers.lazy import lazy
from files.helpers.config.const import *
sidebar_hashes = {}
banner_hashes = {}
@ -17,6 +18,11 @@ class ArtSubmission(Base):
created_utc = Column(Integer)
approved = Column(Boolean, default=False)
if SITE_NAME == 'WPD':
hole = Column(String, ForeignKey("holes.name"))
else:
hole = None
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
super().__init__(*args, **kwargs)

View File

@ -51,11 +51,14 @@ def submit_art_post(v):
username = request.values.get('author', '').lower().strip()
author = get_user(username, v=v)
hole = request.values.get('hole', '').lower().strip()
if not hole: hole = None
entry = ArtSubmission(
kind=kind,
author_id=author.id,
submitter_id=v.id,
hole=hole,
)
g.db.add(entry)
g.db.flush()
@ -106,7 +109,20 @@ def approve_art(v, id):
old = f'/asset_submissions/art/{entry.id}.webp'
copyfile(old, f"/asset_submissions/art/original/{entry.id}.webp")
filename = f"files/assets/images/{SITE_NAME}/{entry.location_kind}/{entry.id}.webp"
hole = request.values.get('hole', '').lower().strip()
if hole:
hole = g.db.get(Hole, hole)
if not hole:
abort(404, "Hole not found!")
filename = f'/images/{time.time()}'.replace('.','') + '.webp'
if entry.kind == "sidebar":
hole.sidebarurls.append(f"{SITE_FULL_IMAGES}{filename}")
else:
hole.bannerurls.append(f"{SITE_FULL_IMAGES}{filename}")
else:
filename = f"files/assets/images/{SITE_NAME}/{entry.location_kind}/{entry.id}.webp"
move(old, filename)
process_image(filename, v, resize=entry.resize, trim=True)

View File

@ -29,6 +29,18 @@
<label class="mt-3" for="author">Author</label>
<input autocomplete="off" type="text" id="author" class="form-control" name="author" maxlength="30" pattern='[a-zA-Z0-9_\- ]{1,30}|\?{3}' placeholder="Required" value="{{username}}" required>
{% if SITE_NAME == 'WPD' %}
<label class='mt-3' for="hole">Hole</label>
<div class="input-group">
<input list="holes" autocomplete="off" id="hole" class="form-control" name="hole" placeholder="Optional">
<datalist id="holes">
{% for h in HOLES() %}
<option value="{{h}}"></option>
{% endfor %}
</datalist>
</div>
{% endif %}
<div class="footer mt-5">
<div class="d-flex">
<input id="submit-btn" disabled type="submit" class="btn btn-primary ml-auto" value="Submit {{kind}}">
@ -57,6 +69,20 @@
<label class="mt-3" for="{{entry.id}}-author">Author</label>
<input autocomplete="off" type="text" id="{{entry.id}}-author" class="form-control" maxlength="30" value="{{entry.author}}" pattern='[a-zA-Z0-9_\- ]{1,30}|\?{3}' placeholder="Required" required {% if v.admin_level < PERMS['MODERATE_PENDING_SUBMITTED_ASSETS'] %}readonly{% endif %}>
{% if SITE_NAME == 'WPD' %}
<label class='mt-3' for="hole">Hole</label>
<div class="input-group">
<input list="holes" autocomplete="off" id="{{entry.id}}-hole" class="form-control" placeholder="Optional" {% if entry.hole %}value="{{entry.hole}}"{% endif %} {% if v.admin_level < PERMS['MODERATE_PENDING_SUBMITTED_ASSETS'] %}readonly{% endif %}>
<datalist id="holes">
{% for h in HOLES() %}
<option value="{{h}}"></option>
{% endfor %}
</datalist>
</div>
{% else %}
<input hidden id="{{entry.id}}-hole">
{% endif %}
</div>
</div>
{% if v.admin_level >= PERMS['MODERATE_PENDING_SUBMITTED_ASSETS'] or v.id == entry.submitter_id %}