[damned-lies] Ensure that statistics objects (and related states/actions) are not deleted when a pofile is deleted
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Ensure that statistics objects (and related states/actions) are not deleted when a pofile is deleted
- Date: Mon, 12 Sep 2011 12:32:04 +0000 (UTC)
commit a386ea594bd6ee01878995bc4f1b65edd2bb099a
Author: Claude Paroz <claude 2xlibre net>
Date: Mon Sep 12 14:31:43 2011 +0200
Ensure that statistics objects (and related states/actions) are not deleted when a pofile is deleted
stats/models.py | 4 ++--
stats/tests/__init__.py | 15 +++++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 15f960d..9af6212 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -1273,8 +1273,8 @@ class Statistics(models.Model):
old_fuzzy = models.IntegerField(default=0) # obsolete
old_untranslated = models.IntegerField(default=0) # obsolete
- full_po = models.OneToOneField(PoFile, null=True, related_name='stat_f')
- part_po = models.OneToOneField(PoFile, null=True, related_name='stat_p')
+ full_po = models.OneToOneField(PoFile, null=True, related_name='stat_f', on_delete=models.SET_NULL)
+ part_po = models.OneToOneField(PoFile, null=True, related_name='stat_p', on_delete=models.SET_NULL)
class Meta:
db_table = 'statistics'
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index 595e6a9..3a6ec91 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -242,6 +242,21 @@ class StatisticsTests(TestCase):
self.assertEqual(stats.po_url(), "/module/po/zenity.po.gnome-2-30.bem.po")
self.assertEqual(stats.po_url(reduced=True), "/module/po/zenity.po.gnome-2-30.bem-reduced.po")
+ def testSetTranslationStats(self):
+ from vertimus.models import State, StateTranslating
+ # Get a stat that has full_po and part_po
+ stat = Statistics.objects.get(branch__module__name='zenity', branch__name='gnome-2-30', language__locale='it', domain__dtype='ui')
+ pers = Person.objects.create(username="toto")
+ state = StateTranslating.objects.create(branch=stat.branch, domain=stat.domain, language=stat.language, person=pers)
+ # Mark file completely translated
+ self.assertNotEqual(stat.part_po, stat.full_po)
+ stat.set_translation_stats('dummy', 136, 0, 0)
+ self.assertEqual(stat.part_po, stat.full_po)
+ # Check state is still translating
+ state = State.objects.filter(branch=stat.branch, domain=stat.domain, language=stat.language)
+ self.assertEqual(len(state), 1)
+ self.assertTrue(isinstance(state[0], StateTranslating))
+
class FigureTests(TestCase):
fixtures = ['sample_data.json']
def testFigureView(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]