Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/YC-1207
Browse files Browse the repository at this point in the history
  • Loading branch information
monodo committed May 28, 2024
2 parents f628aa1 + 4a809a6 commit 5768248
Showing 3 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
<div class="flex_item-100"><h3>{{forms.title.form_category}}</h3></div>
{% endif %}
{% for comment_key, comment in forms.fields.items %}
{% if not comment.name in section.undesired_properties %}
{% if not comment.name in section.list_undesired_properties %}
<div class="flex_item-100" style="text-align: justify; text-justify: inter-character;"><span class="bold">{{comment.name}} : </span>{{comment.value}}</div><br>
{% endif %}
{% endfor %}
Original file line number Diff line number Diff line change
@@ -16,12 +16,12 @@
<div class="flex_item-100"><h3>{{forms.title.form_category}}</h3></div>
{% endif %}
{% for field_key, field in forms.fields.items %}
{% if not field.name in section.undesired_properties %}
{% if not field.name in section.list_undesired_properties and not field_key in section.list_undesired_properties %}
{% if section.style == 0 %}
<div class="flex_item-100" style="padding-top:{{section.line_height}}px;"><span class="bold">{{field.name}} : </span>{{field.value}}<br></div>
<div class="flex_item-100" style="padding-top:{{section.line_height}}px;"><span class="bold">{{field.name}} : </span>{{field.value_formatted}}<br></div>
{% elif section.style == 1 %}
<div class="flex_item-40"><span class="bold">{{field.name}}</span></div>
<div class="flex_item-60">{{field.value}}</div>
<div class="flex_item-60">{{field.value_formatted}}</div>
<div style="padding-top:{{section.line_height}}px;"></div>
{% endif %}
{% endif %}
49 changes: 49 additions & 0 deletions geocity/apps/reports/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, render
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from rest_framework.decorators import api_view

from geocity.apps.accounts.decorators import permanent_user_required
@@ -14,6 +15,31 @@
from .services import generate_report_pdf_as_response


def preprocess_field_format(value):
"""
Uses of this function :
- Interpret line breaks
- Translate bool values in french
- Transform list in formatted strings
"""

if isinstance(value, list):
print(len(value))
if len(value) > 1:
result = "- " + "<br>- ".join(str(item) for item in value)
else:
result = value[0]
return mark_safe(result)

if isinstance(value, bool):
return "Vrai" if value else "Faux"

if value:
return mark_safe(value.replace("\r\n", "<br>").replace("\n", "<br>"))

return value


# TODO: instead of taking Submission and Form arguments, we should take
# in SelectedForm, which already joins both, so they are consistent.
@api_view(["GET"]) # pretend it's a DRF view, so we get token auth
@@ -44,6 +70,29 @@ def report_content(request, submission_id, form_id, report_id, **kwargs):
},
}

# Add line breaks for validation
for group, validation in (
request_json_data["properties"].get("validations", {}).items()
):
if "comment" in validation:
validation["comment"] = preprocess_field_format(validation["comment"])

# Add line breaks for amend_fields
for form_key, forms in (
request_json_data["properties"].get("amend_fields", {}).items()
):
for comment_key, comment in forms.get("fields", {}).items():
if "value" in comment:
comment["value"] = preprocess_field_format(comment["value"])

# Reformat fields to remove lists and add line breaks
for form_key, forms in (
request_json_data["properties"].get("submission_fields", {}).items()
):
for field_key, field in forms.get("fields", {}).items():
if "value" in field:
field["value_formatted"] = preprocess_field_format(field["value"])

transaction = None
if kwargs.get("transaction_id"):
transaction = (

0 comments on commit 5768248

Please sign in to comment.