Ejemplo n.º 1
0
def new(request, lang):
    if request.method == 'POST':
        participant_form = ParticipantForm(request.POST)

        if participant_form.is_valid():
            participant = participant_form.save(commit=False)
            participant.ip = get_client_ip(request),
            participant.ua = get_client_ua(request),
            participant.save()

            sequences = Sequence.objects.all()
            pairs = Pair.objects.all()

            if len(sequences) > len(pairs):
                generate_pairs(len(sequences) - len(pairs) + 1)
                pairs = Pair.objects.all()
                send_email(template='email/pairs_empty.html')

            pairs = pairs[:len(sequences)]

            for sequence, pair in zip(sequences, pairs):
                question = Question(participant=participant,
                                    left=pair.left,
                                    right=pair.right,
                                    sequence=sequence,
                                    answered=False)
                question.save()
                pair.delete()

            request.session['participant_id'] = participant.id
            #messages.add_message(request, messages.SUCCESS, u'Новый участник создан')
            return redirect(reverse('core.views.index', kwargs={'lang': lang}))

    #messages.add_message(request, messages.ERROR, u'Не удалось создать участника')
    return redirect(reverse('core.views.index', kwargs={'lang': lang}))
Ejemplo n.º 2
0
def new(request, lang):
    if request.method == 'POST':
        participant_form = ParticipantForm(request.POST)

        if participant_form.is_valid():
            participant = participant_form.save(commit=False)
            participant.ip = get_client_ip(request),
            participant.ua = get_client_ua(request),
            participant.save()

            sequences = Sequence.objects.all()
            pairs = Pair.objects.all()

            if len(sequences) > len(pairs):
                generate_pairs(len(sequences) - len(pairs) + 1)
                pairs = Pair.objects.all()
                send_email(template='email/pairs_empty.html')

            pairs = pairs[:len(sequences)]

            for sequence, pair in zip(sequences, pairs):
                question = Question(
                    participant=participant,
                    left=pair.left,
                    right=pair.right,
                    sequence=sequence,
                    answered=False
                )
                question.save()
                pair.delete()

            request.session['participant_id'] = participant.id
            #messages.add_message(request, messages.SUCCESS, u'Новый участник создан')
            return redirect(reverse('core.views.index', kwargs={'lang': lang}))

    #messages.add_message(request, messages.ERROR, u'Не удалось создать участника')
    return redirect(reverse('core.views.index', kwargs={'lang': lang}))
Ejemplo n.º 3
0
def generate(request, number):
    generate_pairs(number)
    return redirect(reverse('core.views.cp'))
Ejemplo n.º 4
0
def generate(request, number):
    generate_pairs(number)
    return redirect(reverse('core.views.cp'))