Commit 483b9818 authored by Michal Čihař's avatar Michal Čihař

Store comment counts in the database

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent c77c4bfe
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('trans', '0011_auto_20141114_1008'),
]
operations = [
migrations.AddField(
model_name='translation',
name='have_comment',
field=models.IntegerField(default=0, db_index=True),
preserve_default=True,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db.models.aggregates import Sum
from weblate.trans.boolean_sum import BooleanSum
def fill_in_have_comment(apps, schema_editor):
Translation = apps.get_model('trans', 'Translation')
for translation in Translation.objects.all():
stats = translation.unit_set.aggregate(
Sum('num_words'),
BooleanSum('has_comment'),
)
if stats['num_words__sum'] is not None:
translation.have_comment = int(stats['has_comment__sum'])
translation.save()
class Migration(migrations.Migration):
dependencies = [
('trans', '0012_translation_have_comment'),
]
operations = [
migrations.RunPython(fill_in_have_comment),
]
......@@ -127,6 +127,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
total_words = models.IntegerField(default=0)
failing_checks = models.IntegerField(default=0, db_index=True)
have_suggestion = models.IntegerField(default=0, db_index=True)
have_comment = models.IntegerField(default=0, db_index=True)
enabled = models.BooleanField(default=True, db_index=True)
......@@ -642,6 +643,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
BooleanSum('translated'),
BooleanSum('has_failing_check'),
BooleanSum('has_suggestion'),
BooleanSum('has_comment'),
Count('id'),
)
......@@ -653,6 +655,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
self.translated = 0
self.failing_checks = 0
self.have_suggestion = 0
self.have_comment = 0
else:
self.total_words = stats['num_words__sum']
self.total = stats['id__count']
......@@ -660,6 +663,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
self.translated = int(stats['translated__sum'])
self.failing_checks = int(stats['has_failing_check__sum'])
self.have_suggestion = int(stats['has_suggestion__sum'])
self.have_comment = int(stats['has_comment__sum'])
# Count translated words
self.translated_words = self.unit_set.filter(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment