Skip to content

Commit

Permalink
Added code documentation & system settings
Browse files Browse the repository at this point in the history
  • Loading branch information
wes-otf committed Sep 13, 2024
1 parent 651378e commit 35edf55
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "funds/applicationsubmission_detail.html" %}
{% load i18n static workflow_tags review_tags determination_tags heroicons %}
{% load i18n static workflow_tags review_tags determination_tags translate_tags heroicons %}

{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/fancybox.css' %}">
Expand Down Expand Up @@ -98,5 +98,7 @@ <h5 class="m-0">{% trans "Reminders" %}</h5>
<script src="{% static 'js/jquery.fancybox.min.js' %}"></script>
<script src="{% static 'js/fancybox-global.js' %}"></script>
<script src="{% static 'js/toggle-related.js' %}"></script>
<script src="{% static 'js/application-translate.js' %}"></script>
{% if request.user|can_translate_submission %}
<script src="{% static 'js/application-translate.js' %}"></script>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base-apply.html" %}
{% load i18n static workflow_tags wagtailcore_tags statusbar_tags archive_tags submission_tags %}
{% load i18n static workflow_tags wagtailcore_tags statusbar_tags archive_tags submission_tags translate_tags %}
{% load heroicons %}

{% block title %}{{ object|doc_title }}{% endblock %}
Expand Down Expand Up @@ -145,9 +145,15 @@ <h5>{% blocktrans with stage=object.previous.stage %}Your {{ stage }} applicatio
{% endif %}
</div>
</header>
<div class="wrapper" hx-get="{% url 'funds:submissions:partial-translate-answers' object.id %}" hx-trigger="translateSubmission from:body" hx-indicator="#translate-card-loading" hx-vals='js:{fl: event.detail.from_lang, tl: event.detail.to_lang}'>
{% include "funds/includes/rendered_answers.html" %}
</div>
{% if request.user|can_translate_submission %}
<div class="wrapper" hx-get="{% url 'funds:submissions:partial-translate-answers' object.id %}" hx-trigger="translateSubmission from:body" hx-indicator="#translate-card-loading" hx-vals='js:{fl: event.detail.from_lang, tl: event.detail.to_lang}'>
{% include "funds/includes/rendered_answers.html" %}
</div>
{% else %}
<div class="wrapper">
{% include "funds/includes/rendered_answers.html" %}
</div>
{% endif %}

</article>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n %}
{% load heroicons primaryactions_tags %}
{% load heroicons primaryactions_tags translate_tags %}

<h5>{% trans "Actions to take" %}</h5>

Expand Down Expand Up @@ -84,10 +84,12 @@ <h5>{% trans "Actions to take" %}</h5>
<summary class="sidebar__separator sidebar__separator--medium">{% trans "More actions" %}</summary>
<a class="button button--white button--full-width button--bottom-space" href="{% url 'funds:submissions:revisions:list' submission_pk=object.id %}">{% trans "Revisions" %}</a>

<button class="button button--white button--full-width button--bottom-space" hx-get="{% url 'funds:submissions:translate' pk=object.pk %}" hx-target="#htmx-modal">
{% heroicon_outline "language" aria_hidden="true" size=15 stroke_width=2 class="inline align-baseline me-1" %}
{% trans "Translate" %}
</button>
{% if request.user|can_translate_submission %}
<button class="button button--white button--full-width button--bottom-space" hx-get="{% url 'funds:submissions:translate' pk=object.pk %}" hx-target="#htmx-modal">
{% heroicon_outline "language" aria_hidden="true" size=15 stroke_width=2 class="inline align-baseline me-1" %}
{% trans "Translate" %}
</button>
{% endif %}

<button
class="button button--white button--full-width button--bottom-space"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n wagtailusers_tags workflow_tags heroicons %}
{% if from_lang_name and to_lang_name %}
{% load i18n wagtailusers_tags workflow_tags translate_tags heroicons %}
{% if request.user|can_translate_submission and from_lang_name and to_lang_name %}
<div class="w-full text-center my-2 py-5 border rounded-lg shadow-md">
<span>
{% heroicon_outline "language" aria_hidden="true" size=15 stroke_width=2 class="inline align-baseline me-1" %}
Expand Down
42 changes: 41 additions & 1 deletion hypha/apply/funds/templatetags/translate_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,33 @@


@register.simple_tag(takes_context=True)
def get_language_choices_json(context) -> str:
def get_language_choices_json(context: dict) -> str:
"""Generate a JSON output of available translation options
Args:
context: the context of the template, containing an `HttpRequest` key & object
Returns:
A JSON string in the format of:
```
[
{
"code": "<from language code>",
"name": "<from language name>",
"to": [
{
"code": "<to language code>",
"name": "<from language name>"
}
],
"selectedTo": "<selected to language if any>",
"selected": bool if selected by default
},
...
]
```
"""
available_translations = get_available_translations()
from_langs = {package.from_code for package in available_translations}
default_to_lang = settings.LANGUAGE_CODE
Expand Down Expand Up @@ -44,3 +70,17 @@ def get_language_choices_json(context) -> str:
)

return mark_safe(json.dumps(choices))


@register.filter
def can_translate_submission(user) -> bool:
"""Verify that system settings & user role allows for submission translations.
Args:
user: the user to check the role of.
Returns:
bool: true if submission can be translated, false if not.
"""
return bool(settings.ALLOW_SUBMISSION_TRANSLATIONS and user.is_org_faculty)
3 changes: 3 additions & 0 deletions hypha/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
# The corrosponding locale dir is named: en, en_GB, en_US
LANGUAGE_CODE = env.str("LANGUAGE_CODE", "en")

# Translation settings
ALLOW_SUBMISSION_TRANSLATIONS = env.bool("ALLOW_SUBMISSION_TRANSLATIONS", False)

# Number of seconds that password reset and account activation links are valid (default 259200, 3 days).
PASSWORD_RESET_TIMEOUT = env.int("PASSWORD_RESET_TIMEOUT", 259200)

Expand Down

0 comments on commit 35edf55

Please sign in to comment.