Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. class RestoreApiView(FormView):
  2.     """..."""
  3.     form_class = RestoreForm
  4.  
  5.     def form_invalid(self, form):
  6.         response = super(AjaxableResponseMixin, self).form_invalid(form)
  7.         if self.request.is_ajax():
  8.             return JsonResponse(form.errors, status=400)
  9.         else:
  10.             return response
  11.  
  12.     def form_valid(self, form):
  13.         # We make sure to call the parent's form_valid() method because
  14.         # it might do some processing (in the case of CreateView, it will
  15.         # call form.save() for example).
  16.         response = super(AjaxableResponseMixin, self).form_valid(form)
  17.         if self.request.is_ajax():
  18.             data = {
  19.                 'pk': self.object.pk,
  20.             }
  21.             return JsonResponse(data)
  22.         else:
  23.             return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement