From 4c07209f631f1b16ddafab947320e66395bdbf80 Mon Sep 17 00:00:00 2001 From: GDay <1939656+GDay@users.noreply.github.com> Date: Sun, 12 May 2024 03:22:38 +0200 Subject: [PATCH] fix two forms on one page preboarding/todo --- back/back/templatetags/general.py | 8 ++++++++ back/fixtures/all.json | 21 ++++++++++++------- back/new_hire/templates/_content.html | 29 +++++++++++++-------------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/back/back/templatetags/general.py b/back/back/templatetags/general.py index ef3287644..e8a4faa92 100644 --- a/back/back/templatetags/general.py +++ b/back/back/templatetags/general.py @@ -38,6 +38,14 @@ def next_still_form(content, current_index): return False +@register.filter(name="has_form") +def has_form(content): + """ + Go through all blocks and check if a form has been added + """ + return any(block["type"] == "form" for block in content["blocks"]) + + @register.filter(name="personalize") def personalize(text, user): """ diff --git a/back/fixtures/all.json b/back/fixtures/all.json index 4fc9e425e..44dcb9ea2 100644 --- a/back/fixtures/all.json +++ b/back/fixtures/all.json @@ -511,7 +511,8 @@ "text": "What's a little fun fact about you?", "type": "input" }, - "type": "form" + "type": "form", + "id": "lksdf" }, { "data": { @@ -526,14 +527,16 @@ "text": "Macbook", "type": "select" }, - "type": "form" + "type": "form", + "id": "mac-lks" }, { "data": { "text": "Dell", "type": "select" }, - "type": "form" + "type": "form", + "id": "mac-lkslksd" }, { "data": { @@ -547,7 +550,8 @@ "text": "Please upload a profile picture here", "type": "upload" }, - "type": "form" + "type": "form", + "id": "mac-lkjsdl" } ] }, @@ -577,21 +581,24 @@ "text": "What did you like about the process?", "type": "text" }, - "type": "form" + "type": "form", + "id": "lsdf" }, { "data": { "text": "What did you NOT like about the process?", "type": "text" }, - "type": "form" + "type": "form", + "id": "lksd233" }, { "data": { "text": "Other thoughts?", "type": "text" }, - "type": "form" + "type": "form", + "id": "clkwlksd233" } ] }, diff --git a/back/new_hire/templates/_content.html b/back/new_hire/templates/_content.html index b6a9d6d13..3f5a749fb 100644 --- a/back/new_hire/templates/_content.html +++ b/back/new_hire/templates/_content.html @@ -4,6 +4,13 @@ {% load i18n %} {% autoescape off %} {% with content=content|parse_to_json %} +{% if content|has_form and not object.completed_form_items %} + {% if "preboarding" in request.path %} +
- {% endif %} {% endif %} {% endfor %} +{% if content|has_form and not object.completed_form_items %} + + +{% endif %} {% endwith %} {% endautoescape %}