mirror of https://github.com/snachodog/mybuddy.git
28 lines
881 B
Python
28 lines
881 B
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
|
|
import json
|
|
|
|
from django.http import HttpResponse
|
|
from django.core.urlresolvers import reverse_lazy
|
|
from django.views.generic.edit import FormView
|
|
from django.utils.encoding import force_text
|
|
|
|
from core.forms import BabyForm
|
|
|
|
|
|
class BabyFormView(FormView):
|
|
template_name = 'baby-form.html'
|
|
form_class = BabyForm
|
|
success_url = reverse_lazy('form_data_valid')
|
|
|
|
def post(self, request, **kwargs):
|
|
if request.is_ajax():
|
|
return self.ajax(request)
|
|
return super(BabyFormView, self).post(request, **kwargs)
|
|
|
|
def ajax(self, request):
|
|
form = self.form_class(data=json.loads(request.body))
|
|
response_data = {'errors': form.errors, 'success_url': force_text(self.success_url)}
|
|
return HttpResponse(json.dumps(response_data), content_type="application/json")
|