From 1353c4e7029e1a86c5f923b628d4111cdb87bd3d Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 30 May 2021 14:20:24 +0200 Subject: [PATCH] =?UTF-8?q?On=20d=C3=A9place=20BackgroundUpdateView=20dans?= =?UTF-8?q?=20shared?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- elections/views.py | 21 ++------------------- shared/views.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 shared/views.py diff --git a/elections/views.py b/elections/views.py index 56c237a..1214807 100644 --- a/elections/views.py +++ b/elections/views.py @@ -17,12 +17,13 @@ from django.views.generic import ( DetailView, FormView, ListView, - RedirectView, UpdateView, View, ) from django.views.generic.detail import SingleObjectMixin +from shared.views import BackgroundUpdateView + from .forms import ( DeleteVoteForm, ElectionForm, @@ -47,24 +48,6 @@ User = get_user_model() # TODO: access control *everywhere* -# ############################################################################# -# Utils Views -# ############################################################################# - - -class BackgroundUpdateView(RedirectView): - success_message = "" - - def get_success_message(self): - return self.success_message - - def get(self, request, *args, **kwargs): - success_message = self.get_success_message() - if success_message: - messages.success(self.request, success_message) - return super().get(request, *args, **kwargs) - - # ############################################################################# # Administration Views # ############################################################################# diff --git a/shared/views.py b/shared/views.py new file mode 100644 index 0000000..1193913 --- /dev/null +++ b/shared/views.py @@ -0,0 +1,19 @@ +from django.contrib import messages +from django.views.generic import RedirectView + +# ############################################################################# +# Utils Views +# ############################################################################# + + +class BackgroundUpdateView(RedirectView): + success_message = "" + + def get_success_message(self): + return self.success_message + + def get(self, request, *args, **kwargs): + success_message = self.get_success_message() + if success_message: + messages.success(self.request, success_message) + return super().get(request, *args, **kwargs)