Example #1
0
def generate(request, poll_name):
    amount = request.GET.get('amount', None)
    poll = Poll.objects.get(url=poll_name)
    context = {
        'poll': poll,
        'generate': True
    }

    if amount is not None:
        tokens = [
            Token.generate(poll)
            for _ in range(int(amount))
            ]
        context['tokens'] = tokens
    return render(
        request,
            'polls/token/gen.html',
        context
    )
Example #2
0
def generate_user_token(request, poll_name):
    poll = Poll.objects.get(url=poll_name)
    try:
        t = Token.objects.get(
            poll=poll,
            user=request.user
        )
        return render_to_response(
            'polls/error/has_token.html',
            { 'token': t }
        )
    except Token.DoesNotExist:
        token = Token.generate(
            poll=poll,
            user=request.user
        )
        return render(
            request,
            'polls/token/overview.html',
            {'tokens': [token]}
        )