Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pontoon/administration/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,28 +382,32 @@ def test_manage_project_strings_download_csv(client_superuser):

@pytest.mark.django_db
def test_manage_project_translate_link_excludes_obsolete_resources(client_superuser):
"""Test that translate_locale is only set when non-obsolete resources exist."""
"""Test that Translate link is only shown when non-obsolete resources exist."""
locale_kl = LocaleFactory.create(code="tlh", name="Klingon")
project = ProjectFactory.create(
data_source=Project.DataSource.DATABASE,
locales=[locale_kl],
repositories=[],
)

url = reverse("pontoon.admin.project", args=(project.slug,))
translate_url = reverse(
"pontoon.localizations.localization", args=(locale_kl.code, project.slug)
)

# add obsolete resource
ResourceFactory.create(project=project, obsolete=True)

url = reverse("pontoon.admin.project", args=(project.slug,))
response = client_superuser.get(url)
assert response.status_code == 200
assert "translate_locale" not in response.context
assert translate_url.encode() not in response.content

# add non-obsolete resource
ResourceFactory.create(project=project, obsolete=False)

response = client_superuser.get(url)
assert response.status_code == 200
assert response.context["translate_locale"] == "tlh"
assert translate_url.encode() in response.content


@pytest.mark.django_db
Expand Down
70 changes: 61 additions & 9 deletions pontoon/messaging/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from celery import shared_task
from dateutil.relativedelta import relativedelta
from django_jinja.backend import Jinja2
from notifications.models import Notification

from django.conf import settings
Expand All @@ -18,15 +17,20 @@

from pontoon.actionlog.models import ActionLog
from pontoon.base.models import Locale, UserProfile
from pontoon.base.templatetags.helpers import full_url
from pontoon.insights.models import LocaleInsightsSnapshot
from pontoon.messaging.models import EmailContent
from pontoon.messaging.utils import html_to_plain_text_with_links


jinja_env = Jinja2.get_default().env
log = logging.getLogger(__name__)


class SafeDict(dict):
def __missing__(self, key):
return "{" + key + "}"


def _get_monthly_user_actions(users, months_ago):
month_date = timezone.now() - relativedelta(months=months_ago)

Expand Down Expand Up @@ -334,7 +338,17 @@ def send_onboarding_email_1(user):
Sends 1st onboarding email to a new user.
"""
email_content = EmailContent.objects.get(email="onboarding_1")
content = jinja_env.from_string(email_content.body).render()
content = email_content.body.format_map(
SafeDict(
{
"tutorial_url": full_url(
"pontoon.translate", "projects", "tutorial", "playground"
),
"settings_url": full_url("pontoon.contributors.settings"),
"teams_url": full_url("pontoon.teams"),
}
)
)
Comment thread
functionzz marked this conversation as resolved.

subject = email_content.subject
template = get_template("messaging/emails/transactional.html")
Expand Down Expand Up @@ -370,7 +384,15 @@ def send_onboarding_emails_2(users):
log.info("Start sending 2nd onboarding emails.")

email_content = EmailContent.objects.get(email="onboarding_2")
content = jinja_env.from_string(email_content.body).render()
content = email_content.body.format_map(
SafeDict(
{
"homepage_url": full_url("pontoon.homepage"),
"projects_url": full_url("pontoon.projects"),
"teams_url": full_url("pontoon.teams"),
}
)
)

subject = email_content.subject
template = get_template("messaging/emails/transactional.html")
Expand Down Expand Up @@ -406,7 +428,14 @@ def send_onboarding_emails_3(users):
log.info("Start sending 3rd onboarding emails.")

email_content = EmailContent.objects.get(email="onboarding_3")
content = jinja_env.from_string(email_content.body).render()
content = email_content.body.format_map(
SafeDict(
{
"docs_url": full_url("pontoon.docs"),
"settings_url": full_url("pontoon.contributors.settings"),
}
)
)

subject = email_content.subject
template = get_template("messaging/emails/transactional.html")
Expand Down Expand Up @@ -442,7 +471,14 @@ def send_inactive_contributor_emails(users):
log.info("Start sending inactive contributor emails.")

email_content = EmailContent.objects.get(email="inactive_contributor")
content = jinja_env.from_string(email_content.body).render()
content = email_content.body.format_map(
SafeDict(
{
"INACTIVE_CONTRIBUTOR_PERIOD": settings.INACTIVE_CONTRIBUTOR_PERIOD,
"homepage_url": full_url("pontoon.homepage"),
}
)
)

subject = email_content.subject
template = get_template("messaging/emails/transactional.html")
Expand Down Expand Up @@ -490,7 +526,14 @@ def send_inactive_translator_emails(users, translator_map):
log.error(f"User {user} is not a translator of any locale.")
continue

content = jinja_env.from_string(email_content.body).render({"locale": locale})
content = email_content.body.format_map(
SafeDict(
{
"INACTIVE_TRANSLATOR_PERIOD": settings.INACTIVE_TRANSLATOR_PERIOD,
"team_url": full_url("pontoon.teams.team", locale.code),
}
)
)
body_html = template.render(
{
"content": content,
Expand Down Expand Up @@ -532,8 +575,17 @@ def send_inactive_manager_emails(users, manager_map):
except IndexError:
log.error(f"User {user} is not a manager of any locale.")
continue

content = jinja_env.from_string(email_content.body).render({"locale": locale})
content = email_content.body.format_map(
SafeDict(
{
"INACTIVE_MANAGER_PERIOD": settings.INACTIVE_MANAGER_PERIOD,
"contributors_url": full_url(
"pontoon.teams.contributors", locale.code
),
"team_url": full_url("pontoon.teams.team", locale.code),
}
)
)
body_html = template.render(
{
"content": content,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<p>
It's been a while since we’ve last seen you, but we wanted to thank you for
contributing to localization efforts at
<a href="{{ full_url('pontoon.homepage') }}"
>{{ full_url('pontoon.homepage') }}</a
>.
<a href="{homepage_url}">{homepage_url}</a>.
</p>

<p>
Expand All @@ -15,18 +13,16 @@
<p>
As part of our efforts to keep our localization community active and engaged,
we periodically review account activity. We’ve noticed you haven’t signed in
to your Pontoon account in the past {{ settings.INACTIVE_CONTRIBUTOR_PERIOD }}
months. While we completely understand that circumstances change, we wanted to
inform you that we may deactivate dormant accounts in the future to ensure the
to your Pontoon account in the past {INACTIVE_CONTRIBUTOR_PERIOD} months.
While we completely understand that circumstances change, we wanted to inform
you that we may deactivate dormant accounts in the future to ensure the
security and efficiency of our platform.
</p>

<p>
If you’d like to keep your Pontoon account active (we hope you will!) please
sign in to Pontoon by visiting
<a href="{{ full_url('pontoon.homepage') }}"
>{{ full_url('pontoon.homepage') }}</a
>
<a href="{homepage_url}">{homepage_url}</a>
and click the “Sign in” button in the top right corner.
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<p>
As part of our efforts to keep our localization community active and engaged,
we periodically review account activity. We’ve noticed that in the past
{{ settings.INACTIVE_MANAGER_PERIOD }} months you have not submitted any
translations or reviewed any translation submissions for your locale. We
understand that life can get busy, and finding time to contribute to projects
isn't always easy. We get it.
{INACTIVE_MANAGER_PERIOD} months you have not submitted any translations or
reviewed any translation submissions for your locale. We understand that life
can get busy, and finding time to contribute to projects isn't always easy. We
get it.
</p>

<p>
Expand All @@ -40,18 +40,14 @@
<p>
In addition, another Team Manager responsibility is to evaluate candidates for
advanced roles within their community. Please review the
<a href="{{ full_url('pontoon.teams.contributors', locale.code) }}"
>contributors page</a
>
<a href="{contributors_url}">contributors page</a>
for your team and see if there are any motivated and active community members
that may be interested in taking on additional responsibilities within your
team.
</p>

<p>
<a href="{{ full_url('pontoon.teams.team', locale.code) }}"
>{{ full_url('pontoon.teams.team', locale.code) }}</a
>
<a href="{team_url}">{team_url}</a>
</p>

<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<p>
As part of our efforts to keep our localization community active and engaged,
we periodically review account activity. We’ve noticed that in the past
{{ settings.INACTIVE_TRANSLATOR_PERIOD }} months you have not submitted any
translations or reviewed any translation submissions for your locale. We
understand that life can get busy, and finding time to contribute to projects
isn't always easy. We get it.
{INACTIVE_TRANSLATOR_PERIOD} months you have not submitted any translations or
reviewed any translation submissions for your locale. We understand that life
can get busy, and finding time to contribute to projects isn't always easy. We
get it.
</p>

<p>
Expand All @@ -37,9 +37,7 @@
</ul>

<p>
<a href="{{ full_url('pontoon.teams.team', locale.code) }}"
>{{ full_url('pontoon.teams.team', locale.code) }}</a
>
<a href="{team_url}">{team_url}</a>
</p>

<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@
<ol>
<li>
Take a
<a
href="{{ full_url('pontoon.translate', 'projects', 'tutorial', 'playground') }}"
>tour</a
>
<a href="{tutorial_url}">tour</a>
of Pontoon to get familiar with its workflow and features, then play around
in the sandbox to try it out for yourself.
</li>
<li>
Update your
<a href="{{ full_url('pontoon.contributors.settings') }}">settings</a> to
personalize your Pontoon profile by adding an avatar and username, select
between a dark and light theme, and choose your default locale.
<a href="{settings_url}">settings</a> to personalize your Pontoon profile by
adding an avatar and username, select between a dark and light theme, and
choose your default locale.
</li>
<li>
Check out your <a href="{{ full_url('pontoon.teams') }}">team</a> page to
find more information and resources about your locale.
Check out your <a href="{teams_url}">team</a> page to find more information
and resources about your locale.
<ul>
<li>
On the contributors tab you can find your locale’s team managers. If you
Expand All @@ -41,10 +38,10 @@
<li>
Start translating. One of the best ways to get used to translating is to
dive right in! Check the
<a href="{{ full_url('pontoon.teams') }}">team</a> page for your locale and
find a project to work on: look for a project with progress under 100% and
click the “Missing” number that appears when you hover over it - this will
show you anything that still needs a translation.
<a href="{teams_url}">team</a> page for your locale and find a project to
work on: look for a project with progress under 100% and click the “Missing”
number that appears when you hover over it - this will show you anything
that still needs a translation.
</li>
</ol>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<p>
Thank you again for joining translation community on Pontoon. As always, you
can continue contributing translations at
<a href="{{ full_url('pontoon.homepage') }}"
>{{ full_url('pontoon.homepage') }}</a
>.
<a href="{homepage_url}">{homepage_url}</a>.
</p>

<p>
Expand Down Expand Up @@ -39,15 +37,14 @@ <h2>Translation phases</h2>
included into the product. The timing depends on the project, but often
strings will be implemented at the time of the next build and ready to check
in product. Be sure to check the deadlines in the
<a href="{{ full_url('pontoon.projects') }}">project page</a> to understand
which strings need translations soon.
<a href="{projects_url}">project page</a> to understand which strings need
translations soon.
</li>
</ol>

<p>
Each localization community has its own specific workflows, so do reach out to
your <a href="{{ full_url('pontoon.teams') }}">Team Managers</a> to learn
more.
your <a href="{teams_url}">Team Managers</a> to learn more.
</p>

<h2>Team roles</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ <h2>Additional documentation</h2>

<p>
For in-depth documentation on Pontoon, see our
<a href="{{ full_url('pontoon.docs') }}localizer/"
>Documentation for localizers</a
>.
<a href="{docs_url}localizer/">Documentation for localizers</a>.
</p>

<h2>Pontoon Add-on</h2>
Expand All @@ -38,8 +36,7 @@ <h2>Email settings</h2>
<p>
Finally, if you’re interested in the latest updates, announcements about new
Pontoon features and more, be sure to enable “News and updates“ in your
<a href="{{ full_url('pontoon.contributors.settings') }}">settings</a> so you
can be the first to get notified.
<a href="{settings_url}">settings</a> so you can be the first to get notified.
</p>

<p>
Expand Down
Loading
Loading