Ajout de l'édition des événements

This commit is contained in:
Jean-Marie Favreau 2023-11-05 13:34:49 +01:00
parent 1f44889db8
commit b94e391792
9 changed files with 124 additions and 29 deletions

View File

@ -148,3 +148,16 @@ footer {
clear: both;
}
.infos-and-buttons {
display: flex;
flex-direction: row;
align-items: stretch
}
.infos-and-buttons .infos {
flex: 50;
}
.infos-and-buttons .buttons {
flex: auto;
}

View File

@ -3,6 +3,12 @@
{% load utils_extra %}
{% load event_extra %}
{% comment %}
TODO:
* utiliser flex plutôt que float pour l'image et pour la date
* gérer le flex des boutons dans le cas de petits écrans
{% endcomment %}
<article>
{% if display in "in list by day" %}
{% if display == "in list by day" and event|can_show_start_time %}
@ -76,7 +82,8 @@
{% comment %}
On affiche le pied qui contient les informations de tags, catégories, etc
{% endcomment %}
<footer>
<footer class="infos-and-buttons">
<div class="infos">
<p>
{% if mode %}
{% if category %}
@ -108,7 +115,11 @@
{% else %}
<p><em>Cet événement est disponible uniquement sur les nuits énimagmatiques.</em></p>
{% endif %}
</div>
<div class="buttons">
<a href="{% url 'edit_event' event.id %}" role="button">éditer</a>
<a href="{% url 'delete_event' event.id %}" role="button">supprimer</a>
</div>
</footer>
</article>

View File

@ -0,0 +1,15 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}Supprimer {{ object.title }}{% endblock %}
{% block content %}
<h1>Suppression de l'événement {{ object.title }} ({{ object.start_day }})</h1>
<form method="post">{% csrf_token %}
<p>Êtes-vous sûr·e de vouloir supprimer l'événement «&nbsp;{{ object }}&nbsp;»&nbsp;?</p>
{{ form }}
<input type="submit" value="Confirmer">
</form>
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}Proposer un événement{% endblock %}
{% block content %}
<h1>Proposer un événement</h1>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Enregistrer">
</form>
{% endblock %}

View File

@ -0,0 +1,15 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}Éditer {{ object.title }}{% endblock %}
{% block content %}
<h1>Édition de l'événement {{ object.title }} ({{ object.start_day }})</h1>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Enregistrer">
</form>
{% endblock %}

View File

@ -2,6 +2,11 @@
{% block title %}Tous les événements{% endblock %}
{% comment %}
TODO:
* améliorer le rendu ici
{% endcomment %}
{% block content %}
<h1>Derniers événements soumis</h1>

View File

@ -41,6 +41,7 @@
<summary aria-haspopup="listbox" role="link">Événements</summary>
<ul role="listbox">
<li><a href="{% url 'event_import_form' %}">Importer</a></li>
<li><a href="{% url 'add_event' %}">Créer</a></li>
<li><a>Exporter</a></li>
{% if user.is_authenticated %}
<li><a href="{% url 'view_all_events' %}">Gérer</a></li>

View File

@ -17,7 +17,10 @@ urlpatterns = [
path("tags/", tag_list, name='view_all_tags'),
path("events/", event_list, name='view_all_events'),
path("event/<int:pk>-<extra>", EventDetailView.as_view(), name="view_event"),
path("event/<int:pk>/edit", EventUpdateView.as_view(), name="edit_event"),
path("event/<int:pk>/delete", EventDeleteView.as_view(), name="delete_event"),
path("importer", EventSubmissionFormView.as_view(), name="event_import_form"),
path("ajouter", EventCreateView.as_view(), name="add_event"),
path("admin/", admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
path("test_app/", include("test_app.urls")),

View File

@ -1,5 +1,7 @@
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, DetailView, FormView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.contrib.auth.mixins import LoginRequiredMixin
from .forms import EventSubmissionModelForm
from .celery import create_event_from_submission
@ -10,6 +12,7 @@ from enum import StrEnum
from datetime import datetime, timedelta
from django.db.models import Q
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.utils.translation import activate, get_language_info
import django_filters
@ -100,6 +103,22 @@ def tag_list(request):
return render(request, 'agenda_culturel/tags.html', context)
class EventCreateView(CreateView):
model = Event
fields = ["title"] # TODO add elements
template_name_suffix = "_create_form"
class EventUpdateView(LoginRequiredMixin, UpdateView):
model = Event
fields = ["title"] # TODO add elements
class EventDeleteView(LoginRequiredMixin, DeleteView):
model = Event
success_url = reverse_lazy('view_all_events')
class EventDetailView(DetailView):
model = Event
template_name = "agenda_culturel/page-event.html"