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
from weblate.trans.boolean_sum import BooleanSum
from weblate.accounts.models import notify_new_string, get_author_name
from weblate.trans.models.changes import Change
from weblate.trans.checklists import TranslationChecklist
class TranslationManager(models.Manager):
......@@ -974,92 +975,78 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
'''
Returns list of failing checks on current translation.
'''
result = [
(
'all',
_('All strings'),
self.total,
'success',
)
]
result = TranslationChecklist()
# All strings
result.add('all', _('All strings'), self.total, 'success')
# Count of translated strings
if self.translated > 0:
result.append((
'translated',
_('Translated strings'),
self.translated,
'success',
))
result.add_if(
'translated',
_('Translated strings'),
self.translated,
'success',
)
# Untranslated strings
nottranslated = self.total - self.translated
if nottranslated > 0:
result.append((
'untranslated',
_('Untranslated strings'),
nottranslated,
'danger',
))
result.add_if(
'untranslated',
_('Untranslated strings'),
self.total - self.translated,
'danger',
)
# Untranslated words, the link is same, just to show number of words
nottranslated = self.total_words - self.translated_words
if nottranslated > 0:
result.append((
'untranslated',
_('Untranslated words'),
nottranslated,
'danger',
))
result.add_if(
'untranslated',
_('Untranslated words'),
self.total_words - self.translated_words,
'danger',
)
# Fuzzy strings
if self.fuzzy > 0:
result.append((
'fuzzy',
_('Strings needing review'),
self.fuzzy,
'danger',
))
result.add_if(
'fuzzy',
_('Strings needing review'),
self.fuzzy,
'danger',
)
# Translations with suggestions
if self.have_suggestion > 0:
result.append((
'suggestions',
_('Strings with suggestions'),
self.have_suggestion,
'info',
))
result.add_if(
'suggestions',
_('Strings with suggestions'),
self.have_suggestion,
'info',
)
# All checks
if self.failing_checks > 0:
result.append((
'allchecks',
_('Strings with any failing checks'),
self.failing_checks,
'danger',
))
result.add_if(
'allchecks',
_('Strings with any failing checks'),
self.failing_checks,
'danger',
)
# Process specific checks
for check in CHECKS:
if not CHECKS[check].target:
check_obj = CHECKS[check]
if not check_obj.target:
continue
cnt = self.unit_set.count_type(check, self)
if cnt > 0:
result.append((
check,
CHECKS[check].description,
cnt,
CHECKS[check].severity,
))
result.add_if(
check,
check_obj.description,
self.unit_set.count_type(check, self),
check_obj.severity,
)
# Grab comments
if self.have_comment > 0:
result.append((
'comments',
_('Strings with comments'),
self.have_comment,
'info',
))
result.add_if(
'comments',
_('Strings with comments'),
self.have_comment,
'info',
)
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