2013-03-19 06:48:47 +08:00
|
|
|
from django.contrib import messages
|
|
|
|
|
|
|
|
|
2017-01-19 15:39:46 +08:00
|
|
|
class SuccessMessageMixin:
|
2013-03-19 06:48:47 +08:00
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Add a success message on successful form submission.
|
2013-03-19 06:48:47 +08:00
|
|
|
"""
|
|
|
|
success_message = ''
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
2017-01-21 21:13:44 +08:00
|
|
|
response = super().form_valid(form)
|
2013-03-19 06:48:47 +08:00
|
|
|
success_message = self.get_success_message(form.cleaned_data)
|
|
|
|
if success_message:
|
|
|
|
messages.success(self.request, success_message)
|
|
|
|
return response
|
|
|
|
|
|
|
|
def get_success_message(self, cleaned_data):
|
|
|
|
return self.success_message % cleaned_data
|