Esempio n. 1
0
def field_add_choice(request, pk):
    field = get_object_or_404(Field, pk=pk)

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

    field_choice_form = FieldChoiceForm(
        data=request.POST,
        prefix="choices"
    )
    if field_choice_form.is_valid():
        choice = field_choice_form.save(commit=False)
        choice.field = field
        choice.save()
        return redirect(field)
    form = FieldForm(instance=field)
    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
    })
Esempio n. 2
0
def field_add_choice(request, pk):
    field = get_object_or_404(Field, pk=pk)

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

    field_choice_form = FieldChoiceForm(data=request.POST, prefix="choices")
    if field_choice_form.is_valid():
        choice = field_choice_form.save(commit=False)
        choice.field = field
        choice.save()
        return redirect(field)
    form = FieldForm(instance=field)
    return render(request,
                  "formly/design/survey_list.html",
                  context={
                      "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
                  })
Esempio n. 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(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
    })
Esempio n. 4
0
def choice_update(request, pk):
    choice = get_object_or_404(FieldChoice, pk=pk)

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

    if request.method == "POST":
        form = FieldChoiceForm(
            data=request.POST,
            instance=choice
        )
        if form.is_valid():
            form.save()
            return redirect(choice.field.page)
    else:
        form = FieldChoiceForm(instance=choice)

    return render(request, "formly/design/choice_form.html", {
        "form": form,
        "choice": choice,
        "page": choice.field.page
    })
Esempio n. 5
0
def choice_update(request, pk):
    choice = get_object_or_404(FieldChoice, pk=pk)

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

    if request.method == "POST":
        form = FieldChoiceForm(data=request.POST, instance=choice)
        if form.is_valid():
            form.save()
            return redirect(choice.field.page)
    else:
        form = FieldChoiceForm(instance=choice)

    return render(request,
                  "formly/design/choice_form.html",
                  context={
                      "form": form,
                      "choice": choice,
                      "page": choice.field.page
                  })