Browse Source

View already signed in members.

feature/python-error-tracking
Drew Larson 9 years ago
parent
commit
df6752a13f
  1. 21
      bikeshop_project/assets/js/components/SignIn.jsx
  2. 43
      bikeshop_project/registration/views.py

21
bikeshop_project/assets/js/components/SignIn.jsx

@ -21,7 +21,26 @@ export default class SignIn extends React.Component {
this.signIn = this.signIn.bind(this);
this.chooseMember = this.chooseMember.bind(this);
this.handlePurposeChoice = this.handlePurposeChoice.bind(this);
}
}
componentDidMount () {
fetch('//bikeshop.local/member/signin/')
.then((response) => {
return response.json()
})
.then((data) => {
const visits = JSON.parse(data);
this.setState({signedIn: visits.map((visit) => {
return {
id: visit.member.id,
purpose: visit.purpose,
text: visit.member.full_name,
value: `${visit.member.full_name} <${visit.member.email}>`,
at: moment(visit.created_at)
}
})})
})
}
handlePurposeChoice (event, index, value) {
this.setState({...this.state, signOn: {...this.state.signOn, purpose: value}});

43
bikeshop_project/registration/views.py

@ -1,21 +1,23 @@
import json
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, JsonResponse
from django.template.response import TemplateResponse
from django.views.generic import View
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
from django.core import serializers
from django.views.generic import View
import json
from core.models import Visit
from haystack.query import SearchQuerySet
from rest_framework.serializers import ModelSerializer
from rest_framework.renderers import JSONRenderer
from .forms import MemberForm
from .models import Member
from core.models import Visit
logger = logging.getLogger('bikeshop')
@ -67,6 +69,19 @@ class MemberSearchView(View):
return HttpResponse(data, content_type='application/json')
class MemberSerializer(ModelSerializer):
class Meta:
model = Member
fields = ('full_name', 'email', 'id')
class VisitSerializer(ModelSerializer):
member = MemberSerializer()
class Meta:
model = Visit
fields = ('created_at', 'purpose', 'member')
depth = 1
class MemberSignIn(View):
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
@ -75,8 +90,16 @@ class MemberSignIn(View):
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)
return JsonResponse(data=data, safe=False, status=201)
def get(self, request):
start = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)
end = start.replace(hour=23, minute=59, second=59, microsecond=999999)
visits = Visit.objects.filter(created_at__lte=end, created_at__gte=start).prefetch_related()
serializer = VisitSerializer(visits, many=True)
json = JSONRenderer().render(serializer.data)
return JsonResponse(data=json.decode(), safe=False, status=200)

Loading…
Cancel
Save