Exemple #1
0
def survey_create(request):
    if not request.user.has_perm("formly.create_survey"):
        raise PermissionDenied()

    if request.method == "POST":
        form = SurveyCreateForm(request.POST, user=request.user)
        if form.is_valid():
            survey = form.save()
            return redirect(survey.first_page())
    else:
        form = SurveyCreateForm(user=request.user)

    return render(request, "formly/design/survey_form.html", {
        "form": form,
    })
Exemple #2
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
    })
Exemple #3
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
                  })
Exemple #4
0
def survey_list(request):
    if not request.user.has_perm("formly.view_survey_list"):
        raise PermissionDenied()

    return render(request, "formly/design/survey_list.html", {
        "surveys": Survey.objects.all().order_by("-created"),
        "survey_form": SurveyCreateForm(user=request.user)
    })
Exemple #5
0
def survey_list(request):
    if not request.user.has_perm("formly.view_survey_list"):
        raise PermissionDenied(
        )  # pragma: no cover -> never invoked because @login_required

    return render(request,
                  "formly/design/survey_list.html",
                  context={
                      "surveys": Survey.objects.all().order_by("-created"),
                      "survey_form": SurveyCreateForm(user=request.user)
                  })
Exemple #6
0
def survey_detail(request, pk):
    survey = get_object_or_404(Survey, pk=pk)

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

    return render(request, "formly/design/survey_list.html", {
        "surveys": Survey.objects.all().order_by("-created"),
        "survey_form": SurveyCreateForm(user=request.user),
        "pages": survey.pages.all(),
        "selected_survey": survey
    })
Exemple #7
0
def page_detail(request, pk):
    page = get_object_or_404(Page, pk=pk)

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

    return render(request, "formly/design/survey_list.html", {
        "surveys": Survey.objects.all().order_by("-created"),
        "survey_form": SurveyCreateForm(user=request.user),
        "pages": page.survey.pages.all(),
        "selected_page": page,
        "selected_survey": page.survey,
        "fields": page.fields.all().order_by("ordinal")
    })
Exemple #8
0
def survey_create(request):
    if not request.user.has_perm("formly.create_survey"):
        raise PermissionDenied()

    if request.method == "POST":
        form = SurveyCreateForm(request.POST, user=request.user)
        if form.is_valid():
            survey = form.save()
            return redirect(survey.first_page())
    else:
        form = SurveyCreateForm(user=request.user)

    return render(request, "formly/design/survey_form.html", {
        "form": form,
    })
Exemple #9
0
def survey_create(request):
    if not request.user.has_perm("formly.create_survey"):
        raise PermissionDenied(
        )  # pragma: no cover -> never invoked because @login_required

    if request.method == "POST":
        form = SurveyCreateForm(request.POST, user=request.user)
        if form.is_valid():
            survey = form.save()
            return redirect(survey.first_page())
    else:
        form = SurveyCreateForm(user=request.user)

    return render(request,
                  "formly/design/survey_form.html",
                  context={
                      "form": form,
                  })