def check_in(request, year, event_pk): event = get_object_or_404(Event, pk=event_pk) participants = Participant.objects.filter(event=event).all() react_props = { 'participants': [serializers.participant(participant) for participant in participants], 'event_id': event_pk } return render(request, 'events/check_in.html', {'react_props': json.dumps(react_props)})
def get_by_token(request, event_pk, check_in_token): """ Endpoint to get a participant by their check in token """ event = get_object_or_404(Event, pk=event_pk) participant = Participant.objects.filter( event=event, check_in_token=check_in_token).first() if participant is None: return JsonResponse( {'message': 'No participant with that check_in_token.'}, status=404) return JsonResponse({'participant': serializers.participant(participant)}, status=200)
def update_team(request, event_pk, team_pk): """ Endpoint to update a team """ event = get_object_or_404(Event, pk=event_pk) team = get_object_or_404(Team, pk=team_pk) if not request.user: return JsonResponse({'message': 'Authentication required.'}, status=403) team_member = TeamMember.objects.filter(participant__user_s=request.user, team=team).first() if not team_member and team_member.leader: return JsonResponse( {'message': 'Only the team leader can edit the team.'}, status=403) data = json.loads(request.body) if 'name' not in data or 'members' not in data: return JsonResponse({'message': 'Bad request.'}, status=400) Team.objects.filter(id=team_pk).update(name=data['name']) ids = [member['id'] for member in data['members']] team.teammember_set.exclude(id__in=ids).delete() teams = Team.objects.filter(event=event, allow_join_s=True).all() participant = Participant.objects.get(user_s=request.user, event=event) return JsonResponse( { 'teams': [serializers.team(team) for team in teams], 'participant': serializers.participant(participant) }, status=200)
def signup(request, event_pk): """ Endpoint to signup to events """ event = get_object_or_404(Event, pk=event_pk) if not request.user: return JsonResponse({'message': 'Authentication required.'}, status=403) if not event.open_for_signup: return JsonResponse({'message': 'Event not open for sign ups.'}, status=403) participant, _created = Participant.objects.get_or_create( user_s=request.user, event=event) if event.fee_s > 0 and not participant.fee_payed_s: return JsonResponse({'message': 'Fee has not been payed'}, status=400) data = json.loads(request.body) answers = data['answers'] questions = SignupQuestion.objects.filter(event=event).all() for question in questions: SignupQuestionAnswer.objects.update_or_create( participant=participant, signup_question=question, defaults={'answer': answers[str(question.pk)]}) # TODO Check that all required questions have been answered participant.signup_complete = True participant.save() return JsonResponse({'participant': serializers.participant(participant)}, status=201)