On déplace BackgroundUpdateView dans shared
This commit is contained in:
parent
d8dba17731
commit
1353c4e702
2 changed files with 21 additions and 19 deletions
|
@ -17,12 +17,13 @@ from django.views.generic import (
|
||||||
DetailView,
|
DetailView,
|
||||||
FormView,
|
FormView,
|
||||||
ListView,
|
ListView,
|
||||||
RedirectView,
|
|
||||||
UpdateView,
|
UpdateView,
|
||||||
View,
|
View,
|
||||||
)
|
)
|
||||||
from django.views.generic.detail import SingleObjectMixin
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
|
|
||||||
|
from shared.views import BackgroundUpdateView
|
||||||
|
|
||||||
from .forms import (
|
from .forms import (
|
||||||
DeleteVoteForm,
|
DeleteVoteForm,
|
||||||
ElectionForm,
|
ElectionForm,
|
||||||
|
@ -47,24 +48,6 @@ User = get_user_model()
|
||||||
|
|
||||||
# TODO: access control *everywhere*
|
# 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
|
# Administration Views
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
|
19
shared/views.py
Normal file
19
shared/views.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue