From b614a2b1a6541a85980b3196dfc15b9df7fc83a0 Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Wed, 22 Jun 2016 19:37:59 -0600 Subject: [PATCH] Signin api. --- bikeshop_project/registration/urls.py | 5 +++-- bikeshop_project/registration/views.py | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/bikeshop_project/registration/urls.py b/bikeshop_project/registration/urls.py index c345e7f..40f08cd 100644 --- a/bikeshop_project/registration/urls.py +++ b/bikeshop_project/registration/urls.py @@ -1,8 +1,9 @@ from django.conf.urls import url -from .views import MemberFormView, MemberSearchView +from .views import MemberFormView, MemberSearchView, MemberSignIn urlpatterns = [ url(r'^new/$', MemberFormView.as_view(), name='signup'), url(r'^search/(?P[\w@\.\+]+)/$', MemberSearchView.as_view(), name='member_search'), - url(r'^edit/(?P[0-9]+)/$', MemberFormView.as_view(), name='member_edit') + url(r'^edit/(?P[0-9]+)/$', MemberFormView.as_view(), name='member_edit'), + url(r'^signin/$', MemberSignIn.as_view(), name='member_signin') ] diff --git a/bikeshop_project/registration/views.py b/bikeshop_project/registration/views.py index 99de29a..4774a26 100644 --- a/bikeshop_project/registration/views.py +++ b/bikeshop_project/registration/views.py @@ -1,16 +1,21 @@ import logging from django.contrib import messages +from django.utils.decorators import method_decorator from django.core.urlresolvers import reverse -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.template.response import TemplateResponse from django.views.generic import View +from django.shortcuts import get_object_or_404 +from django.views.decorators.csrf import csrf_exempt +from django.core import serializers import json from haystack.query import SearchQuerySet from .forms import MemberForm from .models import Member +from core.models import Visit logger = logging.getLogger('bikeshop') @@ -60,4 +65,18 @@ class MemberSearchView(View): data = json.dumps(dict(results=results)) - return HttpResponse(data, content_type='application/json') \ No newline at end of file + return HttpResponse(data, content_type='application/json') + +class MemberSignIn(View): + @method_decorator(csrf_exempt) + def dispatch(self, request, *args, **kwargs): + return super(MemberSignIn, self).dispatch(request, *args, **kwargs) + + def post(self, request): + member = get_object_or_404(Member, id=request.POST.get('id')) + Visit.objects.create(member=member, purpose=request.POST.get('purpose')) + + data = json.dumps(dict(results=dict(id=member.id))) + # logger.debug(data) + + return JsonResponse(data=data, safe=False, status=201) \ No newline at end of file