Exemple #1
0
 def create_normal(self, data, translations=None):
     obj = Normal(shared_field=data.shared_field)
     for code in translations or self.translations:
         obj.translate(code)
         obj.translated_field = data.translated_field[code]
         obj.save()
     return obj
Exemple #2
0
 def create_normal(self, data, translations=None):
     obj = Normal(shared_field=data.shared_field)
     for code in translations or self.translations:
         obj.translate(code)
         obj.translated_field = data.translated_field[code]
         obj.save()
     return obj
Exemple #3
0
 def test_filtered_get(self):
     obj = Normal(shared_field='field_1')
     obj.translate('en')
     obj.translated_field = 'field_2'
     obj.save()
     qs = Normal.objects.language('en') | Normal.objects.language('de')
     found = qs.filter(shared_field='field_1').get(pk=obj.pk)
     self.assertEqual(found.pk, obj.pk)
Exemple #4
0
 def test_filtered_get(self):
     obj = Normal(shared_field='field_1')
     obj.translate('en')
     obj.translated_field = 'field_2'
     obj.save()
     qs = Normal.objects.language('en') | Normal.objects.language('de')
     found = qs.filter(shared_field='field_1').get(pk=obj.pk)
     self.assertEqual(found.pk, obj.pk)
Exemple #5
0
 def test_filtered_get(self):
     obj = Normal(shared_field="field_1")
     obj.translate("en")
     obj.translated_field = "field_2"
     obj.save()
     qs = Normal.objects.language("en") | Normal.objects.language("de")
     found = qs.filter(shared_field="field_1").get(pk=obj.pk)
     self.assertEqual(found.pk, obj.pk)
Exemple #6
0
 def test_create_instance_simple(self):
     obj = Normal(language_code='en')
     obj.shared_field = "shared"
     obj.translated_field = "English"
     obj.save()
     en = Normal.objects.language('en').get(pk=obj.pk)
     self.assertEqual(en.shared_field, "shared")
     self.assertEqual(en.translated_field, "English")
     self.assertEqual(en.language_code, "en")
Exemple #7
0
 def test_create_instance_simple(self):
     obj = Normal(language_code='en')
     obj.shared_field = "shared"
     obj.translated_field = "English"
     obj.save()
     en = Normal.objects.language('en').get(pk=obj.pk)
     self.assertEqual(en.shared_field, "shared")
     self.assertEqual(en.translated_field, "English")
     self.assertEqual(en.language_code, "en")
    def test_translated_new_object_can_be_pickled(self):
        normal = Normal(shared_field="Shared")
        normal.translate("en")
        normal.translated_field = "English"
        serialized_repr = pickle.dumps(normal)

        unpickled = pickle.loads(serialized_repr)
        self.assertEqual(normal.shared_field, unpickled.shared_field)
        self.assertEqual(normal.language_code, unpickled.language_code)
        self.assertEqual(normal.translated_field, unpickled.translated_field)
Exemple #9
0
    def test_translated_new_object_can_be_pickled(self):
        normal = Normal(shared_field="Shared")
        normal.translate("en")
        normal.translated_field = "English"
        serialized_repr = pickle.dumps(normal)

        unpickled = pickle.loads(serialized_repr)
        self.assertEqual(normal.shared_field, unpickled.shared_field)
        self.assertEqual(normal.language_code, unpickled.language_code)
        self.assertEqual(normal.translated_field, unpickled.translated_field)
Exemple #10
0
 def test_create_instance_simple_nolang(self):
     with LanguageOverride("en"):
         obj = Normal(language_code="en")
         obj.shared_field = "shared"
         obj.translated_field = "English"
         obj.save()
         en = Normal.objects.language("en").get(pk=obj.pk)
         self.assertEqual(en.shared_field, "shared")
         self.assertEqual(en.translated_field, "English")
         self.assertEqual(en.language_code, "en")