Skip to content

Commit

Permalink
Merge 4c07209 into ea8b155
Browse files Browse the repository at this point in the history
  • Loading branch information
GDay committed May 12, 2024
2 parents ea8b155 + 4c07209 commit b747b3c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
8 changes: 8 additions & 0 deletions back/back/templatetags/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
21 changes: 14 additions & 7 deletions back/fixtures/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"text": "What's a little fun fact about you?",
"type": "input"
},
"type": "form"
"type": "form",
"id": "lksdf"
},
{
"data": {
Expand All @@ -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": {
Expand All @@ -547,7 +550,8 @@
"text": "Please upload a profile picture here",
"type": "upload"
},
"type": "form"
"type": "form",
"id": "mac-lkjsdl"
}
]
},
Expand Down Expand Up @@ -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"
}
]
},
Expand Down
29 changes: 14 additions & 15 deletions back/new_hire/templates/_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<form hx-post="{% url 'new_hire:form' object.id 'preboarding' %}">
{% else %}
<form hx-post="{% url 'new_hire:form' object.id 'to_do' %}">
{% endif %}
{% endif %}
{% for block in content.blocks %}
{% if block.type == 'paragraph' %}
<p> {{ block.data.text|safe|personalize:user}} </p>
Expand Down Expand Up @@ -53,20 +60,13 @@ <h3>{{ block.data.caption }}</h3>
</figure>
</div>
{% endif %}

{% if block.type == 'form' %}
{% if block.id in object.completed_form_items %}
{% if object.completed_form_items %}
{% if not content|next_still_form:forloop.counter0 %}
{% translate "You have already completed this form" %}
<p><b>{% translate "You have already completed this form" %}</b></p>
{% endif %}
{% else %}
{# Create new form when `form` is new #}
{% ifchanged block.type %}
{% if "preboarding" in request.path %}
<form hx-post="{% url 'new_hire:form' object.id 'preboarding' %}">
{% else %}
<form hx-post="{% url 'new_hire:form' object.id 'to_do' %}">
{% endif %}
{% endifchanged %}
{% if block.data.type == 'input' %}
<div class="mb-3">
<label class="form-label">{{ block.data.text|safe|personalize:user }}</label>
Expand Down Expand Up @@ -112,12 +112,11 @@ <h3>{{ block.data.caption }}</h3>
</div>
{% endif %}
{% endif %}

{% if not content|next_still_form:forloop.counter0 and block.id not in object.completed_form_items or forloop.last and block.id not in object.completed_form_items %}
<button class="btn btn-primary mb-2" type="submit">{% translate "Submit" %}</button>
</form>
{% endif %}
{% endif %}
{% endfor %}
{% if content|has_form and not object.completed_form_items %}
<button class="btn btn-primary mb-2" type="submit" style="float:unset; margin-left: 0px">{% translate "Submit" %}</button>
</form>
{% endif %}
{% endwith %}
{% endautoescape %}

0 comments on commit b747b3c

Please sign in to comment.