def tournament_registration(request):
    if request.method == 'POST':  # If the form has been submitted...
        pform = ParticipantForm(request.POST)  # A form bound to the POST data
        rform = CompetitionRegistrationForm(request.POST)
        tournament = Tournament.objects.get(tournament_title__iexact=request.POST["tournament"])
        if pform.is_valid() and rform.is_valid():  # All validation rules pass
            last_name = request.POST["last_name"]
            first_name = request.POST["first_name"]
            middle_name = request.POST["middle_name"]
            try:
                participant = Participant.objects.get(last_name__iexact=last_name, first_name__iexact=first_name,
                                                      middle_name__iexact=middle_name)
            except Participant.DoesNotExist:
                participant = pform.save()
            new_tournament_registration = rform.save(commit=False)
            new_tournament_registration.participant = participant
            new_tournament_registration.tournament = tournament
            new_tournament_registration.save()
            tournament.participants_list.add(participant)
            return HttpResponseRedirect('/participants-lists/')  # Redirect after POST
    else:
        pform = ParticipantForm()
        rform = CompetitionRegistrationForm()
    active_tournaments = Tournament.objects.filter(future_tournament=True)
    return render(request, "competitions/kat_competitionregistration_page.html",
                  {"pform": pform, "rform": rform, "active_tournaments": active_tournaments})

    # def tournament_registration(request):
    #     last_name = request.POST["last_name"]
    #     first_name = request.POST["first_name"]
    #     middle_name = request.POST["middle_name"]
    #
    #     # try:
    #     #     participant = Participant.objects.get(last_name__iexact=last_name, first_name__iexact=first_name,
    #     #                                           middle_name__iexact=middle_name)
    #     # except Participant.DoesNotExist:
    #     sex = request.POST["sex"]
    #     birth_date = request.POST["birth_date"]
    #     participant = Participant(last_name=last_name, first_name=first_name, middle_name=middle_name,
    #                               sex=sex, birth_date=birth_date)
    #     participant.save()
    #     club = request.POST["club"]
    #     city = request.POST["city"]
    #     tournament = Tournament.objects.get(tournament_title__iexact=request.POST["tournament"])
    #     new_tournament_registration = CompetitionRegistration(participant=participant, participant_club=club,
    #                                                           participant_location=city, tournament=tournament)
    #     new_tournament_registration.save()
    #     return render_to_response("kat_main_page.html", RequestContext(request))
Beispiel #2
0
def survey_first(request):
    if request.method == 'POST':
        form = ParticipantForm(request.POST)
        if form.is_valid():
            try:
                participant = Participant.objects.get(session = request.session.session_key)
            except Participant.DoesNotExist:
                participant = form.save(commit=False)
                participant.session = request.session.session_key
                participant.save()
                #request.session['participant_id'] = participant.pk
            return HttpResponseRedirect(reverse('survey-page'))
    else:
        form = ParticipantForm()
    
    return render_to_response('first.html', {
                                             'form': form,
                                             },
                                             context_instance=RequestContext(request))
Beispiel #3
0
def tournament_registration(request):
    if request.method == 'POST':  # If the form has been submitted...
        pform = ParticipantForm(request.POST)  # A form bound to the POST data
        rform = CompetitionRegistrationForm(request.POST)
        tournament = Tournament.objects.get(
            tournament_title__iexact=request.POST["tournament"])
        if pform.is_valid() and rform.is_valid():  # All validation rules pass
            last_name = request.POST["last_name"]
            first_name = request.POST["first_name"]
            middle_name = request.POST["middle_name"]
            try:
                participant = Participant.objects.get(
                    last_name__iexact=last_name,
                    first_name__iexact=first_name,
                    middle_name__iexact=middle_name)
            except Participant.DoesNotExist:
                participant = pform.save()
            new_tournament_registration = rform.save(commit=False)
            new_tournament_registration.participant = participant
            new_tournament_registration.tournament = tournament
            new_tournament_registration.save()
            tournament.participants_list.add(participant)
            return HttpResponseRedirect(
                '/participants-lists/')  # Redirect after POST
    else:
        pform = ParticipantForm()
        rform = CompetitionRegistrationForm()
    active_tournaments = Tournament.objects.filter(future_tournament=True)
    return render(request,
                  "competitions/kat_competitionregistration_page.html", {
                      "pform": pform,
                      "rform": rform,
                      "active_tournaments": active_tournaments
                  })