Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix parser translation field, add modified when new value is different from old value (for each language) #3418

Merged
merged 2 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ In preparation for HD Views developments (PR #3298)
- ApidaeTrekParser: round computed duration
- ApidaeTrekParser: fix attached pictures import


2.93.0 (2022-12-06)
-----------------------

Expand Down
3 changes: 3 additions & 0 deletions geotrek/common/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ def parse_translation_field(self, dst, src, val):
if old_value != val_default_language:
self.set_value(dst_field_lang, src, val_default_language)
modified = True
if new_value != old_value:
modified = True

return modified

def parse_field(self, row, dst, src, updated, non_field):
Expand Down
40 changes: 40 additions & 0 deletions geotrek/trekking/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,13 @@ class TestApidaeTrekParser(ApidaeTrekParser):
selection_id = 654321


class TestApidaeTrekSameValueDefaultLanguageDifferentTranslationParser(TestApidaeTrekParser):
def filter_description(self, src, val):
description = super().filter_description(src, val)
self.set_value('description_fr', src, "FOOBAR")
return description


@skipIf(settings.TREKKING_TOPOLOGY_ENABLED, 'Test without dynamic segmentation only')
class ApidaeTrekParserTests(TestCase):

Expand Down Expand Up @@ -782,6 +789,39 @@ def test_trek_is_imported(self, mocked_get):

self.assertEqual(Attachment.objects.count(), 0)

@mock.patch('requests.get')
def test_trek_import_multiple_time(self, mocked_get):
RouteFactory(route='Boucle')
mocked_get.side_effect = self.make_dummy_get('a_trek.json')

call_command('import', 'geotrek.trekking.tests.test_parsers.TestApidaeTrekParser', verbosity=0)

self.assertEqual(Trek.objects.count(), 1)
trek = Trek.objects.all().first()
old_description_en = trek.description_en
old_description = trek.description
description_fr = (
'<p>Départ : du parking de la Chapelle Saint Michel </p>'
'<p>1/ Suivre le chemin qui part à droite, traversant le vallon.</p>'
'<p>2/ Au carrefour tourner à droite et suivre la rivière</p>'
'<p>3/ Retour à la chapelle en passant à travers le petit bois.</p>'
'<p>Ouvert toute l\'année</p>'
'<p>Fermeture exceptionnelle en cas de pluie forte</p>'
'<p>Suivre le balisage GR (blanc/rouge) ou GRP (jaune/rouge).</p>'
'<p>Montée en télésiège payante. 2 points de vente - télésiège Frastaz et Bois Noir.</p>'
'<p><strong>Site web (URL):</strong>https://example.com/ma_rando.html<br>'
'<strong>Téléphone:</strong>01 23 45 67 89<br>'
'<strong>Mél:</strong>[email protected]<br>'
'<strong>Signaux de fumée:</strong>1 gros nuage suivi de 2 petits</p>'
)
self.assertEqual(trek.description_fr, description_fr)
call_command('import', 'geotrek.trekking.tests.test_parsers.TestApidaeTrekSameValueDefaultLanguageDifferentTranslationParser',
verbosity=0)
trek.refresh_from_db()
self.assertEqual(trek.description_fr, 'FOOBAR')
self.assertEqual(old_description_en, trek.description_en)
self.assertEqual(old_description, trek.description)

@mock.patch('requests.get')
def test_trek_geometry_can_be_imported_from_gpx(self, mocked_get):
mocked_get.side_effect = self.make_dummy_get('a_trek.json')
Expand Down