Stats for subprojects

This commit is contained in:
Michal Čihař 2012-03-05 13:45:16 +01:00
parent 830015769c
commit e792bacaad
2 changed files with 20 additions and 2 deletions

View File

@ -11,10 +11,24 @@
<h2>{% trans "Subprojects" %}</h2>
<ul>
<table>
<thead>
<tr>
<th>{% trans "Project" %}</th>
<th colspan="2">{% trans "Translated" %}</th>
</tr>
<tbody>
{% for prj in object.subproject_set.all %}
<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 %}
</ul>
</tbody>
</table>
{% endblock %}

View File

@ -185,6 +185,10 @@ class SubProject(models.Model):
self.create_translations()
def get_translated_percent(self):
translations = self.translation_set.aggregate(Sum('translated'), Sum('total'))
return round(translations['translated__sum'] * 100.0 / translations['total__sum'], 1)
class Translation(models.Model):
subproject = models.ForeignKey(SubProject)
language = models.ForeignKey(Language)