Skip to content

Commit

Permalink
Merge pull request #294 from biocore/csymons_reactivate_japanese
Browse files Browse the repository at this point in the history
Reactivate Japanese Locale
  • Loading branch information
cassidysymons authored Oct 24, 2023
2 parents 0380e34 + 3850a0a commit ce64c11
Show file tree
Hide file tree
Showing 13 changed files with 2,593 additions and 2,178 deletions.
62 changes: 54 additions & 8 deletions microsetta_interface/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Source:
client_state = RedisCache()

# Countries allowed to view the contents of the My Kits tab
KITS_TAB_WHITELIST = {'US', 'ES', 'JP'}
KITS_TAB_WHITELIST = {'US', 'ES', 'JP', 'MX', 'GB'}

# Countries allowed to view the contents of the My Nutrition tab
NUTRITION_TAB_WHITELIST = {'US'}
Expand Down Expand Up @@ -932,12 +932,7 @@ def get_authrocket_callback(token=None, redirect_uri=None):
"account_id": primary['account_id'],
"email": primary['email']
}
# NB: Disabling Japanese for the initial relaunch period until the
# Tokyo Tech team can review finalized translations
if primary["language"] == JA_JP_KEY:
session[LANG_KEY] = EN_US_KEY
else:
session[LANG_KEY] = primary["language"]
session[LANG_KEY] = primary["language"]
else:
session[ADMIN_MODE_KEY] = False
session[LOGIN_INFO_KEY] = {
Expand Down Expand Up @@ -2035,6 +2030,23 @@ def get_reports(*, account_id=None, source_id=None):
else:
pending_samples.append(sample)

# Retrieve external reports for the source
has_error, external_reports, _ = ApiRequest.get(
'/accounts/%s/sources/%s/external_reports' % (account_id, source_id))
if has_error:
return samples_output

external_reports_kit = []
external_reports_ffq = []
for er in external_reports:
if er['report_type'] == "kit":
external_reports_kit.append(er)
elif er['report_type'] == "ffq":
external_reports_ffq.append(er)
else:
# This should be impossible to reach
raise Exception("Unknown report type: " + er['report_type'])

profile_has_samples = _check_if_source_has_samples(account_id, source_id)

return _render_with_defaults(
Expand All @@ -2047,8 +2059,42 @@ def get_reports(*, account_id=None, source_id=None):
source_name=source_output['source_name'],
barcode_prefix=SERVER_CONFIG['barcode_prefix'],
public_endpoint=SERVER_CONFIG['public_api_endpoint'],
profile_has_samples=profile_has_samples
profile_has_samples=profile_has_samples,
external_reports_kit=external_reports_kit,
external_reports_ffq=external_reports_ffq
)


@prerequisite([SOURCE_PREREQS_MET, BIOSPECIMEN_PREREQS_MET])
def get_external_report(*,
account_id=None,
source_id=None,
external_report_id=None):
has_error, external_report, _ = ApiRequest.get(
'/accounts/%s/sources/%s/external_reports/%s' %
(account_id, source_id, external_report_id)
)
if has_error:
return external_report

has_error, external_report_bytes, _ = ApiRequest.get(
'/accounts/%s/sources/%s/external_reports/%s/bytes' %
(account_id, source_id, external_report_id),
parse_json=False
)
if has_error:
return external_report_bytes

response = make_response(
external_report_bytes
)
response.headers.set("Content-Type", external_report['file_type'])
# TODO: Do we want it to download a file or be embedded in the html?
response.headers.set('Content-Disposition',
'attachment',
filename=external_report['file_name'])

return response


@prerequisite([SOURCE_PREREQS_MET, BIOSPECIMEN_PREREQS_MET])
Expand Down
2 changes: 1 addition & 1 deletion microsetta_interface/model_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
EN_US_KEY: Lang("en_US", "English"),
ES_MX_KEY: Lang("es_MX", "Español (México)"),
ES_ES_KEY: Lang("es_ES", "Español (España)"),
# JA_JP_KEY: Lang("ja_JP", "日本語")
JA_JP_KEY: Lang("ja_JP", "日本語")
}

# We need a default full locale when a user's browser only sends a partial
Expand Down
29 changes: 28 additions & 1 deletion microsetta_interface/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,23 @@ paths:
schema:
type: string

'/accounts/{account_id}/sources/{source_id}/external_reports/{external_report_id}':
get:
operationId: microsetta_interface.implementation.get_external_report
tags:
- Survey
summary: Retrieve an external report and render the file for the user
description: Retrieve an external report and render the file for the user
parameters:
- $ref: '#/components/parameters/account_id'
- $ref: '#/components/parameters/source_id'
- $ref: '#/components/parameters/external_report_id'
responses:
'200':
description: External report file
'404':
description: No such report

'/accounts/{account_id}/sources/{source_id}/decline_reconsent':
get:
operationId: microsetta_interface.implementation.decline_reconsent
Expand Down Expand Up @@ -1524,6 +1541,13 @@ components:
description: T/F flag on whether the Kits page should check user's most recent survey update date
schema:
$ref: '#/components/schemas/check_survey_date'
external_report_id:
name: external_report_id
in: path
description: Unique identifier for an external report
schema:
$ref: '#/components/schemas/external_report_id'
required: true

schemas:
# account section
Expand Down Expand Up @@ -1571,7 +1595,7 @@ components:
example: "aaaaa"
activation_code:
type: string
example: TMI-XXXXX-XXXXX-XXXXX
example: "TMI-XXXXX-XXXXX-XXXXX"
target:
type: string
example: "home"
Expand All @@ -1587,3 +1611,6 @@ components:
check_survey_date:
type: boolean
example: True
external_report_id:
type: string
example: "b0b0b0b0-b0b0-b0b0-b0b0-b0b0b0b0b0b0"
2 changes: 1 addition & 1 deletion microsetta_interface/static/css/minimal_interface.css
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ h1.profile-h1 {
.profile-nav > .nav-item {
width: 190px;
text-align: center;
font-size: 24px;
font-size: 20px;
line-height: 40px;
background-color: var(--tmi-blue);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion microsetta_interface/templates/account_overview.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{% else %}
{{ _('You have') }}&nbsp;<span class="orange-text">{{ source.alerts }}</span>&nbsp;{{ _('update') }}
{% endif %}
<a class="btn btn-orange ms-4" style="width: fit-content;" href="/accounts/{{account.account_id}}/sources/{{ source.source_id|e }}">View</a>
<a class="btn btn-orange ms-4" style="width: fit-content;" href="/accounts/{{account.account_id}}/sources/{{ source.source_id|e }}">{{ _('View') }}</a>
</div>
</div>
{% else %}
Expand Down
2 changes: 2 additions & 0 deletions microsetta_interface/templates/new_participant.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
</div>
</div>
<div class="row mb-4">
{% if language_tag != "ja_JP" %}
<div class="col-md">
<input type="radio" id="age-range-1" name="age-range" value="0-6" onchange="change_consent_div(this)">
<label for="age-range-1" class="consent-age-label">{{ tl['PARTICIPANT_FORM']['AGE_0_6'] |e}}</label>
Expand All @@ -254,6 +255,7 @@
<input type="radio" id="age-range-3" name="age-range" value="13-17" onchange="change_consent_div(this)">
<label for="age-range-3" class="consent-age-label">{{ tl['PARTICIPANT_FORM']['AGE_13_17'] |e}}</label>
</div>
{% endif %}
<div class="col-md">
<input type="radio" id="age-range-4" name="age-range" value="18-plus" onchange="change_consent_div(this)">
<label for="age-range-4" class="consent-age-label">{{ tl['PARTICIPANT_FORM']['AGE_18'] |e}}</label>
Expand Down
33 changes: 9 additions & 24 deletions microsetta_interface/templates/new_results_page.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@
<div class="how_you_compare_section">
<h4>{{ _('Microbiome Map') }}</h4>
<p>
{{ _('Where are you on the') }} <a class="fake-tab" href="#microbial-map" data-link="#microbial-map-tab">{{ _('Microbiome Map') }}</a>?
{{ _('Where are you on the <a class="fake-tab" href="#microbial-map" data-link="#microbial-map-tab">Microbiome Map</a>?') }}
</p>
</div>
</div>
Expand Down Expand Up @@ -1508,19 +1508,15 @@
<img class="diversity-icon" src='/static/img/vegetables.png'>
</div>
<div class="col-sm-8 diversity-text">
<span id="beta_diversity_plants_per_week_value" class="info-loader font-weight-bold">...</span>
{{ _('of people with a microbiome like yours eat') }}
<span id="beta_diversity_plants_per_week_response" class="info-loader text-success">...</span>
{{ _('plants per week') }}
{{ _('<span id="beta_diversity_plants_per_week_value" class="info-loader font-weight-bold">...</span> of people with a microbiome like yours eat <span id="beta_diversity_plants_per_week_response" class="info-loader text-success">...</span> plants per week') }}
</div>
</div>
<div class="col diversity-compare">
<div class="col-sm-2">
<img class="diversity-icon" src='/static/img/diet.png'>
</div>
<div class="col-sm-8 diversity-text">
<span id="beta_diversity_diet_type_value" class="info-loader font-weight-bold">...</span>
{{ _('of people with a microbiome like yours had a similar diet (e.g. omnivore, vegetarian, etc.)') }}
{{ _('<span id="beta_diversity_diet_type_value" class="info-loader font-weight-bold">...</span> of people with a microbiome like yours had a similar diet (e.g. omnivore, vegetarian, etc.)') }}
</div>
</div>
</div>
Expand All @@ -1536,19 +1532,15 @@
<img class="diversity-icon" src='/static/img/probiotics.png'>
</div>
<div class="col-sm-8 diversity-text">
<span id="beta_diversity_probiotics_value" class="info-loader font-weight-bold">...</span>
{{ _('of people with a microbiome like yours') }}
<span id="beta_diversity_probiotics_response" class="info-loader text-success">...</span>
{{ _('take probiotics') }}
{{ _('<span id="beta_diversity_probiotics_value" class="info-loader font-weight-bold">...</span> of people with a microbiome like yours <span id="beta_diversity_probiotics_response" class="info-loader text-success">...</span> take probiotics') }}
</div>
</div>
<div class="col diversity-compare">
<div class="col-sm-2">
<img class="diversity-icon" src='/static/img/vitamins.png'>
</div>
<div class="col-sm-8 diversity-text">
<span id="beta_diversity_multivitamin_value" class="info-loader font-weight-bold">...</span>
{{ _('of people with a microbiome like yours take vitamins') }}
{{ _('<span id="beta_diversity_multivitamin_value" class="info-loader font-weight-bold">...</span> of people with a microbiome like yours take vitamins') }}
</div>
</div>
</div>
Expand All @@ -1564,20 +1556,15 @@
<img class="diversity-icon" src='/static/img/exercise.png'>
</div>
<div class="col-sm-8 diversity-text">
<span id="beta_diversity_exercise_value" class="info-loader font-weight-bold">...</span>
{{ _('of people with a microbiome like yours exercise') }}
<span id="beta_diversity_exercise_response" class="info-loader text-success">...</span>
{{ _('<span id="beta_diversity_exercise_value" class="info-loader font-weight-bold">...</span> of people with a microbiome like yours exercise <span id="beta_diversity_exercise_response" class="info-loader text-success">...</span>') }}
</div>
</div>
<div class="col diversity-compare">
<div class="col-sm-2">
<img class="diversity-icon" src='/static/img/sleep.png'>
</div>
<div class="col-sm-8 diversity-text">
<span id="beta_diversity_sleep_value" class="info-loader font-weight-bold">...</span>
{{ _('of people with a microbiome like yours get') }}
<span id="beta_diversity_sleep_response" class="info-loader text-success">...</span>
{{ _('of sleep at night') }}
{{ _('<span id="beta_diversity_sleep_value" class="info-loader font-weight-bold">...</span> of people with a microbiome like yours get <span id="beta_diversity_sleep_response" class="info-loader text-success">...</span> of sleep at night') }}
</div>
</div>
</div>
Expand All @@ -1593,17 +1580,15 @@
<img class="diversity-icon" src='/static/img/age.png'>
</div>
<div class="col-sm-8 diversity-text">
<span id="beta_diversity_age_value" class="info-loader font-weight-bold">...</span>
{{ _('of people with a microbiome like yours were the same age as you') }}
{{ _('<span id="beta_diversity_age_value" class="info-loader font-weight-bold">...</span> of people with a microbiome like yours were the same age as you') }}
</div>
</div>
<div class="col diversity-compare">
<div class="col-sm-2">
<img class="diversity-icon" src='/static/img/gender.png'>
</div>
<div class="col-sm-8 diversity-text">
<span id="beta_diversity_sex_value" class="info-loader font-weight-bold">...</span>
{{ _('of people with a microbiome like yours were the same gender') }}
{{ _('<span id="beta_diversity_sex_value" class="info-loader font-weight-bold">...</span> of people with a microbiome like yours were the same gender') }}
</div>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions microsetta_interface/templates/reports.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@
</div>
</div>
{% endfor %}
{% for er in external_reports_kit %}
<div class="row mb-2">
<div class="barcode-col">
<img src="/static/img/tube_icon.svg" width="24" height="24" />
</div>
<div class="barcode-col barcode-text">
{{ er.file_title }}
</div>
<div class="barcode-col barcode-col-end">
<a href="/accounts/{{account_id}}/sources/{{source_id}}/external_reports/{{ er.external_report_id }}" class="btn btn-white-blue-border" role="button" onClick="return disable_link(this);">{{ _('Download Report') }}</a>
</div>
</div>
{% endfor %}
</div>
<div class="card mt-4 p-4">
<div class="row">
Expand All @@ -120,6 +133,16 @@
</div>
</div>
{% endfor %}
{% for er in external_reports_ffq %}
<div class="row mt-3">
<div class="barcode-col ffq-text">
{{ er.file_title }}
</div>
<div class="barcode-col barcode-col-end">
<a href="/accounts/{{account_id}}/sources/{{source_id}}/external_reports/{{ er.external_report_id }}" class="btn btn-white-blue-border" role="button" onClick="return disable_link(this);">{{ _('Download Report') }}</a>
</div>
</div>
{% endfor %}
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions microsetta_interface/templates/sitebase.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
{{ _('The') }} "<span class="skip-text">{{ _('SKIP') }}</span>" {{ _('option can be found at the top right corner of each question.') }}
<ul>
<li>{{ _('Skipping a question clears your selected answer and hides the options.') }}</li>
<li>{{ _('Click') }} "<span class="skip-text">{{ _('DISPLAY') }}</span>" {{ _('to bring back the hidden response options.') }}</li>
<li>{{ _('If you want to reset an incorrect answer quickly, click') }} "<span class="skip-text">{{ _('SKIP') }}</span>" {{ _('then') }} "<span class="skip-text">{{ _('DISPLAY') }}</span>".</li>
<li>{{ _('Click "<span class="skip-text">DISPLAY</span>" to bring back the hidden response options.') }}</li>
<li>{{ _('If you want to reset an incorrect answer quickly, click "<span class="skip-text">SKIP</span>" then "<span class="skip-text">DISPLAY</span>".') }}</li>
<li>{{ _('Skipping a question logs a blank response and counts towards completing a survey.') }}</li>
</ul>
</div>
Expand Down
Loading

0 comments on commit ce64c11

Please sign in to comment.