Skip to content

Commit

Permalink
format_html, mark_safe, translations
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 22, 2025
1 parent 8fdec74 commit 26282c6
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 57 deletions.
8 changes: 4 additions & 4 deletions edc_he/modeladmin_mixins/assets_model_admin_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class HealthEconomicsAssetsModelAdminMixin:
_("Household assets (continued)"),
{
"description": format_html(
"{}? <BR>{}",
_(
"{text1}? <BR>{text2}",
text1=_(
"Does your household or anyone in your household have the following "
"in working order"
),
_(
text2=_(
"Note: If a household owns one of the assets below but the asset "
"is not in working order then it should be marked as 'No'",
"is not in working order then it should be marked as 'No'"
),
),
"fields": (
Expand Down
35 changes: 20 additions & 15 deletions edc_he/modeladmin_mixins/household_head_model_admin_mixin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from django.template.loader import render_to_string
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
Expand All @@ -11,8 +12,8 @@ class HealthEconomicsHouseholdHeadModelAdminMixin:
form = None

additional_instructions = format_html(
"{}",
mark_safe(
"{html}",
html=mark_safe(
"<H5><B><font color='orange'>Interviewer to read</font></B></H5>"
"<p>We want to learn about the household and we use these questions "
"to get an understanding of wealth and opportunities in the community.</p>"
Expand Down Expand Up @@ -43,12 +44,17 @@ class HealthEconomicsHouseholdHeadModelAdminMixin:
"Household members",
{
"description": format_html(
_(
"<H5><B><font color='orange'>Interviewer to read</font></B></H5>"
f"<p>By a <B>HOUSEHOLD</B> {household_description}.</P>"
f"<P>By a <B>HOUSEHOLD MEMBER</B> {household_member_description}."
f"</P><P><B>{_('Note')}:</B> {household_description_extra}.</p>"
)
"{html}",
html=mark_safe(
render_to_string(
"edc_he/household_head/household_members_description.html",
context=dict(
household_description=household_description,
household_member_description=household_member_description,
household_description_extra=household_description_extra,
),
)
), # nosec B703, B308
),
"fields": (
"hh_count",
Expand All @@ -71,13 +77,12 @@ class HealthEconomicsHouseholdHeadModelAdminMixin:
"Head of household",
{
"description": format_html(
"<H5><B><font color='darkorange'>Note to interviewer</font></B></H5>"
"If the PATIENT is the head of household, skip to the bottom of this form "
"and click SAVE or SAVE NEXT, otherwise continue."
"<H5><B><font color='orange'>Interviewer to read</font></B></H5>"
"<p>By <B>HEAD OF THE HOUSEHOLD</B> we mean the <u>main decision "
"maker</u> in the HOUSEHOLD. The HEAD can be either male or female. If "
"two people are equal decision-makers, take the older person</p>"
"{html}",
html=mark_safe(
render_to_string(
"edc_he/household_head/household_head_description.html"
)
), # nosec B703, B308
),
"fields": (
"relationship_to_hoh",
Expand Down
48 changes: 18 additions & 30 deletions edc_he/modeladmin_mixins/income_model_admin_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.contrib import admin
from django.template.loader import render_to_string
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django_audit_fields.admin import audit_fieldset_tuple
from edc_crf.admin import crf_status_fieldset_tuple
Expand Down Expand Up @@ -34,10 +36,13 @@ def get_income_fieldsets_tuple() -> list[tuple]:
label,
{
"description": format_html(
_(
"Estimate the total amount of income from this source "
"for the <b>household</b> over the time period indicated"
)
"{html}",
html=mark_safe(
_(
"Estimate the total amount of income from this source "
"for the <b>household</b> over the time period indicated"
)
), # nosec B703, B308
),
"fields": tuple(fields),
},
Expand All @@ -50,22 +55,12 @@ class HealthEconomicsIncomeModelAdminMixin:
form = None

additional_instructions = format_html(
_(
"<H5><B><font color='orange'>Interviewer to read</font></B></H5>"
"<P>We want to learn about the household and we use these questions "
"to get an understanding of wealth and opportunities in the community.</P>"
"<p>Now, I will ask about <b>income for the household</b> from paid work or "
"other sources.</p><p>I know it may be difficult to calculate those figures, "
"but please do try to give amounts as accurately as possible. Remember "
"that <b>all information will be kept strictly confidential</b>. This "
"information is important to assess overall health and well-being of "
"people in your household, compared to other similar households.</p><p>"
"I am now going to read you a list of possible sources of income. "
"Thinking over the last 12 months, can you tell me what the average "
"earnings of the household have been per week or per month or per year? "
"Please tell me whichever time period that is easier for you.</p>"
)
"{html}",
html=mark_safe(
render_to_string("edc_he/income/additional_instructions.html")
), # nosec B703, B308
)

fieldsets = (
(None, {"fields": ("subject_visit", "report_datetime")}),
*get_income_fieldsets_tuple(),
Expand All @@ -84,17 +79,10 @@ class HealthEconomicsIncomeModelAdminMixin:
"Debt / Loans",
{
"description": format_html(
_(
"<H5><B><font color='orange'>Interviewer to read</font></B></H5>"
"<p>Now, I will ask about the total current debt/loans for the "
"household. I know it may be difficult to calculate this, but please "
"do try to give amounts as accurately as possible. Remember that "
"all information will be kept strictly confidential. <B>It is not "
"possible to offer any help for your debts through this project</B>, "
"but this information will contribute to research and is important "
"to assess the overall health and well-being of people in your "
"household, compared to other similar households.</p>"
)
"{html}",
html=mark_safe(
render_to_string("edc_he/income/debt_loans.html")
), # nosec B703, B308
),
"fields": (
"household_debt",
Expand Down
14 changes: 6 additions & 8 deletions edc_he/modeladmin_mixins/property_model_admin_mixin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.contrib import admin
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django_audit_fields.admin import audit_fieldset_tuple
from django_dev.django.template.loader import render_to_string
from edc_crf.admin import crf_status_fieldset_tuple


Expand All @@ -18,14 +20,10 @@ class HealthEconomicsPropertyModelAdminMixin:
"Property",
{
"description": format_html(
_(
"<H5><B><font color='orange'>Interviewer to read</font></B></H5><p>"
"I would now like to know if you own any <B>land or other "
"property</B> – and the approximate value (amount). I know this "
"is sensitive information and will not share this with any persons "
"outside of the survey team. <B><U>There is no need to give details "
"or show me any of the items.</U></B></P>"
)
"{html}",
html=mark_safe(
render_to_string("edc_he/property/description.html"),
), # nosec #B703 # B308
),
"fields": (
"land_owner",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<H5><B><span style="color:darkorange">Note to interviewer</span></B></H5>
If the PATIENT is the head of household, skip to the bottom of this form and click SAVE or SAVE NEXT, otherwise continue.
<H5><B><span style="color:orange">Interviewer to read</span></B></H5>
<p>By <B>HEAD OF THE HOUSEHOLD</B> we mean the <u>main decision maker</u> in the HOUSEHOLD. The HEAD can be either male or female. If two people are equal decision-makers, take the older person</p>",
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<H5><B><span style="color:orange">Interviewer to read</span></B></H5>
<p>By a <B>HOUSEHOLD</B> {{ household_description }}.</P>
<P>By a <B>HOUSEHOLD_MEMBER</B> {{ household_member_description }}.
</P><P><B>Note:</B> {{ household_description_extra }}.</p>
13 changes: 13 additions & 0 deletions edc_he/templates/edc_he/income/additional_instructions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<H5><B><span style="color:orange">Interviewer to read</span></B></H5>
<P>We want to learn about the household and we use these questions
to get an understanding of wealth and opportunities in the community.</P>
<p>Now, I will ask about <b>income for the household</b> from paid work or
other sources.</p><p>I know it may be difficult to calculate those figures,
but please do try to give amounts as accurately as possible. Remember
that <b>all information will be kept strictly confidential</b>. This
information is important to assess overall health and well-being of
people in your household, compared to other similar households.</p><p>
I am now going to read you a list of possible sources of income.
Thinking over the last 12 months, can you tell me what the average
earnings of the household have been per week or per month or per year?
Please tell me whichever time period that is easier for you.</p>
2 changes: 2 additions & 0 deletions edc_he/templates/edc_he/income/debt_loans.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<H5><B><span style="color:orange">{% translate "Interviewer to read" %}</span></B></H5>
<p>{% translate "Now, I will ask about the total current debt/loans for the household. I know it may be difficult to calculate this, but please do try to give amounts as accurately as possible. Remember that all information will be kept strictly confidential" %}. <B> {% translate "It is not possible to offer any help for your debts through this project" %}</B>, {% translate "but this information will contribute to research and is important to assess the overall health and well-being of people in your household, compared to other similar households" %}.</p>
4 changes: 4 additions & 0 deletions edc_he/templates/edc_he/property/description.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<H5><B><span style="color:orange">Interviewer to read</span></B></H5>
<p>
{% translate "I would now like to know if you own any" %} <B>{% translate "land or other property" %}</B> – {% translate "and the approximate value (amount). I know this is sensitive information and will not share this with any persons outside of the survey team" %}. <B><U>{% translate "There is no need to give details or show me any of the items" %}.</U></B>
</P>

0 comments on commit 26282c6

Please sign in to comment.