def get_per_language_stats(project):
 result = []
 languages = Translation.objects.filter(subproject__project=project).values_list(u'language', flat=True).distinct()
 total = 0
 total_words = 0
 for component in project.subproject_set.all():
  try:
   translation = component.translation_set.all()[0]
   total += translation.total
   total_words += translation.total_words
  except IndexError:
   pass
 for language in Language.objects.filter(pk__in=languages):
  data = Translation.objects.filter(language=language, subproject__project=project).aggregate(Sum(u'translated'), Sum(u'translated_words'))
  translated = data[u'translated__sum']
  translated_words = data[u'translated_words__sum']
  pos = None
  for (i, data) in enumerate(result):
   if (translated >= data[1]):
    pos = i
    break
  value = (language, translated, total, translated_words, total_words)
  if (pos is not None):
   result.insert(pos, value)
  else:
   result.append(value)
 return result

def get_per_language_stats ( project ) : result = [ ] languages = Translation . objects . filter ( subproject__project = project ) . values_list ( u'language' , flat = True ) . distinct ( ) total = 0 total_words = 0 for component in project . subproject_set . all ( ) : try : translation = component . translation_set . all ( ) [ 0 ] total += translation . total total_words += translation . total_words except IndexError : pass for language in Language . objects . filter ( pk__in = languages ) : data = Translation . objects . filter ( language = language , subproject__project = project ) . aggregate ( Sum ( u'translated' ) , Sum ( u'translated_words' ) ) translated = data [ u'translated__sum' ] translated_words = data [ u'translated_words__sum' ] pos = None for ( i , data ) in enumerate ( result ) : if ( translated >= data [ 1 ] ) : pos = i break value = ( language , translated , total , translated_words , total_words ) if ( pos is not None ) : result . insert ( pos , value ) else : result . append ( value ) return result
calculates per language stats for project .