Save file in post folder

This commit is contained in:
Emmanuelle Helly 2018-10-04 18:17:06 +02:00
parent b3b78cfd4f
commit 99d5c49286

View File

@ -3,6 +3,8 @@ import time
from pathlib import Path
from xml.etree import ElementTree
from werkzeug.utils import secure_filename
POST_ACTUALITIES = 'actualites'
POST_JOBS = 'emplois'
@ -108,10 +110,13 @@ def save_post(category, timestamp, admin, form, files):
for key, value in form.items():
if key.startswith('_'):
continue
if key == 'image':
print(files)
element = ElementTree.SubElement(tree, key)
element.text = value
if 'image' in files:
post_image = files['image']
filename = secure_filename(post_image.filename)
post_image.save(str(post.parent / filename))
element = ElementTree.SubElement(tree, STATE_PUBLISHED)
element.text = email.utils.formatdate(