Success_message in utils.views

This commit is contained in:
Oskar Hahn 2013-09-07 22:57:29 +02:00
parent 66679c8efe
commit 477daa3fdf
2 changed files with 25 additions and 2 deletions

View File

@ -127,6 +127,7 @@ class MotionEditMixin(object):
MotionSupporter.objects.bulk_create(
[MotionSupporter(motion=self.object, person=person)
for person in form.cleaned_data['supporter']])
messages.success(self.request, self.get_success_message())
return HttpResponseRedirect(self.get_success_url())
def get_form_class(self):

View File

@ -337,22 +337,44 @@ class ModelFormMixin(object):
class UpdateView(PermissionMixin, UrlMixin, ExtraContextMixin,
ModelFormMixin, _UpdateView):
success_message = None
def form_invalid(self, form):
messages.error(self.request, _('Please check the form for errors.'))
return super(UpdateView, self).form_invalid(form)
def form_valid(self, form):
value = super(UpdateView, self).form_valid(form)
messages.success(self.request, self.get_success_message())
return value
def get_success_message(self):
return _('%s was successfully modified.') % html_strong(self.object)
if self.success_message is None:
message = _('%s was successfully modified.') % html_strong(self.object)
else:
message = self.success_message
return message
class CreateView(PermissionMixin, UrlMixin, ExtraContextMixin,
ModelFormMixin, _CreateView):
success_message = None
def form_invalid(self, form):
messages.error(self.request, _('Please check the form for errors.'))
return super(CreateView, self).form_invalid(form)
def form_valid(self, form):
value = super(CreateView, self).form_valid(form)
messages.success(self.request, self.get_success_message())
return value
def get_success_message(self):
return _('%s was successfully created.') % html_strong(self.object)
if self.success_message is None:
message = _('%s was successfully created.') % html_strong(self.object)
else:
message = self.success_message
return message
class DeleteView(SingleObjectMixin, QuestionMixin, RedirectView):