コード例 #1
0
def field_update(request, pk):
    field = get_object_or_404(Field, pk=pk)

    if not request.user.has_perm("formly.edit_survey", obj=field.survey):
        raise PermissionDenied()

    if request.method == "POST":
        if request.POST.get("action") == "field_update":
            form = FieldForm(data=request.POST, instance=field)
            field_choice_form = FieldChoiceForm(prefix="choices")
            if form.is_valid():
                form.save()
                return redirect(field)
    else:
        form = FieldForm(instance=field)
        field_choice_form = FieldChoiceForm(prefix="choices")
        likert_scale_form = LikertScaleForm()

    return render(request, "formly/design/survey_list.html", {
        "surveys": Survey.objects.all().order_by("-created"),
        "survey_form": SurveyCreateForm(user=request.user),
        "pages": field.page.survey.pages.all(),
        "selected_page": field.page,
        "selected_survey": field.survey,
        "fields": field.page.fields.all().order_by("ordinal"),
        "selected_field": field,
        "field_form": form,
        "field_choice_form": field_choice_form,
        "likert_scales": LikertScale.objects.all(),
        "likert_scale_form": likert_scale_form
    })
コード例 #2
0
ファイル: design.py プロジェクト: StefanKjartansson/formly
def field_update(request, pk):
    field = get_object_or_404(Field, pk=pk)
    
    if not request.user.has_perm("formly.edit_survey", obj=field.survey):
        raise PermissionDenied()
    
    if request.method == "POST":
        if request.POST.get("action") == "field_update":
            form = FieldForm(data=request.POST, instance=field)
            field_choice_form = FieldChoiceForm(field=field, prefix="choices")
            if form.is_valid():
                form.save()
                return redirect(field.page.get_absolute_url())
        if request.POST.get("action") == "choice_add":
            form = FieldForm(instance=field)
            field_choice_form = FieldChoiceForm(
                data=request.POST,
                field=field,
                prefix="choices"
            )
            if field_choice_form.is_valid():
                choice = field_choice_form.save(commit=False)
                choice.field = field
                choice.save()
                return redirect("formly_dt_field_update", pk=field.pk)
    else:
        form = FieldForm(instance=field)
        field_choice_form = FieldChoiceForm(field=field, prefix="choices")
    
    return render(request, "formly/design/field_form.html", {
        "form": form,
        "page": field.page,
        "field": field,
        "field_choice_form": field_choice_form
    })
コード例 #3
0
def field_update(request, pk):
    field = get_object_or_404(Field, pk=pk)

    if not request.user.has_perm("formly.edit_survey", obj=field.survey):
        raise PermissionDenied()

    if request.method == "POST":
        if request.POST.get("action") == "field_update":
            form = FieldForm(data=request.POST, instance=field)
            field_choice_form = FieldChoiceForm(prefix="choices")
            if form.is_valid():
                form.save()
                return redirect(field)
    else:
        form = FieldForm(instance=field)
        field_choice_form = FieldChoiceForm(prefix="choices")
        likert_scale_form = OrdinalScaleForm()
        rating_scale_form = OrdinalScaleForm()

    return render(request, "formly/design/survey_list.html", {
        "surveys": Survey.objects.all().order_by("-created"),
        "survey_form": SurveyCreateForm(user=request.user),
        "pages": field.page.survey.pages.all(),
        "selected_page": field.page,
        "selected_survey": field.survey,
        "fields": field.page.fields.all().order_by("ordinal"),
        "selected_field": field,
        "field_form": form,
        "field_choice_form": field_choice_form,
        "likert_scales": OrdinalScale.objects.filter(kind=OrdinalScale.ORDINAL_KIND_LIKERT),
        "likert_scale_form": likert_scale_form,
        "rating_scales": OrdinalScale.objects.filter(kind=OrdinalScale.ORDINAL_KIND_RATING),
        "rating_scale_form": rating_scale_form
    })
コード例 #4
0
def page_update(request, pk):
    # @@@ break this apart into seperate views
    page = get_object_or_404(Page, pk=pk)

    if not request.user.has_perm("formly.edit_survey", obj=page.survey):
        raise PermissionDenied()

    if request.method == "POST":
        if request.POST.get("action") == "page_update":
            form = PageUpdateForm(data=request.POST, instance=page)
            field_form = FieldForm(prefix="fields")
            if form.is_valid():
                page = form.save()
                return redirect(page)
        if request.POST.get("action") == "field_add":
            form = PageUpdateForm(instance=page)
            field_form = FieldForm(request.POST, prefix="fields")
            if field_form.is_valid():
                field = field_form.save(commit=False)
                field.page = page
                field.survey = page.survey
                field.save()
                return redirect(page)
    else:
        form = PageUpdateForm(instance=page)
        field_form = FieldForm(prefix="fields")
    return render(request, "formly/design/page_form.html", {
        "form": form,
        "page": page,
        "field_form": field_form
    })
コード例 #5
0
def page_update(request, pk):
    # @@@ break this apart into separate views
    page = get_object_or_404(Page, pk=pk)

    if not request.user.has_perm("formly.edit_survey", obj=page.survey):
        raise PermissionDenied()

    if request.method == "POST":
        if request.POST.get("action") == "page_update":
            form = PageUpdateForm(data=request.POST, instance=page)
            field_form = FieldForm(prefix="fields")
            if form.is_valid():
                page = form.save()
                return redirect(page)
        if request.POST.get("action") == "field_add":
            form = PageUpdateForm(instance=page)
            field_form = FieldForm(data=request.POST, prefix="fields")
            if field_form.is_valid():
                field = field_form.save(commit=False)
                field.page = page
                field.survey = page.survey
                field.save()
                return redirect(page)
    else:
        form = PageUpdateForm(instance=page)
        field_form = FieldForm(prefix="fields")
    return render(request,
                  "formly/design/page_form.html",
                  context={
                      "form": form,
                      "page": page,
                      "field_form": field_form
                  })