Commit 88942882 authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

Ajouter la possibilité de supprimer un évènement ; fixes #12

parent 5117cfa4
......@@ -41,3 +41,21 @@ def create():
today_date = datetime.strftime(datetime.now(), "%Y-%m-%d")
return render_template("events/create.html", today_date=today_date)
@bp.route("/delete/<event_id>", methods=["GET"])
@login_required
def delete(event_id):
if not event_id:
flash("L'identifiant d'évènement est requis.")
event = Event.find_by_id(event_id)
if not event:
flash("L’évènement n’existe pas.")
else:
try:
event.delete()
except:
flash("L’évènement n’a pas pu être supprimé.")
else:
flash("L’évènement a été correctement supprimé.")
return redirect(url_for("index"))
......@@ -125,3 +125,8 @@ class Event:
database.commit()
return cls.find_by_id(cursor.lastrowid)
def delete(self):
database = db.get_db()
database.execute(("DELETE FROM events WHERE id=?"), (self.id,))
database.commit()
......@@ -2,6 +2,12 @@
{% block content %}
<div class="container">
<div class="alert alert-error">
{% for message in get_flashed_messages() %}
<p>{{ message }}</p>
{% endfor %}
</div>
<div class="container-title">
<h1>Temps forts</h1>
......@@ -49,6 +55,12 @@
{% else %}
{{ event.title }}
{% endif %}
{% if g.current_user %}
<button onclick="confirmDelete('{{ url_for('events.delete', event_id=event.id ) }}')">
🗑
</button>
{% endif %}
</li>
{% endfor %}
</ul>
......@@ -58,4 +70,12 @@
</div>
{% endfor %}
</div>
<script>
function confirmDelete(deleteUrl) {
if (window.confirm("Êtes-vous sûr.e de vouloir supprimer cet évènement ?")) {
window.location = deleteUrl;
}
}
</script>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment