Created
June 4, 2013 20:18
-
-
Save MattTheRed/5709197 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from face_grabber.models import Face, FaceForm | |
| from django.views.generic.edit import CreateView | |
| from django.http import HttpResponse | |
| import json | |
| class FaceUploadAjax(CreateView): | |
| template_name = "index.html" | |
| form_class = FaceForm | |
| model = Face | |
| success_url = '/' | |
| def render_to_json_response(self, context, status, **response_kwargs): | |
| data = json.dumps(context) | |
| content_type = 'application/json' | |
| return HttpResponse(data, content_type) | |
| def form_invalid(self, form): | |
| data = {} | |
| data['status_code'] = 400 | |
| return self.render_to_json_response(form.errors, status=400) | |
| def form_valid(self, form): | |
| form.save() | |
| data = {} | |
| data['status_code'] = 200 | |
| data['photo_url'] = form.instance.photo.url | |
| data['frequency'] = form.instance.frequency | |
| return self.render_to_json_response(data, status=200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment