Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize tags dashboards #3101

Merged
merged 9 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
27 changes: 27 additions & 0 deletions pontoon/base/migrations/0053_alter_translation_index_together.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.15 on 2024-02-20 10:51

from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("base", "0052_rename_logged_in_users"),
]

operations = [
migrations.AlterIndexTogether(
name="translation",
index_together={
("locale", "user", "entity"),
("entity", "user", "approved", "pretranslated"),
("entity", "locale", "fuzzy"),
("date", "locale"),
("entity", "locale", "approved"),
("entity", "locale", "pretranslated"),
("approved_date", "locale"),
},
),
]
39 changes: 20 additions & 19 deletions pontoon/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,25 @@ class AggregatedStats(models.Model):
class Meta:
abstract = True

@classmethod
def get_chart_dict(cls, obj):
"""Get chart data dictionary"""
if obj.total_strings:
return {
"total_strings": obj.total_strings,
"approved_strings": obj.approved_strings,
"pretranslated_strings": obj.pretranslated_strings,
"strings_with_errors": obj.strings_with_errors,
"strings_with_warnings": obj.strings_with_warnings,
"unreviewed_strings": obj.unreviewed_strings,
"approved_share": round(obj.approved_percent),
"pretranslated_share": round(obj.pretranslated_percent),
"errors_share": round(obj.errors_percent),
"warnings_share": round(obj.warnings_percent),
"unreviewed_share": round(obj.unreviewed_percent),
"completion_percent": int(math.floor(obj.completed_percent)),
}

@classmethod
def get_stats_sum(cls, qs):
"""
Expand Down Expand Up @@ -1837,25 +1856,6 @@ def get_chart(cls, self, extra=None):

return chart

@classmethod
def get_chart_dict(cls, obj):
"""Get chart data dictionary"""
if obj.total_strings:
return {
"total_strings": obj.total_strings,
"approved_strings": obj.approved_strings,
"pretranslated_strings": obj.pretranslated_strings,
"strings_with_errors": obj.strings_with_errors,
"strings_with_warnings": obj.strings_with_warnings,
"unreviewed_strings": obj.unreviewed_strings,
"approved_share": round(obj.approved_percent),
"pretranslated_share": round(obj.pretranslated_percent),
"errors_share": round(obj.errors_percent),
"warnings_share": round(obj.warnings_percent),
"unreviewed_share": round(obj.unreviewed_percent),
"completion_percent": int(math.floor(obj.completed_percent)),
}

def aggregate_stats(self):
TranslatedResource.objects.filter(
resource__project=self.project,
Expand Down Expand Up @@ -3284,6 +3284,7 @@ class Meta:
("entity", "locale", "fuzzy"),
("locale", "user", "entity"),
("date", "locale"),
("approved_date", "locale"),
)
constraints = [
models.UniqueConstraint(
Expand Down
11 changes: 2 additions & 9 deletions pontoon/localizations/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import math
from operator import attrgetter
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db.models import Q
Expand All @@ -20,7 +19,7 @@
)
from pontoon.contributors.views import ContributorsMixin
from pontoon.insights.utils import get_insights
from pontoon.tags.utils import TagsTool
from pontoon.tags.utils import Tags


def localization(request, code, slug):
Expand Down Expand Up @@ -159,13 +158,7 @@ def ajax_tags(request, code, slug):
if not project.tags_enabled:
raise Http404

tags_tool = TagsTool(
locales=[locale],
projects=[project],
priority=True,
)

tags = sorted(tags_tool, key=attrgetter("priority"), reverse=True)
tags = Tags(project=project, locale=locale).get()

return render(
request,
Expand Down
4 changes: 4 additions & 0 deletions pontoon/projects/templates/projects/includes/teams.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
{% set locale_projects = project.available_locales_list() %}

{% for locale in locales %}
{% if not tag %}
{% set main_link = url('pontoon.projects.project', project.slug) %}
{% set chart_link = url('pontoon.translate', locale.code, project.slug, 'all-resources') %}
{% set latest_activity = locale.get_latest_activity(project) %}
{% set chart = locale.get_chart(project) %}
{% endif %}
{% if locale.code in locale_projects %}
{% set class = 'limited' %}
{% if chart %}
Expand All @@ -35,6 +37,8 @@
{% if tag %}
{% set main_link = url('pontoon.projects.project', project.slug) + '?tag=' + tag.slug %}
{% set chart_link = url('pontoon.translate', locale.code, project.slug, 'all-resources') + '?tag=' + tag.slug %}
{% set latest_activity = locale.latest_activity %}
{% set chart = locale.chart %}
{% if chart %}
{% set main_link = chart_link %}
{% endif %}
Expand Down
10 changes: 2 additions & 8 deletions pontoon/projects/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import uuid
from operator import attrgetter
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
Expand All @@ -19,7 +18,7 @@
from pontoon.contributors.views import ContributorsMixin
from pontoon.insights.utils import get_insights
from pontoon.projects import forms
from pontoon.tags.utils import TagsTool
from pontoon.tags.utils import Tags


def projects(request):
Expand Down Expand Up @@ -107,12 +106,7 @@ def ajax_tags(request, slug):
if not project.tags_enabled:
raise Http404

tags_tool = TagsTool(
projects=[project],
priority=True,
)

tags = sorted(tags_tool, key=attrgetter("priority"), reverse=True)
tags = Tags(project=project).get()

return render(
request,
Expand Down
2 changes: 1 addition & 1 deletion pontoon/tags/templates/tags/tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h1>
</ul>

{{ HeadingInfo.progress_chart() }}
{{ HeadingInfo.progress_chart_legend(tag) }}
{{ HeadingInfo.progress_chart_legend(tag.chart) }}
</div>
</section>
{% endblock %}
Expand Down
12 changes: 3 additions & 9 deletions pontoon/tags/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.urls import reverse

from pontoon.base.models import Priority
from pontoon.tags.utils import TaggedLocale, TagTool


@pytest.mark.django_db
Expand Down Expand Up @@ -144,14 +143,11 @@ def test_view_project_tag_locales(client, project_a, tag_a):
)

# tag is not associated with project
project_a.tag_set.remove(tag_a)
response = client.get(url)
assert response.status_code == 404

# tag has no priority so still wont show up...
project_a.tag_set.add(tag_a)
response = client.get(url)
assert response.status_code == 404

tag_a.priority = Priority.NORMAL
tag_a.save()
response = client.get(url)
Expand All @@ -165,12 +161,11 @@ def test_view_project_tag_locales(client, project_a, tag_a):
assert response.context_data["project"] == project_a

res_tag = response.context_data["tag"]
assert isinstance(res_tag, TagTool)
assert res_tag.object == tag_a
assert res_tag == tag_a


@pytest.mark.django_db
def test_view_project_tag_locales_ajax(client, project_a, project_locale_a, tag_a):
def test_view_project_tag_locales_ajax(client, project_a, tag_a):
url = reverse(
"pontoon.tags.ajax.teams",
kwargs=dict(project=project_a.slug, tag=tag_a.slug),
Expand All @@ -192,7 +187,6 @@ def test_view_project_tag_locales_ajax(client, project_a, project_locale_a, tag_

for i, locale in enumerate(locales):
locale = response.context_data["locales"][i]
assert isinstance(locale, TaggedLocale)
assert locale.code == locales[i].locale.code
assert locale.name == locales[i].locale.name

Expand Down
Loading
Loading