2013-03-19 06:48:47 +08:00
|
|
|
from django.contrib import messages
|
|
|
|
|
|
|
|
|
2013-05-17 23:59:06 +08:00
|
|
|
class SuccessMessageMixin(object):
|
2013-03-19 06:48:47 +08:00
|
|
|
"""
|
|
|
|
Adds a success message on successful form submission.
|
|
|
|
"""
|
|
|
|
success_message = ''
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
response = super(SuccessMessageMixin, self).form_valid(form)
|
|
|
|
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
|