Example #1
0
def update_ctf(request, ctf_slug):
    ctf = get_object_or_404(Competition.objects, slug=ctf_slug)
    if request.method == 'GET':
        data = {
            'ctf': ctf,
            'form': CompetitionModelForm(instance=ctf)
        }
        return render_to_response('ctf/update.html', data, RequestContext(request))

    elif request.method == 'POST':
        form = CompetitionModelForm(request.POST, instance=ctf)
        saved = False
        if form.is_valid():
            form.save()
            saved = True

        data = {
            'ctf': ctf,
            'form': form,
            'saved': saved
        }
        return render_to_response('ctf/update.html', data, RequestContext(request))
Example #2
0
def add_ctf(request):
    if request.method == 'GET':
        form = CompetitionModelForm()
        data = {
            'form': form
        }
        return render_to_response('ctf/add.html', data, RequestContext(request))

    elif request.method == 'POST':
        form = CompetitionModelForm(request.POST)
        data = {
            'form': form
        }

        if form.is_valid():
            competition = form.save(commit=False)
            competition.slug = slugify(competition.name)
            competition.save()
            data['competition'] = competition
            return redirect(competition.get_absolute_url())

        # url tbd
        return render_to_response('ctf/add.html', data, RequestContext(request))