Example #1
0
def edit_hack(request, slug, template_name="hack/hack_form.html"):

    hack = get_object_or_404(Hack, slug=slug)
    form = HackForm(request.POST or None, instance=hack)

    if form.is_valid():
        modified_hack = form.save()
        modified_hack.last_modified_by = request.user
        modified_hack.save()

        return HttpResponseRedirect(reverse("hack", kwargs={"slug": modified_hack.slug}))

    return render_to_response(template_name, {
        "form": form,
        "hack": hack,
        "repos": repos_for_js(),
        "action": "edit",
        },
        context_instance=RequestContext(request))
Example #2
0
def add_hack(request, template_name="hack/hack_form.html"):

    new_hack = Hack()
    form = HackForm(request.POST or None, instance=new_hack)

    if form.is_valid():
        new_hack = form.save()
        new_hack.created_by = request.user
        new_hack.last_modified_by = request.user
        new_hack.fetch_metadata()
        new_hack.save()
        return HttpResponseRedirect(reverse("hack", kwargs={"slug":new_hack.slug}))

    return render_to_response(template_name, {
        "form": form,
        "repos": repos_for_js(),
        "action": "add",
        },
        context_instance=RequestContext(request))