Skip to content

Commit

Permalink
Move functions to a more logical place.
Browse files Browse the repository at this point in the history
  • Loading branch information
julen committed Aug 22, 2012
1 parent f85ab2d commit 1b0f19f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
35 changes: 0 additions & 35 deletions pootle/apps/pootle_store/templatetags/store_tags.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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())
Expand Down
47 changes: 47 additions & 0 deletions pootle/apps/pootle_store/util.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions pootle/apps/pootle_store/views.py
Expand Up @@ -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


Expand Down

0 comments on commit 1b0f19f

Please sign in to comment.