コード例 #1
0
ファイル: views.py プロジェクト: adborden/crisishacks
def add_deployment(request, slug, template_name="hack/add_deployment.html"):

    hack = get_object_or_404(Hack, slug=slug)
    new_hack_example = Deployment()
    form = DeploymentForm(request.POST or None, instance=new_hack_example)
    
    if form.is_valid() and request.POST:
        hack_example = Deployment(hack=hack,
                title=form.cleaned_data["title"],
                url=form.cleaned_data["url"],
                location=form.cleaned_data["location"],
                description=form.cleaned_data["description"],
                number_users=form.cleaned_data["number_users"],
                created_by=request.user,
                lat=form.cleaned_data["lat"],
                lng=form.cleaned_data["lng"],
                bbox=form.cleaned_data["bbox"])
        hack_example.save()
        return HttpResponseRedirect(reverse("hack", kwargs={"slug":hack_example.hack.slug}))

    return render_to_response(template_name, {
        "form": form,
        "hack":hack
        },
        context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: adborden/crisishacks
def edit_example(request, slug, id, template_name="hack/edit_example.html"):

    hack_example = get_object_or_404(Deployment, id=id)
    form = DeploymentForm(request.POST or None, instance=hack_example)

    if form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse("hack", kwargs={"slug": hack_example.hack.slug}))

    return render_to_response(template_name, {
        "form": form,
        "hack":hack_example.hack
        },
        context_instance=RequestContext(request))