Button delete

This commit is contained in:
Jérémie 2018-10-04 17:53:55 +02:00
parent a86b322cf7
commit 7e42f8636b
3 changed files with 42 additions and 5 deletions

View File

@ -10,11 +10,23 @@ POSTS = {POST_ACTUALITIES: "Actualités", POST_JOBS: "Offres demploi"}
STATE_WAITING = 'waiting'
STATE_PUBLISHED = 'published'
STATES = {STATE_WAITING: "En attente", STATE_PUBLISHED: "Publié"}
STATE_TRASHED = 'trash'
STATES = {
STATE_WAITING: "En attente",
STATE_PUBLISHED: "Publié",
STATE_TRASHED: "À la corbeille"
}
ACTION_PUBLISH = 'publish'
ACTION_UNPUBLISH = 'unpublish'
ACTIONS = {ACTION_PUBLISH: "Publier", ACTION_UNPUBLISH: "Dépublier"}
ACTION_REPUBLISH = 'republish'
ACTION_TRASH = 'trash'
ACTIONS = {
ACTION_PUBLISH: "Publier",
ACTION_UNPUBLISH: "Dépublier",
ACTION_REPUBLISH: "Republier",
ACTION_TRASH: "Supprimer",
}
TIMESTAMP = '_timestamp'
STATE = '_state'
@ -90,6 +102,8 @@ def save_post(category, timestamp, admin, form):
status = STATE_WAITING
elif get_path(category, STATE_PUBLISHED, timestamp, BASE_FILE).is_file():
status = STATE_PUBLISHED
elif get_path(category, STATE_TRASHED, timestamp, BASE_FILE).is_file():
status = STATE_TRASHED
else:
raise DataException(http_code=404)
if status == STATE_PUBLISHED and not admin:
@ -117,5 +131,13 @@ def save_post(category, timestamp, admin, form):
(root / category / STATE_PUBLISHED / timestamp).rename(
root / category / STATE_WAITING / timestamp
)
elif ACTION_REPUBLISH in form and status == STATE_TRASHED:
(root / category / STATE_TRASHED / timestamp).rename(
root / category / STATE_PUBLISHED / timestamp
)
elif ACTION_TRASH in form and status == STATE_PUBLISHED:
(root / category / STATE_PUBLISHED / timestamp).rename(
root / category / STATE_TRASHED / timestamp
)
return get_post(category, timestamp)

View File

@ -8,7 +8,13 @@
<article>
<h2>{{ label }}</h2>
{% for state, timestamps in posts.items() %}
{% set state_label = 'En attente' if state == 'waiting' else 'Publiés' %}
{% if state == 'waiting' %}
{% set state_label= 'En attente' %}
{% elif state == 'published' %}
{% set state_label= 'Publiés' %}
{% else %}
{% set state_label= 'Supprimés' %}
{% endif %}
<h3>{{ state_label }}</h3>
{% if timestamps %}
<table>

View File

@ -52,12 +52,21 @@
</label>
<input type="submit" value="Enregistrer" />
{% if admin %}
{% if post.state == 'waiting' %}
{% if post._state == 'waiting' %}
<input type="submit" name="publish" value="Publier" />
{% else %}
{% elif post._state == 'published' %}
<input type="submit" name="unpublish" value="Dépublier" />
{% else %}
<input type="submit" name="republish" value="Republier" />
{% endif %}
{% endif %}
{% if post._state == 'published' %}
<input type="submit" name="trashed" value="Supprimer" />
{% endif %}
</form>
{% if name == 'actualites' %}
<p>