コード例 #1
0
def edit_visualization(request, pk):
    # This could apparently also be done with formsets? But they seem awful.
    viz = get_object_or_404(SCOTUSMap, pk=pk, user=request.user)
    if request.method == 'POST':
        form_viz = VizEditForm(request.POST, instance=viz)
        if form_viz.is_valid():
            cd_viz = form_viz.cleaned_data

            viz.title = cd_viz['title']
            viz.notes = cd_viz['notes']
            viz.published = cd_viz['published']
            viz.save()

            return HttpResponseRedirect(
                reverse('view_visualization',
                        kwargs={
                            'pk': viz.pk,
                            'slug': viz.slug
                        }))
    else:
        form_viz = VizEditForm(instance=viz)
    return render(request, 'edit_visualization.html', {
        'form_viz': form_viz,
        'private': True
    })
コード例 #2
0
def edit_visualization(request: HttpRequest, pk: int) -> HttpResponse:
    # This could apparently also be done with formsets? But they seem awful.
    viz = get_object_or_404(SCOTUSMap, pk=pk, user=request.user)
    if request.method == "POST":
        form_viz = VizEditForm(request.POST, instance=viz)
        if form_viz.is_valid():
            cd_viz = form_viz.cleaned_data

            viz.title = cd_viz["title"]
            viz.notes = cd_viz["notes"]
            viz.published = cd_viz["published"]
            viz.save()

            return HttpResponseRedirect(
                reverse(
                    "view_visualization",
                    kwargs={"pk": viz.pk, "slug": viz.slug},
                )
            )
    else:
        form_viz = VizEditForm(instance=viz)
    return render(
        request,
        "edit_visualization.html",
        {"form_viz": form_viz, "private": True},
    )
コード例 #3
0
ファイル: views.py プロジェクト: Andr3iC/courtlistener
def edit_visualization(request, pk):
    # This could apparently also be done with formsets? But they seem awful.
    viz = get_object_or_404(SCOTUSMap, pk=pk, user=request.user)
    if request.method == 'POST':
        form_viz = VizEditForm(request.POST, instance=viz)
        if form_viz.is_valid():
            cd_viz = form_viz.cleaned_data

            viz.title = cd_viz['title']
            viz.notes = cd_viz['notes']
            viz.published = cd_viz['published']
            viz.save()

            return HttpResponseRedirect(reverse(
                'view_visualization',
                kwargs={'pk': viz.pk, 'slug': viz.slug}
            ))
    else:
        form_viz = VizEditForm(instance=viz)
    return render_to_response(
        'edit_visualization.html',
        {'form_viz': form_viz,
         'private': True},
        RequestContext(request),
    )