Beispiel #1
0
def competition_edit(request, sel_event_id, competition_id):
    # CHeck for permissions
    if not request.user.has_perm('kompomaatti.change_competition'):
        raise Http403
    
    # Get competition
    competition = get_object_or_404(Competition, pk=competition_id)
    
    # Handle form
    if request.method == "POST":
        competitionform = AdminCompetitionForm(request.POST, instance=competition)
        if competitionform.is_valid():
            c = competitionform.save()
            logger.info('Competition "{}" edited.'.format(c.name),
                        extra={'user': request.user, 'event_id': sel_event_id})
            return HttpResponseRedirect(reverse('manage-kompomaatti:competitions', args=(sel_event_id,))) 
    else:
        competitionform = AdminCompetitionForm(instance=competition)
    
    # Render response
    return admin_render(request, "admin_kompomaatti/competition_edit.html", {
        'competition': competition,
        'competitionform': competitionform,
        'selected_event_id': int(sel_event_id),
    })
Beispiel #2
0
def competitions_browse(request, sel_event_id):
    # Get competitions
    competitions = Competition.objects.filter(event_id=int(sel_event_id))
    
    # Form handling
    if request.method == "POST":
        # CHeck for permissions
        if not request.user.has_perm('kompomaatti.add_competition'):
            raise Http403
        
        # Handle form
        competitionform = AdminCompetitionForm(request.POST)
        if competitionform.is_valid():
            data = competitionform.save(commit=False)
            data.event_id = int(sel_event_id)
            data.save()
            logger.info('Competition "{}" added.'.format(data.name),
                        extra={'user': request.user, 'event_id': sel_event_id})
            return HttpResponseRedirect(reverse('manage-kompomaatti:competitions', args=(sel_event_id,))) 
    else:
        competitionform = AdminCompetitionForm()
    
    # Render response
    return admin_render(request, "admin_kompomaatti/competitions.html", {
        'competitions': competitions,
        'competitionform': competitionform,
        'selected_event_id': int(sel_event_id),
    })
Beispiel #3
0
def competition_edit(request, sel_event_id, competition_id):
    # CHeck for permissions
    if not request.user.has_perm('kompomaatti.change_competition'):
        raise Http403

    # Get competition
    competition = get_object_or_404(Competition, pk=competition_id)

    # Handle form
    if request.method == "POST":
        competitionform = AdminCompetitionForm(request.POST,
                                               instance=competition)
        if competitionform.is_valid():
            c = competitionform.save()
            logger.info('Competition "{}" edited.'.format(c.name),
                        extra={
                            'user': request.user,
                            'event_id': sel_event_id
                        })
            return HttpResponseRedirect(
                reverse('manage-kompomaatti:competitions',
                        args=(sel_event_id, )))
    else:
        competitionform = AdminCompetitionForm(instance=competition)

    # Render response
    return admin_render(
        request, "admin_kompomaatti/competition_edit.html", {
            'competition': competition,
            'competitionform': competitionform,
            'selected_event_id': int(sel_event_id),
        })
Beispiel #4
0
def competitions_browse(request, sel_event_id):
    # Get competitions
    competitions = Competition.objects.filter(event_id=int(sel_event_id))

    # Form handling
    if request.method == "POST":
        # CHeck for permissions
        if not request.user.has_perm('kompomaatti.add_competition'):
            raise Http403

        # Handle form
        competitionform = AdminCompetitionForm(request.POST)
        if competitionform.is_valid():
            data = competitionform.save(commit=False)
            data.event_id = int(sel_event_id)
            data.save()
            logger.info('Competition "{}" added.'.format(data.name),
                        extra={
                            'user': request.user,
                            'event_id': sel_event_id
                        })
            return HttpResponseRedirect(
                reverse('manage-kompomaatti:competitions',
                        args=(sel_event_id, )))
    else:
        competitionform = AdminCompetitionForm()

    # Render response
    return admin_render(
        request, "admin_kompomaatti/competitions.html", {
            'competitions': competitions,
            'competitionform': competitionform,
            'selected_event_id': int(sel_event_id),
        })