diff --git a/pootle/apps/pootle_store/templatetags/store_tags.py b/pootle/apps/pootle_store/templatetags/store_tags.py index 54df7b1dbbc..1018c0b7bb0 100644 --- a/pootle/apps/pootle_store/templatetags/store_tags.py +++ b/pootle/apps/pootle_store/templatetags/store_tags.py @@ -38,16 +38,6 @@ register = template.Library() -def find_altsrcs(unit, alt_src_langs, store=None, project=None): - store = store or unit.store - project = project or store.translation_project.project - altsrcs = Unit.objects.filter(unitid_hash=unit.unitid_hash, - store__translation_project__project=project, - store__translation_project__language__in=alt_src_langs, - state=TRANSLATED).select_related('store', 'store__translation_project', 'store__translation_project__language') - if project.get_treestyle() == 'nongnu': - altsrcs = altsrcs.filter(store__name=store.name) - return altsrcs def call_highlight(old, new): """Calls diff highlighting code only if the target is set. @@ -118,31 +108,6 @@ def _difflib_highlight_diffs(old, new): highlight_diffs = _difflib_highlight_diffs -def get_sugg_list(unit): - """Get suggested translations and rated scores for the given unit. - - :return: List of tuples containing the suggestion and the score for - it in case it's a terminology project. Otherwise the score - part is filled with False values. - """ - sugg_list = [] - scores = {} - suggestions = unit.get_suggestions() - - if suggestions: - # Avoid the votes query if we're not editing terminology - if (unit.store.is_terminology or - unit.store.translation_project.project.is_terminology): - from voting.models import Vote - scores = Vote.objects.get_scores_in_bulk(suggestions) - - for sugg in suggestions: - score = scores.get(sugg.id, False) - sugg_list.append((sugg, score)) - - return sugg_list - - @register.filter('stat_summary') def stat_summary(store): stats = add_percentages(store.getquickstats()) diff --git a/pootle/apps/pootle_store/util.py b/pootle/apps/pootle_store/util.py index b6c142e4d38..cb36ead9f68 100644 --- a/pootle/apps/pootle_store/util.py +++ b/pootle/apps/pootle_store/util.py @@ -28,6 +28,7 @@ from pootle_misc.aggregate import sum_column from pootle_misc.util import dictsum + # Unit States #: Unit is no longer part of the store OBSOLETE = -100 @@ -149,3 +150,49 @@ def suggestions_sum(queryset): total += item.get_suggestion_count() return total + + +def find_altsrcs(unit, alt_src_langs, store=None, project=None): + from pootle_store.models import Unit + + store = store or unit.store + project = project or store.translation_project.project + + altsrcs = Unit.objects.filter( + unitid_hash=unit.unitid_hash, + store__translation_project__project=project, + store__translation_project__language__in=alt_src_langs, + state=TRANSLATED) \ + .select_related( + 'store', 'store__translation_project', + 'store__translation_project__language') + + if project.get_treestyle() == 'nongnu': + altsrcs = altsrcs.filter(store__name=store.name) + + return altsrcs + + +def get_sugg_list(unit): + """Get suggested translations and rated scores for the given unit. + + :return: List of tuples containing the suggestion and the score for + it in case it's a terminology project. Otherwise the score + part is filled with False values. + """ + sugg_list = [] + scores = {} + suggestions = unit.get_suggestions() + + if suggestions: + # Avoid the votes query if we're not editing terminology + if (unit.store.is_terminology or + unit.store.translation_project.project.is_terminology): + from voting.models import Vote + scores = Vote.objects.get_scores_in_bulk(suggestions) + + for sugg in suggestions: + score = scores.get(sugg.id, False) + sugg_list.append((sugg, score)) + + return sugg_list diff --git a/pootle/apps/pootle_store/views.py b/pootle/apps/pootle_store/views.py index bef91ba7cad..5ffd4ccdf58 100644 --- a/pootle/apps/pootle_store/views.py +++ b/pootle/apps/pootle_store/views.py @@ -52,12 +52,11 @@ from pootle_store.forms import (unit_comment_form_factory, unit_form_factory, highlight_whitespace) from pootle_store.signals import translation_submitted -from pootle_store.templatetags.store_tags import (find_altsrcs, get_sugg_list, - highlight_diffs, +from pootle_store.templatetags.store_tags import (highlight_diffs, pluralize_source, pluralize_target) from pootle_store.util import (UNTRANSLATED, FUZZY, TRANSLATED, STATES_MAP, - absolute_real_path) + absolute_real_path, find_altsrcs, get_sugg_list) from pootle_translationproject.forms import make_search_form