Remove image from post

This commit is contained in:
Emmanuelle Helly 2018-10-05 16:36:51 +02:00
parent 0bcd4a5618
commit 7be8934370
2 changed files with 8 additions and 6 deletions

View File

@ -119,7 +119,9 @@ def save_post(category, timestamp, admin, form, files):
element.text = value
if ACTION_DELETE_IMAGE in form:
os.remove(form['_image_path'])
image_path = root / form['_image_path']
if image_path.exists:
image_path.unlink()
if 'image' in files:
post_image = files['image']
@ -144,6 +146,4 @@ def save_post(category, timestamp, admin, form, files):
root / category / STATE_WAITING / timestamp
)
return get_post(category, timestamp)

View File

@ -31,11 +31,13 @@
<textarea name="summary">{{ post.summary }}</textarea>
</label>
<label>Image
<img alt="" src="{{ url_for('post_image', path=post._image) }}" />
{% if post._image %}
<img alt="" src="{{ url_for('post_image', path=post._image) }}" />
<input name="_image_path" id="_image_path" value="{{ post._image }}" type="hidden"/>
<input type="submit" name="delete_image" value="Supprimer l'image" class="button" />
{% endif %}
<input name="image" id="image" type="file" value="{{ post.image }}" />
<input name="_image_path" id="_image_path" value="{{ post._image }}" type="hidden"/>
</label>
<input type="submit" name="delete_image" value="Supprimer l'image" class="button" />
<label>Contenu de l'article
<textarea name="content" id="content">{{ post.content }}</textarea>
</label>