def form_valid(self, form):
'''
If the form is valid send email notifications to the site administrators.
We don't return the super().form_valid because we don't want the data
to be saved.
'''
subject = 'Correction submitted for exercise #{0}'.format(self.get_object().pk)
context = {
'exercise': self.get_object(),
'form_data': form.cleaned_data,
'user': self.request.user
}
message = render_to_string('exercise/email_correction.tpl', context)
mail.mail_admins(six.text_type(subject),
six.text_type(message),
fail_silently=True)
messages.success(self.request, self.messages)
return HttpResponseRedirect(reverse('exercise:exercise:view',
kwargs={'id': self.object.id}))
评论列表
文章目录