コード例 #1
0
ファイル: forms_inline.py プロジェクト: spectras/django-hvad
    def test_mixed_update_translations(self):
        instance = Normal.objects.language('en').get(pk=self.normal_id[1])
        Formset = translationformset_factory(Normal, extra=1, exclude=[])

        initial = Formset(instance=instance)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')
        data.set_formset_field(initial, 1, 'translated_field', 'updated_ja')
        data.set_formset_field(initial, 2, 'language_code', 'de')
        data.set_formset_field(initial, 2, 'translated_field', 'Deutsch')

        formset = Formset(data=data, instance=instance)
        self.assertTrue(formset.is_valid())
        formset.save()

        self.assertCountEqual(instance.translations.all_languages(),
                              ('ja', 'de'))

        obj = Normal.objects.language('ja').get(pk=instance.pk)
        self.assertEqual(obj.shared_field, NORMAL[1].shared_field)
        self.assertEqual(obj.translated_field, 'updated_ja')

        obj = Normal.objects.language('de').get(pk=instance.pk)
        self.assertEqual(obj.shared_field, NORMAL[1].shared_field)
        self.assertEqual(obj.translated_field, 'Deutsch')
コード例 #2
0
ファイル: forms_inline.py プロジェクト: Madec/django-hvad
    def test_create_translations(self):
        Formset = translationformset_factory(Normal, extra=1)

        initial = Formset(instance=self.object)
        data = FormData(initial)
        data.set_formset_field(initial, 2, 'language_code', 'de')
        data.set_formset_field(initial, 2, 'translated_field', 'translated_test_de')

        formset = Formset(data=data, instance=self.object)
        formset.save()

        obj = Normal.objects.language('de').get(pk=self.object.pk)
        self.assertEqual(obj.translated_field, 'translated_test_de')
        self.assertEqual(obj.translations.count(), 3)
コード例 #3
0
    def test_create_translations(self):
        instance = Normal.objects.untranslated().get(pk=self.normal_id[1])
        Formset = translationformset_factory(Normal, extra=1, exclude=[])

        initial = Formset(instance=instance)
        data = FormData(initial)
        data.set_formset_field(initial, 2, 'language_code', 'de')
        data.set_formset_field(initial, 2, 'translated_field', 'Deutsch')

        formset = Formset(data=data, instance=instance)
        formset.save()

        obj = Normal.objects.language('de').get(pk=instance.pk)
        self.assertEqual(obj.translated_field, 'Deutsch')
        self.assertEqual(obj.translations.count(), 3)
コード例 #4
0
ファイル: forms_inline.py プロジェクト: Madec/django-hvad
    def test_mixed_update_translations(self):
        Formset = translationformset_factory(Normal, extra=1)

        initial = Formset(instance=self.object)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')
        data.set_formset_field(initial, 1, 'translated_field', 'updated_fr')
        data.set_formset_field(initial, 2, 'language_code', 'de')
        data.set_formset_field(initial, 2, 'translated_field', 'translated_test_de')

        formset = Formset(data=data, instance=self.object)
        self.assertTrue(formset.is_valid())
        formset.save()

        self.assertCountEqual(self.object.get_available_languages(), ('fr', 'de'))

        obj = Normal.objects.language('fr').get(pk=self.object.pk)
        self.assertEqual(obj.shared_field, 'test')
        self.assertEqual(obj.translated_field, 'updated_fr')

        obj = Normal.objects.language('de').get(pk=self.object.pk)
        self.assertEqual(obj.shared_field, 'test')
        self.assertEqual(obj.translated_field, 'translated_test_de')
コード例 #5
0
ファイル: forms_inline.py プロジェクト: jqb/django-hvad
    def test_mixed_update_translations(self):
        instance = Normal.objects.language('en').get(pk=self.normal_id[1])
        Formset = translationformset_factory(Normal, extra=1)

        initial = Formset(instance=instance)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')
        data.set_formset_field(initial, 1, 'translated_field', 'updated_ja')
        data.set_formset_field(initial, 2, 'language_code', 'de')
        data.set_formset_field(initial, 2, 'translated_field', 'Deutsch')

        formset = Formset(data=data, instance=instance)
        self.assertTrue(formset.is_valid())
        formset.save()

        self.assertCountEqual(instance.get_available_languages(), ('ja', 'de'))

        obj = Normal.objects.language('ja').get(pk=instance.pk)
        self.assertEqual(obj.shared_field, NORMAL[1].shared_field)
        self.assertEqual(obj.translated_field, 'updated_ja')

        obj = Normal.objects.language('de').get(pk=instance.pk)
        self.assertEqual(obj.shared_field, NORMAL[1].shared_field)
        self.assertEqual(obj.translated_field, 'Deutsch')
コード例 #6
0
ファイル: forms_inline.py プロジェクト: Kunpors/dr.pors-
    def test_delete_translations(self):
        instance = Normal.objects.language('en').get(pk=self.normal_id[1])
        Formset = translationformset_factory(Normal, extra=1, exclude=[])

        # Delete one of the two translations
        initial = Formset(instance=instance)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')

        formset = Formset(data=data, instance=instance)
        self.assertTrue(formset.is_valid())
        formset.save()

        self.assertCountEqual(instance.get_available_languages(), ('ja', ))

        # Try to delete the other translation - should fail
        initial = Formset(instance=instance)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')

        formset = Formset(data=data, instance=instance)
        self.assertFalse(formset.is_valid())
コード例 #7
0
ファイル: forms_inline.py プロジェクト: Kunpors/dr.pors-
    def test_create_translations(self):
        instance = Normal.objects.untranslated().get(pk=self.normal_id[1])
        Formset = translationformset_factory(Normal, extra=1, exclude=[])

        initial = Formset(instance=instance)
        data = FormData(initial)
        data.set_formset_field(initial, 2, 'language_code', 'de')
        data.set_formset_field(initial, 2, 'translated_field', 'Deutsch')

        formset = Formset(data=data, instance=instance)
        formset.save()

        obj = Normal.objects.language('de').get(pk=instance.pk)
        self.assertEqual(obj.translated_field, 'Deutsch')
        self.assertEqual(obj.translations.count(), 3)
コード例 #8
0
ファイル: forms_inline.py プロジェクト: Madec/django-hvad
    def test_delete_translations(self):
        Formset = translationformset_factory(Normal, extra=1)

        # Delete one of the two translations
        initial = Formset(instance=self.object)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')

        formset = Formset(data=data, instance=self.object)
        self.assertTrue(formset.is_valid())
        formset.save()

        self.assertCountEqual(self.object.get_available_languages(), ('fr',))

        # Try to delete the other translation - should fail
        initial = Formset(instance=self.object)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')

        formset = Formset(data=data, instance=self.object)
        self.assertFalse(formset.is_valid())
コード例 #9
0
    def test_delete_translations(self):
        instance = Normal.objects.language('en').get(pk=self.normal_id[1])
        Formset = translationformset_factory(Normal, extra=1, exclude=[])

        # Delete one of the two translations
        initial = Formset(instance=instance)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')

        formset = Formset(data=data, instance=instance)
        self.assertTrue(formset.is_valid())
        formset.save()

        self.assertCountEqual(instance.get_available_languages(), ('ja',))

        # Try to delete the other translation - should fail
        initial = Formset(instance=instance)
        data = FormData(initial)
        data.set_formset_field(initial, 0, 'DELETE', 'DELETE')

        formset = Formset(data=data, instance=instance)
        self.assertFalse(formset.is_valid())