Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RestoreApiView(FormView):
- """..."""
- form_class = RestoreForm
- def form_invalid(self, form):
- response = super(AjaxableResponseMixin, self).form_invalid(form)
- if self.request.is_ajax():
- return JsonResponse(form.errors, status=400)
- else:
- return response
- def form_valid(self, form):
- # We make sure to call the parent's form_valid() method because
- # it might do some processing (in the case of CreateView, it will
- # call form.save() for example).
- response = super(AjaxableResponseMixin, self).form_valid(form)
- if self.request.is_ajax():
- data = {
- 'pk': self.object.pk,
- }
- return JsonResponse(data)
- else:
- return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement