Beispiel #1
0
def compoentry_edit(request, event_id, compo_id, entry_id):
    # Get compo
    compo = get_object_or_404(Compo, pk=int(compo_id))
    
    # Check if user is allowed to edit
    if datetime.now() >= compo.editing_end:
        raise Http403
    
    # Get entry (make sure the user owns it, too)
    entry = get_object_or_404(Entry, pk=int(entry_id), compo=compo, user=request.user)
    
    # Handle entry adding
    if request.method == 'POST':
        entryform = EntryForm(request.POST, request.FILES, instance=entry, compo=compo)
        if entryform.is_valid():
            entryform.save()
            return HttpResponseRedirect(reverse('km:compo', args=(event_id, compo_id,)))
    else:
        entryform = EntryForm(instance=entry, compo=compo)
    
    # Dump template
    return render(request, 'kompomaatti/entry_edit.html', {
        'sel_event_id': int(event_id),
        'compo': compo,
        'entry': entry,
        'entryform': entryform,
    })
Beispiel #2
0
def editentry(request, entry_id):
    # Check if entry exists and get the object
    try:
        entry = Entry.objects.get(id=entry_id)
    except ObjectDoesNotExist:
        raise Http404
    
    # Make sure the user owns the entry
    if entry.user != request.user:
        raise Http404
    
    # Make sure the compo is active and if adding time is open
    if not entry.compo.active or entry.compo.editing_end < datetime.now():
        raise Http404
    
    # Check if we got filled form    
    if request.method == 'POST':
        editform = EntryForm(request.POST, request.FILES, instance=entry, editing=True, compo=entry.compo, legend="Muokkaa tuotosta")
        if editform.is_valid():
            editform.save()
            return HttpResponseRedirect('/kompomaatti/myentries/') 
    else:
        editform = EntryForm(instance=entry, editing=True, compo=entry.compo, legend="Muokkaa tuotosta")
    
    # Return the edit form
    return custom_render(request, 'kompomaatti/editentry.html', {
        'editform': editform,
        'entry': entry,
    })
Beispiel #3
0
def compoentry_edit(request, event_id, compo_id, entry_id):
    # Get compo
    compo = get_object_or_404(Compo, pk=int(compo_id))
    
    # Check if user is allowed to edit
    if timezone.now() >= compo.editing_end:
        raise Http403
    
    # Get entry (make sure the user owns it, too)
    entry = get_object_or_404(Entry, pk=int(entry_id), compo=compo, user=request.user)
    
    # Handle entry adding
    if request.method == 'POST':
        entryform = EntryForm(request.POST, request.FILES, instance=entry, compo=compo)
        if entryform.is_valid():
            entryform.save()
            return HttpResponseRedirect(reverse('km:compo', args=(event_id, compo_id,)))
    else:
        entryform = EntryForm(instance=entry, compo=compo)
    
    # Dump template
    return render(request, 'kompomaatti/entry_edit.html', {
        'sel_event_id': int(event_id),
        'compo': compo,
        'entry': entry,
        'entryform': entryform,
    })
Beispiel #4
0
def addentry(request, compo_id):
    # Check if entry exists and get the object
    try:
        compo = Compo.objects.get(id=compo_id)
    except ObjectDoesNotExist:
        raise Http404
    
    # Make sure the compo is active and if adding time is open
    if not compo.active or compo.adding_end < datetime.now():
        raise Http404
    
    # Check if we got filled form
    if request.method == 'POST':
        addform = EntryForm(request.POST, request.FILES, compo=compo, legend="Uusi tuotos")
        if addform.is_valid():
            nentry = addform.save(commit=False)
            nentry.user = request.user
            nentry.compo = compo
            nentry.save()
            return HttpResponseRedirect('/kompomaatti/myentries/') 
    else:
        addform = EntryForm(compo=compo, legend="Uusi tuotos")

    # Return the edit form
    return custom_render(request, 'kompomaatti/addentry.html', {
        'addform': addform,
        'compo': compo,
    })
Beispiel #5
0
def compo_details(request, event_id, compo_id):
    # Get compo
    compo = compo_times_formatter(get_object_or_404(Compo, pk=compo_id, active=True, event=event_id))
    
    # Check if user may vote (voting open, user has code)
    can_vote = False
    if request.user.is_active and request.user.is_authenticated():
        try:
            VoteCode.objects.get(associated_to=request.user, event=event_id)
            can_vote = True
        except VoteCode.DoesNotExist:
            pass

        # See if ticket is used as votecode
        try:
            TicketVoteCode.objects.get(associated_to=request.user, event=event_id)
            can_vote = True
        except TicketVoteCode.DoesNotExist:
            pass
        
    # Handle entry adding
    if request.method == 'POST' and compo.is_adding_open():
        # Make sure user is authenticated
        if not request.user.is_active or not request.user.is_authenticated():
            raise Http403
        
        # Handle data
        entryform = EntryForm(request.POST, request.FILES, compo=compo)
        if entryform.is_valid():
            entry = entryform.save(commit=False)
            entry.user = request.user
            entry.compo = compo
            entry.save()
            return HttpResponseRedirect(reverse('km:compo', args=(event_id, compo_id,)))
    else:
        entryform = EntryForm(compo=compo)
    
    # Get entries, and only show them if voting has started
    # (only show results if it has been allowed in model)
    all_entries = []
    if compo.has_voting_started:
        if compo.show_voting_results:
            all_entries = entrysort.sort_by_score(Entry.objects.filter(compo=compo))
        else:
            all_entries = Entry.objects.filter(compo=compo).order_by('name')
    
    # Stuff for users that have logged in 
    my_entries = []
    has_voted = False
    if request.user.is_active and request.user.is_authenticated():
        # Get all entries added by the user
        my_entries = Entry.objects.filter(compo=compo, user=request.user)
    
        # Check if user has already voted
        if Vote.objects.filter(user=request.user, compo=compo).count() > 0:
            has_voted = True
    
    # Dump template
    return render(request, 'kompomaatti/compo_details.html', {
        'sel_event_id': int(event_id),
        'compo': compo,
        'entryform': entryform,
        'can_vote': can_vote,
        'all_entries': all_entries,
        'my_entries': my_entries,
        'has_voted': has_voted,
    })
Beispiel #6
0
def compo_details(request, event_id, compo_id):
    # Get compo
    compo = compo_times_formatter(get_object_or_404(Compo, pk=compo_id, active=True, event=event_id))
    
    # Check if user may vote (voting open, user has code)
    can_vote = False
    if request.user.is_active and request.user.is_authenticated:
        # See if ticket is used as votecode
        try:
            TicketVoteCode.objects.get(associated_to=request.user, event=event_id)
            can_vote = True
        except TicketVoteCode.DoesNotExist:
            pass

        if not can_vote:
            try:
                VoteCodeRequest.objects.get(user=request.user, event=event_id, status=1)
                can_vote = True
            except VoteCodeRequest.DoesNotExist:
                pass

    # Handle entry adding
    if request.method == 'POST' and compo.is_adding_open():
        # Make sure user is authenticated
        if not request.user.is_active or not request.user.is_authenticated:
            raise Http403
        
        # Handle data
        entryform = EntryForm(request.POST, request.FILES, compo=compo)
        if entryform.is_valid():
            entry = entryform.save(commit=False)
            entry.user = request.user
            entry.compo = compo
            entry.save()
            return HttpResponseRedirect(reverse('km:compo', args=(event_id, compo_id,)))
    else:
        entryform = EntryForm(compo=compo)
    
    # Get entries, and only show them if voting has started
    # (only show results if it has been allowed in model)
    all_entries = []
    if compo.has_voting_started:
        if compo.show_voting_results:
            all_entries = entrysort.sort_by_score(Entry.objects.filter(compo=compo))
        else:
            all_entries = Entry.objects.filter(compo=compo).order_by('name')
    
    # Stuff for users that have logged in 
    my_entries = []
    has_voted = False
    if request.user.is_active and request.user.is_authenticated:
        # Get all entries added by the user
        my_entries = Entry.objects.filter(compo=compo, user=request.user)
    
        # Check if user has already voted
        if Vote.objects.filter(user=request.user, compo=compo).count() > 0:
            has_voted = True
    
    # Dump template
    return render(request, 'kompomaatti/compo_details.html', {
        'sel_event_id': int(event_id),
        'compo': compo,
        'entryform': entryform,
        'can_vote': can_vote,
        'all_entries': all_entries,
        'my_entries': my_entries,
        'has_voted': has_voted,
    })