コード例 #1
0
ファイル: views.py プロジェクト: Artikulpi/public_courts
def admin_view_case(request, case_id):
    try:
        case = Case.objects.get(pk=case_id)
        imprisonments = Imprisonment.objects.filter(case=case)
        criminal_fineses = CriminalFines.objects.filter(case=case)
    except ObjectDoesNotExist:
        raise Http404

    ImprisonmentFormSet = inlineformset_factory(Case, Imprisonment)
    CriminalFinesFormSet = inlineformset_factory(Case, CriminalFines)

    if request.method == "POST":
        form = CaseForm(request.POST, request.FILES, instance=case)
        if form.is_valid():
            form.save()

            formset = ImprisonmentFormSet(request.POST, instance=case)
            cfformset = CriminalFinesFormSet(request.POST, instance=case)
            if formset.is_valid() and cfformset.is_valid():
                formset.save()
                cfformset.save()

            return HttpResponseRedirect("./")
    else:
        form = CaseForm(instance=case)
        formset = ImprisonmentFormSet(instance=case)
        cfformset = CriminalFinesFormSet(instance=case)

    return render_to_response(
        "corruption/admin/view_case.html",
        {
            "case": case,
            "form": form,
            "imprisonments": imprisonments,
            "criminal_fineses": criminal_fineses,
            "formset": formset,
            "cfformset": cfformset,
        },
        context_instance=RequestContext(request),
    )
コード例 #2
0
ファイル: views.py プロジェクト: Artikulpi/public_courts
def admin(request):
    ImprisonmentFormSet = inlineformset_factory(Case, Imprisonment, can_delete=False)
    CriminalFinesFormSet = inlineformset_factory(Case, CriminalFines, can_delete=False)
    if request.method == "POST":
        form = CaseForm(request.POST, request.FILES)
        if form.is_valid():
            case_instance = form.save()
            formset = ImprisonmentFormSet(request.POST, instance=case_instance)
            if formset.is_valid():
                formset.save()

            cfformset = CriminalFinesFormSet(request.POST, instance=case_instance)
            if cfformset.is_valid():
                cfformset.save()

            return HttpResponseRedirect("./")
    else:
        form = CaseForm()
        formset = ImprisonmentFormSet()
        cfformset = CriminalFinesFormSet()

    cases_list = Case.objects.all().order_by("-id")
    paginator = Paginator(cases_list, 10)
    page = request.GET.get("page")
    try:
        cases = paginator.page(page)
    except PageNotAnInteger:
        cases = paginator.page(1)
    except EmptyPage:
        cases = paginator.page(paginator.num_pages)

    return render_to_response(
        "corruption/admin/home.html",
        {"cases": cases, "form": form, "formset": formset, "cfformset": cfformset},
        context_instance=RequestContext(request),
    )
コード例 #3
0
ファイル: views.py プロジェクト: Artikulpi/public_courts
def admin(request):
    ImprisonmentFormSet = inlineformset_factory(Case,
                                                Imprisonment,
                                                can_delete=False)
    CriminalFinesFormSet = inlineformset_factory(Case,
                                                 CriminalFines,
                                                 can_delete=False)
    if request.method == "POST":
        form = CaseForm(request.POST, request.FILES)
        if form.is_valid():
            case_instance = form.save()
            formset = ImprisonmentFormSet(request.POST, instance=case_instance)
            if formset.is_valid():
                formset.save()

            cfformset = CriminalFinesFormSet(request.POST,
                                             instance=case_instance)
            if cfformset.is_valid():
                cfformset.save()

            return HttpResponseRedirect('./')
    else:
        form = CaseForm()
        formset = ImprisonmentFormSet()
        cfformset = CriminalFinesFormSet()

    cases_list = Case.objects.all().order_by("-id")
    paginator = Paginator(cases_list, 10)
    page = request.GET.get('page')
    try:
        cases = paginator.page(page)
    except PageNotAnInteger:
        cases = paginator.page(1)
    except EmptyPage:
        cases = paginator.page(paginator.num_pages)

    return render_to_response("corruption/admin/home.html", {
        "cases": cases,
        "form": form,
        "formset": formset,
        "cfformset": cfformset,
    },
                              context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: Artikulpi/public_courts

@admin_required
def admin_view_case(request, case_id):
    try:
        case = Case.objects.get(pk=case_id)
        imprisonments = Imprisonment.objects.filter(case=case)
        criminal_fineses = CriminalFines.objects.filter(case=case)
    except ObjectDoesNotExist:
        raise Http404

    ImprisonmentFormSet = inlineformset_factory(Case, Imprisonment)
    CriminalFinesFormSet = inlineformset_factory(Case, CriminalFines)

    if request.method == "POST":
        form = CaseForm(request.POST, request.FILES, instance=case)
        if form.is_valid():
            form.save()

            formset = ImprisonmentFormSet(request.POST, instance=case)
            cfformset = CriminalFinesFormSet(request.POST, instance=case)
            if formset.is_valid() and cfformset.is_valid():
                formset.save()
                cfformset.save()

            return HttpResponseRedirect('./')
    else:
        form = CaseForm(instance=case)
        formset = ImprisonmentFormSet(instance=case)
        cfformset = CriminalFinesFormSet(instance=case)