Commit 5227e58b authored by Michal Čihař's avatar Michal Čihař

Simplify handing of translation checklist

Factored out TranslationChecklist class which handles most of the logic.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 62ebed8a
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2016 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
class TranslationChecklist(list):
"""Simple list wrapper for translation checklist"""
def add_if(self, name, label, count, level):
"""Add to list if there are matches"""
if count > 0:
self.add(name, label, count, level)
def add(self, name, label, count, level):
"""Adds item to the list"""
self.append((name, label, count, level))
...@@ -47,6 +47,7 @@ from weblate.trans.mixins import URLMixin, PercentMixin, LoggerMixin ...@@ -47,6 +47,7 @@ from weblate.trans.mixins import URLMixin, PercentMixin, LoggerMixin
from weblate.trans.boolean_sum import BooleanSum from weblate.trans.boolean_sum import BooleanSum
from weblate.accounts.models import notify_new_string, get_author_name from weblate.accounts.models import notify_new_string, get_author_name
from weblate.trans.models.changes import Change from weblate.trans.models.changes import Change
from weblate.trans.checklists import TranslationChecklist
class TranslationManager(models.Manager): class TranslationManager(models.Manager):
...@@ -974,92 +975,78 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -974,92 +975,78 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
''' '''
Returns list of failing checks on current translation. Returns list of failing checks on current translation.
''' '''
result = [ result = TranslationChecklist()
(
'all', # All strings
_('All strings'), result.add('all', _('All strings'), self.total, 'success')
self.total,
'success',
)
]
# Count of translated strings # Count of translated strings
if self.translated > 0: result.add_if(
result.append((
'translated', 'translated',
_('Translated strings'), _('Translated strings'),
self.translated, self.translated,
'success', 'success',
)) )
# Untranslated strings # Untranslated strings
nottranslated = self.total - self.translated result.add_if(
if nottranslated > 0:
result.append((
'untranslated', 'untranslated',
_('Untranslated strings'), _('Untranslated strings'),
nottranslated, self.total - self.translated,
'danger', 'danger',
)) )
# Untranslated words, the link is same, just to show number of words # Untranslated words, the link is same, just to show number of words
nottranslated = self.total_words - self.translated_words result.add_if(
if nottranslated > 0:
result.append((
'untranslated', 'untranslated',
_('Untranslated words'), _('Untranslated words'),
nottranslated, self.total_words - self.translated_words,
'danger', 'danger',
)) )
# Fuzzy strings # Fuzzy strings
if self.fuzzy > 0: result.add_if(
result.append((
'fuzzy', 'fuzzy',
_('Strings needing review'), _('Strings needing review'),
self.fuzzy, self.fuzzy,
'danger', 'danger',
)) )
# Translations with suggestions # Translations with suggestions
if self.have_suggestion > 0: result.add_if(
result.append((
'suggestions', 'suggestions',
_('Strings with suggestions'), _('Strings with suggestions'),
self.have_suggestion, self.have_suggestion,
'info', 'info',
)) )
# All checks # All checks
if self.failing_checks > 0: result.add_if(
result.append((
'allchecks', 'allchecks',
_('Strings with any failing checks'), _('Strings with any failing checks'),
self.failing_checks, self.failing_checks,
'danger', 'danger',
)) )
# Process specific checks # Process specific checks
for check in CHECKS: for check in CHECKS:
if not CHECKS[check].target: check_obj = CHECKS[check]
if not check_obj.target:
continue continue
cnt = self.unit_set.count_type(check, self) result.add_if(
if cnt > 0:
result.append((
check, check,
CHECKS[check].description, check_obj.description,
cnt, self.unit_set.count_type(check, self),
CHECKS[check].severity, check_obj.severity,
)) )
# Grab comments # Grab comments
if self.have_comment > 0: result.add_if(
result.append((
'comments', 'comments',
_('Strings with comments'), _('Strings with comments'),
self.have_comment, self.have_comment,
'info', 'info',
)) )
return result return result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment