Exemplo n.º 1
0
def add_challenge(request, ctf_slug):
    ctf = get_object_or_404(Competition.objects, slug=ctf_slug)
    if request.method == 'GET':
        form = ChallengeModelForm(initial={'competition': ctf})
        data = {
            'form': form,
            'ctf': ctf
        }
        return render_to_response('ctf/challenge/add.html', data, RequestContext(request))

    elif request.method == 'POST':
        form = ChallengeModelForm(request.POST)
        data = {
            'form': form,
            'ctf': ctf
        }

        if form.is_valid():
            challenge = form.save(commit=False)
            challenge.competition = ctf
            challenge.last_viewed = datetime.now()
            challenge.slug = slugify(challenge.name)
            challenge.save()
            return redirect(ctf.get_absolute_url())

        return render_to_response('ctf/challenge/add.html', data, RequestContext(request))
Exemplo n.º 2
0
def update_challenge(request, ctf_slug, chall_slug):
    ctf = get_object_or_404(Competition.objects, slug=ctf_slug)
    challenge = get_object_or_404(Challenge.objects,
                                  competition=ctf,
                                  slug=chall_slug)
    if request.method == 'GET':
        data = {
            'ctf': ctf,
            'challenge': challenge,
            'form': ChallengeModelForm(instance=challenge)
        }
        return render_to_response('ctf/challenge/update.html', data,
                                  RequestContext(request))

    elif request.method == 'POST':
        form = ChallengeModelForm(request.POST, instance=challenge)
        saved = False
        if form.is_valid():
            challenge = form.save(commit=False)
            challenge.last_viewed = datetime.now()
            challenge.save()
            saved = True
            return redirect(challenge.get_absolute_url())

        data = {
            'ctf': ctf,
            'challenge': challenge,
            'form': ChallengeModelForm(instance=challenge),
            'saved': saved
        }
        return render_to_response('ctf/challenge/update.html', data,
                                  RequestContext(request))
Exemplo n.º 3
0
def update_challenge(request, ctf_slug, chall_slug):
    ctf = get_object_or_404(Competition.objects, slug=ctf_slug)
    challenge = get_object_or_404(Challenge.objects, competition=ctf, slug=chall_slug)
    if request.method == 'GET':
        data = {
            'ctf': ctf,
            'challenge': challenge,
            'form': ChallengeModelForm(instance=challenge)
        }
        return render_to_response('ctf/challenge/update.html', data, RequestContext(request))

    elif request.method == 'POST':
        form = ChallengeModelForm(request.POST, instance=challenge)
        saved = False
        if form.is_valid():
            challenge = form.save(commit=False)
            challenge.last_viewed = datetime.now()
            challenge.save()
            saved = True
            return redirect(challenge.get_absolute_url())

        data = {
            'ctf': ctf,
            'challenge': challenge,
            'form': ChallengeModelForm(instance=challenge),
            'saved': saved
        }
        return render_to_response('ctf/challenge/update.html', data, RequestContext(request))
Exemplo n.º 4
0
def add_challenge(request, ctf_slug):
    ctf = get_object_or_404(Competition.objects, slug=ctf_slug)
    if request.method == 'GET':
        form = ChallengeModelForm(initial={'competition': ctf})
        data = {'form': form, 'ctf': ctf}
        return render_to_response('ctf/challenge/add.html', data,
                                  RequestContext(request))

    elif request.method == 'POST':
        form = ChallengeModelForm(request.POST)
        data = {'form': form, 'ctf': ctf}

        if form.is_valid():
            challenge = form.save(commit=False)
            challenge.competition = ctf
            challenge.last_viewed = datetime.now()
            challenge.slug = slugify(challenge.name)
            challenge.save()
            return redirect(ctf.get_absolute_url())

        return render_to_response('ctf/challenge/add.html', data,
                                  RequestContext(request))