Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Allow passing of all languages at once for ingredient sync.

Cam Cecil1e792f1192ff
diff --git a/wger/nutrition/api/filtersets.py b/wger/nutrition/api/filtersets.py
index 601f6c8d9..c324a8251 100644
--- a/wger/nutrition/api/filtersets.py
+++ b/wger/nutrition/api/filtersets.py
@@ -40,7 +40,7 @@ class IngredientFilterSet(filters.FilterSet):
'created': ['exact', 'gt', 'lt'],
'last_update': ['exact', 'gt', 'lt'],
'last_imported': ['exact', 'gt', 'lt'],
- 'language': ['exact'],
+ 'language': ['exact', 'in'],
'license': ['exact'],
'license_author': ['exact'],
}
diff --git a/wger/nutrition/sync.py b/wger/nutrition/sync.py
index facfe7cd9..06663c22e 100644
--- a/wger/nutrition/sync.py
+++ b/wger/nutrition/sync.py
@@ -231,7 +231,7 @@ def sync_ingredients(
url = make_uri(
INGREDIENTS_ENDPOINT,
server_url=remote_url,
- query={'limit': API_MAX_ITEMS, 'language': language_id},
+ query={'limit': API_MAX_ITEMS, 'language__in': language_id},
)
else:
url = make_uri(
diff --git a/wger/nutrition/tests/test_sync.py b/wger/nutrition/tests/test_sync.py
index 96e94274a..7cfe3fdc7 100644
--- a/wger/nutrition/tests/test_sync.py
+++ b/wger/nutrition/tests/test_sync.py
@@ -101,9 +101,9 @@ class TestSyncMethods(WgerTestCase):
self.assertEqual(ingredient.code, '1234567890987654321')
# Act
- sync_ingredients(lambda x: x, language_codes='en')
+ sync_ingredients(lambda x: x)
mock_request.assert_called_with(
- 'https://wger.de/api/v2/ingredient/?limit=999&language=2',
+ 'https://wger.de/api/v2/ingredient/?limit=999',
headers=wger_headers(),
)
@@ -123,3 +123,12 @@ class TestSyncMethods(WgerTestCase):
self.assertEqual(new_ingredient.energy, 256)
self.assertAlmostEqual(new_ingredient.protein, Decimal(11), 2)
self.assertEqual(new_ingredient.code, '3181238941963')
+
+ @patch('requests.get', return_value=MockIngredientResponse())
+ def test_ingredient_sync_languages(self, mock_request):
+ # Ensure correct URL is called when language codes are provided
+ sync_ingredients(lambda x: x, language_codes='en')
+ mock_request.assert_called_with(
+ 'https://wger.de/api/v2/ingredient/?limit=999&language=2',
+ headers=wger_headers(),
+ )