|
7 | 7 |
|
8 | 8 | from django.contrib.postgres.fields import ArrayField |
9 | 9 | from django.db import models |
10 | | -from django.db.models import Count, F, Prefetch, Q |
| 10 | +from django.db.models import F, Prefetch, Q |
11 | 11 | from django.utils import timezone |
12 | 12 |
|
13 | 13 | from pontoon.base import utils |
|
16 | 16 | from pontoon.base.models.project_locale import ProjectLocale |
17 | 17 | from pontoon.base.models.resource import Resource |
18 | 18 | from pontoon.base.models.section import Section |
| 19 | +from pontoon.base.models.stats import aggregate_translation_stats |
19 | 20 |
|
20 | 21 |
|
21 | 22 | def combine_entity_filters(entities, filter_choices, filters, *args): |
@@ -290,48 +291,7 @@ def get_stats(self, locale) -> dict[str, int]: |
290 | 291 | :arg Locale locale: filter translations for this locale. |
291 | 292 | :return: a dictionary with stats for the Entity+Locale |
292 | 293 | """ |
293 | | - stats = self.translation_set.filter(locale=locale).aggregate( |
294 | | - approved_count=Count( |
295 | | - "pk", |
296 | | - filter=Q(approved=True, errors__isnull=True, warnings__isnull=True), |
297 | | - ), |
298 | | - pretranslated_count=Count( |
299 | | - "pk", |
300 | | - filter=Q( |
301 | | - pretranslated=True, errors__isnull=True, warnings__isnull=True |
302 | | - ), |
303 | | - ), |
304 | | - errors_count=Count( |
305 | | - "pk", |
306 | | - distinct=True, |
307 | | - filter=Q( |
308 | | - Q(Q(approved=True) | Q(pretranslated=True) | Q(fuzzy=True)) |
309 | | - & Q(errors__isnull=False) |
310 | | - ), |
311 | | - ), |
312 | | - warnings_count=Count( |
313 | | - "pk", |
314 | | - distinct=True, |
315 | | - filter=Q( |
316 | | - Q(Q(approved=True) | Q(pretranslated=True) | Q(fuzzy=True)) |
317 | | - & Q(warnings__isnull=False) |
318 | | - ), |
319 | | - ), |
320 | | - unreviewed_count=Count( |
321 | | - "pk", |
322 | | - distinct=True, |
323 | | - filter=Q( |
324 | | - approved=False, rejected=False, pretranslated=False, fuzzy=False |
325 | | - ), |
326 | | - ), |
327 | | - ) |
328 | | - return { |
329 | | - "approved": stats["approved_count"], |
330 | | - "pretranslated": stats["pretranslated_count"], |
331 | | - "errors": stats["errors_count"], |
332 | | - "warnings": stats["warnings_count"], |
333 | | - "unreviewed": stats["unreviewed_count"], |
334 | | - } |
| 294 | + return aggregate_translation_stats(self.translation_set.filter(locale=locale)) |
335 | 295 |
|
336 | 296 | def has_changed(self, locale): |
337 | 297 | """ |
|
0 commit comments