Ejemplo n.º 1
0
 def delete(self, lang=None):
     r"""
     Delete the translations of the `Context`\ 's `purview` in a language.
     """
     lang = _get_translate_language(lang)
     if lang != _get_default_language():
         _get_translations(self.query, lang).delete()
Ejemplo n.º 2
0
    def test_queryset_level_1_2_relation_with_lang(self):
        create_samples(continent_names=['europe', 'asia'],
                       country_names=['germany', 'south korea'],
                       city_names=['cologne', 'seoul'],
                       continent_fields=['name', 'denonym'],
                       country_fields=['name', 'denonym'],
                       city_fields=['name', 'denonym'],
                       langs=['de', 'tr'])

        lvl_1_2 = (
            'countries',
            'countries__cities',
        )

        continents = Continent.objects.all()
        hierarchy = _get_relations_hierarchy(*lvl_1_2)
        mapping, query = _get_purview(continents, hierarchy)

        self.assertQuerysetEqual(
            _get_translations(query, 'de').order_by('id'), [
                '<Translation: Europe: Europa>',
                '<Translation: European: Europäisch>',
                '<Translation: Germany: Deutschland>',
                '<Translation: German: Deutsche>',
                '<Translation: Cologne: Köln>',
                '<Translation: Cologner: Kölner>',
                '<Translation: Asia: Asien>',
                '<Translation: Asian: Asiatisch>',
                '<Translation: South Korea: Südkorea>',
                '<Translation: South Korean: Südkoreanisch>',
                '<Translation: Seoul: Seül>',
                '<Translation: Seouler: Seüler>',
            ])
Ejemplo n.º 3
0
    def test_instance_level_1_2_relation_with_lang(self):
        create_samples(continent_names=['europe'],
                       country_names=['germany'],
                       city_names=['cologne'],
                       continent_fields=['name', 'denonym'],
                       country_fields=['name', 'denonym'],
                       city_fields=['name', 'denonym'],
                       langs=['de', 'tr'])

        lvl_1_2 = (
            'countries',
            'countries__cities',
        )

        europe = Continent.objects.get(code='EU')
        hierarchy = _get_relations_hierarchy(*lvl_1_2)
        mapping, query = _get_purview(europe, hierarchy)

        self.assertQuerysetEqual(
            _get_translations(query, 'de').order_by('id'), [
                '<Translation: Europe: Europa>',
                '<Translation: European: Europäisch>',
                '<Translation: Germany: Deutschland>',
                '<Translation: German: Deutsche>',
                '<Translation: Cologne: Köln>',
                '<Translation: Cologner: Kölner>',
            ])
Ejemplo n.º 4
0
 def update(self, lang=None):
     r"""
     Update the translations of the `Context`\ 's `purview` in a language.
     """
     lang = _get_translate_language(lang)
     if lang != _get_default_language():
         query = models.Q()
         _translations = []
         for address, text in self._get_changed_fields():
             query |= models.Q(**address)
             _translations.append(
                 translations.models.Translation(
                     language=lang, text=text, **address
                 )
             )
         _get_translations(query, lang).delete()
         translations.models.Translation.objects.bulk_create(_translations)
Ejemplo n.º 5
0
 def read(self, lang=None):
     r"""
     Read the translations of the `Context`\ 's `purview` in a language.
     """
     lang = _get_translate_language(lang)
     if lang != _get_default_language():
         _translations = _get_translations(self.query, lang)
         for translation in _translations:
             ct_id = translation.content_type.id
             obj_id = translation.object_id
             field = translation.field
             text = translation.text
             obj = self.mapping[ct_id][obj_id]
             if field in type(obj)._get_translatable_fields_names():
                 setattr(obj, field, text)
     else:
         self.reset()
Ejemplo n.º 6
0
    def test_queryset_level_0_relation_with_lang(self):
        create_samples(continent_names=['europe', 'asia'],
                       country_names=['germany', 'south korea'],
                       city_names=['cologne', 'seoul'],
                       continent_fields=['name', 'denonym'],
                       country_fields=['name', 'denonym'],
                       city_fields=['name', 'denonym'],
                       langs=['de', 'tr'])

        continents = Continent.objects.all()
        hierarchy = _get_relations_hierarchy()
        mapping, query = _get_purview(continents, hierarchy)

        self.assertQuerysetEqual(
            _get_translations(query, 'de').order_by('id'), [
                '<Translation: Europe: Europa>',
                '<Translation: European: Europäisch>',
                '<Translation: Asia: Asien>',
                '<Translation: Asian: Asiatisch>',
            ])