From 8409ee4cc454328d5fb0071c6862244cb6a4ff44 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 31 Jul 2020 17:15:31 +0200 Subject: [PATCH] Display "Create WEI" button only for people that can create a WEI, see #53 --- apps/wei/views.py | 5 +++++ templates/wei/weiclub_list.html | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/wei/views.py b/apps/wei/views.py index dde9fe78..f2ac40dc 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -54,6 +54,11 @@ class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): ordering = '-year' extra_context = {"title": _("Search WEI")} + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["can_create_wei"] = PermissionBackend.check_perm(self.request.user, "wei.add_weiclub", WEIClub()) + return context + class WEICreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): """ diff --git a/templates/wei/weiclub_list.html b/templates/wei/weiclub_list.html index 5390ade6..2739e5bf 100644 --- a/templates/wei/weiclub_list.html +++ b/templates/wei/weiclub_list.html @@ -5,8 +5,10 @@
-
- {% trans "Create WEI" %} + {% if can_create_wei %} +
+ {% trans "Create WEI" %} + {% endif %}