From 5fa5fff7bc9ab41af186d1795343f6a3348a1ce6 Mon Sep 17 00:00:00 2001 From: Ludovic Druette Date: Sun, 3 Apr 2022 14:14:33 +0200 Subject: [PATCH] Display author choices in post edit and create only if user is in at least one club --- back/news/templates/news/post_edit.html | 8 +++++--- back/news/views.py | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/back/news/templates/news/post_edit.html b/back/news/templates/news/post_edit.html index d3a7af87..c13f311b 100644 --- a/back/news/templates/news/post_edit.html +++ b/back/news/templates/news/post_edit.html @@ -24,9 +24,11 @@

{% if Edit %}Éditer{% else %}Créer{% endif %} un post
- {{EditPost.club.errors}} -
Publier en tant que :
- {{EditPost.club}} + {% if IsInClub %} + {{EditPost.club.errors}} +
Publier en tant que :
+ {{EditPost.club}} + {% endif %} {{EditPost.event.errors}}
Est-ce que ce post est associé à un évènement ?
diff --git a/back/news/views.py b/back/news/views.py index 700455e0..b4ee795b 100644 --- a/back/news/views.py +++ b/back/news/views.py @@ -168,6 +168,7 @@ def post_edit(request, post_id): else: form = EditPost(request.user.id, instance=post) context["EditPost"] = form + context["IsInClub"] = len(form.fields["club"].choices) > 1 context["post"] = post context["Edit"] = True request.session["origin"] = request.META.get("HTTP_REFERER", "news:posts") @@ -196,6 +197,7 @@ def post_create(request, event_id=None): form.fields["event"].initial = get_object_or_404(Event, id=event_id) request.session["origin"] = request.META.get("HTTP_REFERER", "news:posts") context["EditPost"] = form + context["IsInClub"] = len(form.fields["club"].choices) > 1 context["Edit"] = False return render(request, "news/post_edit.html", context)