Compare commits

...

3 Commits

Author SHA1 Message Date
decentral1se 17bf2fa74f
fix: save before loading list 3 weeks ago
decentral1se de85c36510
fix: use named var in f-string 3 weeks ago
decentral1se a9675c5b7f
fix: ignore static files 3 weeks ago
  1. 2
      .gitignore
  2. 14
      upload.py

2
.gitignore

@ -138,3 +138,5 @@ dmypy.json
# Cython debug symbols
cython_debug/
# static
/static/images/

14
upload.py

@ -17,13 +17,13 @@ APP.config["SECRET_KEY"] = os.urandom(24)
class ImageUploadForm(FlaskForm):
"""Image upload form."""
allowed = ", ".join(ALLOWED_FILES)
image = FileField(
"image:",
validators=[
FileAllowed(
ALLOWED_FILES,
f"Images only, please use any of the following file extensions: {(", ").join(ALLOWED_FILES)}",
f"Images only, please use any of the following file extensions: {allowed}",
)
],
)
@ -39,6 +39,11 @@ def saveimage(image):
def index():
"""Upload route, a page to upload an image"""
imageuploadform = ImageUploadForm()
if request.method == "POST":
if imageuploadform.validate_on_submit():
saveimage(imageuploadform.image.data)
uploaded_files = sorted(
[
os.path.join(APP.config["IMAGE_FOLDER"], file)
@ -46,10 +51,7 @@ def index():
],
key=os.path.getctime,
)
print(uploaded_files)
if request.method == "POST":
if imageuploadform.validate_on_submit():
saveimage(imageuploadform.image.data)
return render_template(
"upload.html",
imageuploadform=imageuploadform,

Loading…
Cancel
Save