On simplifie la page de modération et la page de proposition d'un événement

Fix #56
Fix #49
This commit is contained in:
Jean-Marie Favreau 2023-12-14 18:48:56 +01:00
parent a82eb7e01c
commit 7a55525408
7 changed files with 98 additions and 59 deletions

View File

@ -41,6 +41,9 @@ $enable-responsive-typography: true;
}
body>footer {
text-align: center;
}
.cat,
.action {
@ -607,3 +610,10 @@ form [role="button"] {
.large {
margin: 2em auto;
}
@media (min-width: 992px) {
.grid.two-columns {
grid-column-gap: var(--nav-element-spacing-vertical);
grid-template-columns: auto 25%;
}
}

View File

@ -5,16 +5,35 @@
{% block content %}
<h1>Importer un événement</h1>
<h1>Ajouter un événement</h1>
<article>
<header>
{% url 'event_import_form' as local_url %}
{% include "agenda_culturel/static_content.html" with name="import" url_path=local_url %}
</header>
</article>
<article>
<header>
<h2>Ajout automatique</h2>
<p>Si l'événement est déjà en ligne sur un autre site internet, on essaye de l'importer...</p>
</header>
<form method="post" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Lancer l'import">
</form>
</article>
<article>
<header>
<h2>Ajout manuel</h2>
<p>Si l'import automatique ne marche pas, ou si l'événement n'est pas en ligne, vous pouvez l'ajouter en remplissant le
formulaire ci-dessous.</p>
</header>
<form method="post">{% csrf_token %}
{{ form_event.as_p }}
<input type="submit" value="Enregistrer">
</form>
</article>
{% endblock %}

View File

@ -8,7 +8,7 @@
{% endblock %}
{% block content %}
<div class="grid two-columns">
<article>
<header>
<h1>Derniers événements soumis</h1>
@ -43,4 +43,22 @@
</footer>
</article>
<aside>
<article>
<h2>Consulter</h2>
<ul>
<li><a href="{% url 'view_all_tags' %}">Toutes les étiquettes</a></li>
</ul>
<h2>Configurer</h2>
<ul>
<li><a href="{% url 'admin:index' %}">Administration de django</a></li>
</ul>
</article>
<article>
<p>Vous êtes connecté(e) en tant que {{ user }}.</p>
<a role="button" href="{% url 'logout' %}?next={% url 'home' %}">Déconnexion</a>
</article>
</aside>
</div>
{% endblock %}

View File

@ -67,32 +67,21 @@
<footer class="container-fluid">
<div class="grid">
<div>
<h3>Informations</h3>
<ul>
<li><a href="{% url 'view_all_tags' %}">Toutes les étiquettes</a></li>
<li><a href="{% url 'mentions_legales' %}">Mentions légales</a></li>
<li><a>Exporter</a></li>
</ul>
<a href="{% url 'mentions_legales' %}">Mentions légales</a>
</div>
<div>
<h3>Contribuer</h3>
<ul>
<li><a href="{% url 'event_import_form' %}">Importer un événement</a></li>
<li><a href="{% url 'add_event' %}">Créer un événement</a></li>
</ul>
Contact
</div>
<div>
<h3>Administrer</h3>
<ul>
{% if user.is_authenticated %}
<li><a href="{% url 'view_all_events' %}">Gérer les événements</a></li>
<li><a href="{% url 'admin:index' %}">Administration</a></li>
<li><a href="{% url 'logout' %}?next={% url 'home' %}">Déconnexion</a></li>
<li>Vous êtes connecté(e) en tant que {{ user }}</li>
{% else %}
<li><a href="{% url 'login' %}?next={% url 'view_all_events' %}">Connexion</a></li>
{% endif %}
</ul>
<a href="{% url 'add_event' %}">Ajouter un événement</a>
</div>
<div>
{% if user.is_authenticated %}
<a href="{% url 'moderation' %}">Administrer</a>
<p>Vous êtes connecté(e) en tant que {{ user }}</p>
{% else %}
<a href="{% url 'login' %}?next={% url 'moderation' %}">Administrer</a>
{% endif %}
</div>
</div>

View File

@ -44,6 +44,6 @@ def show_badges_events():
# TODO: seulement ceux dans le futur ?
nb_drafts = nb_draft_events()
if nb_drafts != 0:
return mark_safe('<a href="' + reverse_lazy("view_all_events") + '?status=draft" class="badge" data-tooltip="' + str(nb_drafts) + ' brouillon' + pluralize(nb_drafts) + ' à valider">' + str(nb_drafts) + '</a>')
return mark_safe('<a href="' + reverse_lazy("moderation") + '?status=draft" class="badge" data-tooltip="' + str(nb_drafts) + ' brouillon' + pluralize(nb_drafts) + ' à valider">' + str(nb_drafts) + '</a>')
else:
return ""

View File

@ -17,13 +17,12 @@ urlpatterns = [
path("ce-mois-ci", month_view, name="ce_mois_ci"),
path("tag/<t>/", view_tag, name='view_tag'),
path("tags/", tag_list, name='view_all_tags'),
path("events/", event_list, name='view_all_events'),
path("moderation/", moderation, name='moderation'),
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>/change-status/<status>", change_status_event, name="change_status_event"),
path("event/<int:pk>/delete", EventDeleteView.as_view(), name="delete_event"),
path("importer", import_from_url, name="event_import_form"),
path("ajouter", EventCreateView.as_view(), name="add_event"),
path("ajouter", import_from_url, name="add_event"),
path("admin/", admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
path("test_app/", include("test_app.urls")),

View File

@ -182,33 +182,33 @@ class StaticContentUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateVie
class EventCreateView(SuccessMessageMixin, CreateView):
model = Event
# class EventCreateView(SuccessMessageMixin, CreateView):
# model = Event
form_class = EventForm
template_name_suffix = "_create_form"
success_message = _('The event has been submitted and will be published as soon as it has been validated by the moderation team.')
# form_class = EventForm
# template_name_suffix = "_create_form"
# success_message = _('The event has been submitted and will be published as soon as it has been validated by the moderation team.')
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['is_authenticated'] = self.request.user.is_authenticated
return kwargs
# def get_form_kwargs(self):
# kwargs = super().get_form_kwargs()
# kwargs['is_authenticated'] = self.request.user.is_authenticated
# return kwargs
def get_initial(self):
initial = super().get_initial()
initial = initial.copy()
initial["start_day"] = date.today() + timedelta(days=1)
initial["start_time"] = "20:00"
initial["end_time"] = "22:00"
return initial
# def get_initial(self):
# initial = super().get_initial()
# initial = initial.copy()
# initial["start_day"] = date.today() + timedelta(days=1)
# initial["start_time"] = "20:00"
# initial["end_time"] = "22:00"
# return initial
def get_success_url(self, **kwargs):
if self.request.user.is_authenticated:
return self.object.get_absolute_url()
else:
return reverse_lazy("home")
# def get_success_url(self, **kwargs):
# if self.request.user.is_authenticated:
# return self.object.get_absolute_url()
# else:
# return reverse_lazy("home")
class EventUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
@ -224,7 +224,7 @@ class EventUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
class EventDeleteView(SuccessMessageMixin, LoginRequiredMixin, DeleteView):
model = Event
success_url = reverse_lazy('view_all_events')
success_url = reverse_lazy('moderation')
success_message = _('The event has been successfully deleted.')
@ -258,12 +258,9 @@ def import_from_url(request):
import logging
logger = logging.getLogger(__name__)
if "title" in request.POST and request.method == 'POST':
logger.error("on passe l")
if request.method == 'POST' and "title" in request.POST:
form = EventForm(request.POST)
logger.error("on passe i")
if form.is_valid():
logger.error("valide")
new_event = form.save()
if request.user.is_authenticated:
messages.success(request, _("The event is saved."))
@ -277,9 +274,16 @@ def import_from_url(request):
else:
form = EventSubmissionForm()
initial = {"start_day": date.today() + timedelta(days=1),
"start_time": "20:00",
"end_time": "22:00"}
form_event = EventForm(initial=initial)
if request.method == 'POST':
form = EventSubmissionForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
url = cd.get('url')
@ -297,7 +301,7 @@ def import_from_url(request):
else:
form = EventForm(initial={'url': [url]})
messages.error(request, _("Unable to extract an event from the proposed URL. Please use the form below to submit the event."))
return render(request, 'agenda_culturel/importer.html', context={'form': form })
return render(request, 'agenda_culturel/import.html', context={'form': form, 'form_event': form_event})
else:
published = [e for e in existing if e.status == Event.STATUS.PUBLISHED]
drafts = [e for e in existing if e.status == Event.STATUS.DRAFT]
@ -314,7 +318,7 @@ def import_from_url(request):
messages.info(request, _("This URL has already been submitted and is awaiting moderation."))
return render(request, 'agenda_culturel/import.html', context={'form': form })
return render(request, 'agenda_culturel/import.html', context={'form': form, 'form_event': form_event})
class EventFilterAdmin(django_filters.FilterSet):
@ -326,7 +330,7 @@ class EventFilterAdmin(django_filters.FilterSet):
@login_required(login_url="/accounts/login/")
def event_list(request):
def moderation(request):
filter = EventFilterAdmin(request.GET, queryset=Event.objects.all().order_by("-created_date"))
paginator = Paginator(filter.qs, 10)
page = request.GET.get('page')
@ -338,7 +342,7 @@ def event_list(request):
except EmptyPage:
response = paginator.page(paginator.num_pages)
return render(request, 'agenda_culturel/recently-added.html', {'filter': filter, 'paginator_filter': response})
return render(request, 'agenda_culturel/moderation.html', {'filter': filter, 'paginator_filter': response})
class SimpleSearchEventFilter(django_filters.FilterSet):