Summary stats on title page

This commit is contained in:
Michal Čihař 2012-03-05 13:43:33 +01:00
parent e1571b96a7
commit 830015769c
4 changed files with 29 additions and 3 deletions

View File

@ -5,11 +5,24 @@
<h2>{% trans "Projects" %}</h2> <h2>{% trans "Projects" %}</h2>
<ul> <table>
<thead>
<tr>
<th>{% trans "Project" %}</th>
<th colspan="2">{% trans "Translated" %}</th>
</tr>
<tbody>
{% for prj in projects %} {% for prj in projects %}
<li><a href="{{ prj.get_absolute_url }}">{{ prj.name }}</a></li> {% with prj.get_translated_percent as percent %}
<tr>
<th><a href="{{ prj.get_absolute_url }}">{{ prj.name }}</a></th>
<td class="percent">{{ percent }}%</td>
<td class="progress"><div class="progress" id="{{ percent|floatformat:0 }}"></div></td>
</tr>
{% endwith %}
{% endfor %} {% endfor %}
</ul> </tbody>
</table>
{% endblock %} {% endblock %}

View File

@ -83,3 +83,9 @@ td.suggestions table {
.helptext { .helptext {
font-size: smaller; font-size: smaller;
} }
.percent {
text-align: right;
}
div.progress {
width: 20em;
}

View File

@ -18,4 +18,5 @@ $(document).ready(function(){
}); });
$('.accordion').accordion(); $('.accordion').accordion();
$('.errorlist').addClass('ui-state-error ui-corner-all'); $('.errorlist').addClass('ui-state-error ui-corner-all');
$('div.progress').each(function f(i, e) {e = $(e); e.progressbar({ value: parseInt(e.attr('id')) })});
}); });

View File

@ -3,6 +3,7 @@ from django.db.models import Q
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from lang.models import Language from lang.models import Language
from django.db.models import Sum
from django.utils.translation import ugettext_lazy, ugettext as _ from django.utils.translation import ugettext_lazy, ugettext as _
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from glob import glob from glob import glob
@ -51,6 +52,11 @@ class Project(models.Model):
super(Project, self).save(*args, **kwargs) super(Project, self).save(*args, **kwargs)
def get_translated_percent(self):
translations = Translation.objects.filter(subproject__project = self).aggregate(Sum('translated'), Sum('total'))
return round(translations['translated__sum'] * 100.0 / translations['total__sum'], 1)
class SubProject(models.Model): class SubProject(models.Model):
name = models.CharField(max_length = 100, help_text = _('Name to display')) name = models.CharField(max_length = 100, help_text = _('Name to display'))
slug = models.SlugField(db_index = True, help_text = _('Name used in URLs')) slug = models.SlugField(db_index = True, help_text = _('Name used in URLs'))