Esempio n. 1
0
def dashboard(request): 
    # Get list of users entries
    my_entries = Entry.objects.filter(user=request.user)
    
    # Get list of open compos, format times
    open_compos = Compo.objects.filter(active=True, adding_end__gte = datetime.now())
    oclist = []
    for compo in open_compos:
        formatted_compo = compo_times_formatter(compo)
        oclist.append(formatted_compo)

    # Check if we got data from vote code assoc form
    if request.method == 'POST' and request.POST['formtype'] == 'votecodeassocform':
        assocform = VoteCodeAssocForm(request.POST)
        if assocform.is_valid():
            code = assocform.cleaned_data['code']
            try:
                vc = VoteCode.objects.get(key=code)
                vc.associated_to = request.user
                vc.time = datetime.now()
                vc.save()
            except VoteCode.DoesNotExist:
                pass
            return HttpResponseRedirect('/kompomaatti/myentries/') 
    else:
        assocform = VoteCodeAssocForm()
    
    # Get last VoteCodeRequest, if it exists
    try:
        vcreq = VoteCodeRequest.objects.get(user=request.user)
    except VoteCodeRequest.DoesNotExist:
        vcreq = None
    
    # Check if we got data from vote code request form
    if request.method == 'POST' and request.POST['formtype'] == 'requestvotecodeform':
        requestform = RequestVoteCodeForm(request.POST)
        if requestform.is_valid():
            if vcreq:
                vcreq.text = requestform.cleaned_data['text']
                vcreq.save()
            else:
                req = requestform.save(commit=False)
                req.user = request.user
                req.save()
            return HttpResponseRedirect('/kompomaatti/myentries/') 
    else:
        if vcreq:
            requestform = RequestVoteCodeForm(instance=vcreq)
        else:
            requestform = RequestVoteCodeForm()
        
    # Dump the page to the user
    return custom_render(request, 'kompomaatti/myentries.html', {
        'myentries': my_entries,
        'opencompos': oclist,
        'user': request.user,
        'assocform': assocform,
        'requestform': requestform,
    })
Esempio n. 2
0
def votecode(request, event_id):
    # Get event
    event = get_object_or_404(Event, pk=int(event_id))
        
    # Check if user has the right to vote via separate vote code
    reserved_code = None
    can_vote = False
    votecode_type = None
    try:
        separate_votecode = VoteCode.objects.get(event=event, associated_to=request.user)
        reserved_code = separate_votecode.key
        can_vote = True
        votecode_type = 'votecode'
    except VoteCode.DoesNotExist:
        pass

    # Check if user has the right to vote via ticket
    try:
        ticket_votecode = TicketVoteCode.objects.get(event=event, associated_to=request.user)
        reserved_code = ticket_votecode.ticket.key
        can_vote = True
        votecode_type = "ticket"
    except TicketVoteCode.DoesNotExist:
        pass

    # Check if request for vote code has been made
    request_made = False
    try:
        VoteCodeRequest.objects.get(event=event, user=request.user)
        request_made = True
    except VoteCodeRequest.DoesNotExist:
        pass

    # Ticket votecode association form
    if request.method == 'POST' and 'submit-ticketvcassoc' in request.POST:
        ticket_votecode_form = TicketVoteCodeAssocForm(request.POST, event=event, user=request.user)
        if ticket_votecode_form.is_valid():
            ticket_votecode_form.save()
            return HttpResponseRedirect(reverse('km:votecode', args=(event_id,)))
    else:
        ticket_votecode_form = TicketVoteCodeAssocForm(event=event, user=request.user)

    # Votecode Association form
    if request.method == 'POST' and 'submit-vcassoc' in request.POST:
        votecodeassocform = VoteCodeAssocForm(request.POST, event=event, user=request.user)
        if votecodeassocform.is_valid():
            votecodeassocform.save()
            return HttpResponseRedirect(reverse('km:votecode', args=(event_id,)))
    else:
        votecodeassocform = VoteCodeAssocForm(event=event, user=request.user)
    
    # Votecode Request form
    if request.method == 'POST' and 'submit-vcreq' in request.POST:
        votecoderequestform = VoteCodeRequestForm(request.POST)
        if votecoderequestform.is_valid():
            vcr = votecoderequestform.save(commit=False)
            vcr.user = request.user
            vcr.event = event
            vcr.save()
            return HttpResponseRedirect(reverse('km:votecode', args=(event_id,)))
    else:
        votecoderequestform = VoteCodeRequestForm()
    
    # Render
    return render(request, 'kompomaatti/votecode.html', {
        'sel_event_id': int(event_id),
        'votecodeassocform': votecodeassocform,
        'votecoderequestform': votecoderequestform,
        'ticket_votecode_form': ticket_votecode_form,
        'reserved_code': reserved_code,
        'can_vote': can_vote,
        'votecode_type': votecode_type,
        'request_made': request_made,
    })
Esempio n. 3
0
def votecode(request, event_id):
    # Get event
    event = get_object_or_404(Event, pk=int(event_id))

    # Check if user has the right to vote via separate vote code
    reserved_code = None
    can_vote = False
    votecode_type = None
    try:
        separate_votecode = VoteCode.objects.get(event=event,
                                                 associated_to=request.user)
        reserved_code = separate_votecode.key
        can_vote = True
        votecode_type = 'votecode'
    except VoteCode.DoesNotExist:
        pass

    # Check if user has the right to vote via ticket
    try:
        ticket_votecode = TicketVoteCode.objects.get(
            event=event, associated_to=request.user)
        reserved_code = ticket_votecode.ticket.key
        can_vote = True
        votecode_type = "ticket"
    except TicketVoteCode.DoesNotExist:
        pass

    # Check if request for vote code has been made
    request_made = False
    try:
        VoteCodeRequest.objects.get(event=event, user=request.user)
        request_made = True
    except VoteCodeRequest.DoesNotExist:
        pass

    # Ticket votecode association form
    if request.method == 'POST' and 'submit-ticketvcassoc' in request.POST:
        ticket_votecode_form = TicketVoteCodeAssocForm(request.POST,
                                                       event=event,
                                                       user=request.user)
        if ticket_votecode_form.is_valid():
            ticket_votecode_form.save()
            return HttpResponseRedirect(
                reverse('km:votecode', args=(event_id, )))
    else:
        ticket_votecode_form = TicketVoteCodeAssocForm(event=event,
                                                       user=request.user)

    # Votecode Association form
    if request.method == 'POST' and 'submit-vcassoc' in request.POST:
        votecodeassocform = VoteCodeAssocForm(request.POST,
                                              event=event,
                                              user=request.user)
        if votecodeassocform.is_valid():
            votecodeassocform.save()
            return HttpResponseRedirect(
                reverse('km:votecode', args=(event_id, )))
    else:
        votecodeassocform = VoteCodeAssocForm(event=event, user=request.user)

    # Votecode Request form
    if request.method == 'POST' and 'submit-vcreq' in request.POST:
        votecoderequestform = VoteCodeRequestForm(request.POST)
        if votecoderequestform.is_valid():
            vcr = votecoderequestform.save(commit=False)
            vcr.user = request.user
            vcr.event = event
            vcr.save()
            return HttpResponseRedirect(
                reverse('km:votecode', args=(event_id, )))
    else:
        votecoderequestform = VoteCodeRequestForm()

    # Render
    return render(
        request, 'kompomaatti/votecode.html', {
            'sel_event_id': int(event_id),
            'votecodeassocform': votecodeassocform,
            'votecoderequestform': votecoderequestform,
            'ticket_votecode_form': ticket_votecode_form,
            'reserved_code': reserved_code,
            'can_vote': can_vote,
            'votecode_type': votecode_type,
            'request_made': request_made,
        })