From 13f15485db7332bfa8622dc2d7666512e2d3fa26 Mon Sep 17 00:00:00 2001 From: bbk Date: Tue, 15 Aug 2023 12:23:07 +0200 Subject: [PATCH 01/10] use env.REGISTRY_REPO for docker hub --- .github/workflows/docker-base.yml | 2 +- .github/workflows/docker-demo.yml | 2 +- .github/workflows/docker.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-base.yml b/.github/workflows/docker-base.yml index 70387f519..cfbd1f8dc 100644 --- a/.github/workflows/docker-base.yml +++ b/.github/workflows/docker-base.yml @@ -39,4 +39,4 @@ jobs: push: true file: extras/docker/base/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 - tags: wger/base:latest,wger/base:2.2-dev + tags: ${{ env.REGISTRY_REPO }}/base:latest,${{ env.REGISTRY_REPO }}/base:2.2-dev diff --git a/.github/workflows/docker-demo.yml b/.github/workflows/docker-demo.yml index 8d83a11f5..f3e6c9379 100644 --- a/.github/workflows/docker-demo.yml +++ b/.github/workflows/docker-demo.yml @@ -41,4 +41,4 @@ jobs: push: true file: extras/docker/demo/Dockerfile platforms: linux/amd64,linux/arm64 - tags: wger/demo:latest,wger/demo:2.2-dev,wger/apache:latest,wger/apache:2.2-dev + tags: ${{ env.REGISTRY_REPO }}/demo:latest,${{ env.REGISTRY_REPO }}/demo:2.2-dev,${{ env.REGISTRY_REPO }}/apache:latest,${{ env.REGISTRY_REPO }}/apache:2.2-dev diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index bc2bdd9a1..b1518542d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -8,8 +8,8 @@ on: - master env: - REGISTRY_IMAGE: wger/server - REGISTRY_IMAGE_ALT: wger/devel + REGISTRY_IMAGE: ${{ env.REGISTRY_REPO }}/server + REGISTRY_IMAGE_ALT: ${{ env.REGISTRY_REPO }}/devel jobs: build-prod: From f016659805b9198ac5d135e62c7fb0387e5ff2f7 Mon Sep 17 00:00:00 2001 From: bbk Date: Tue, 15 Aug 2023 12:31:54 +0200 Subject: [PATCH 02/10] it's $REGISTRY_REPO not $env.REGISTRY_REPO --- .github/workflows/docker-base.yml | 2 +- .github/workflows/docker-demo.yml | 2 +- .github/workflows/docker.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-base.yml b/.github/workflows/docker-base.yml index cfbd1f8dc..7701e68cf 100644 --- a/.github/workflows/docker-base.yml +++ b/.github/workflows/docker-base.yml @@ -39,4 +39,4 @@ jobs: push: true file: extras/docker/base/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 - tags: ${{ env.REGISTRY_REPO }}/base:latest,${{ env.REGISTRY_REPO }}/base:2.2-dev + tags: ${{ REGISTRY_REPO }}/base:latest,${{ REGISTRY_REPO }}/base:2.2-dev diff --git a/.github/workflows/docker-demo.yml b/.github/workflows/docker-demo.yml index f3e6c9379..40b7a7363 100644 --- a/.github/workflows/docker-demo.yml +++ b/.github/workflows/docker-demo.yml @@ -41,4 +41,4 @@ jobs: push: true file: extras/docker/demo/Dockerfile platforms: linux/amd64,linux/arm64 - tags: ${{ env.REGISTRY_REPO }}/demo:latest,${{ env.REGISTRY_REPO }}/demo:2.2-dev,${{ env.REGISTRY_REPO }}/apache:latest,${{ env.REGISTRY_REPO }}/apache:2.2-dev + tags: ${{ REGISTRY_REPO }}/demo:latest,${{ REGISTRY_REPO }}/demo:2.2-dev,${{ REGISTRY_REPO }}/apache:latest,${{ REGISTRY_REPO }}/apache:2.2-dev diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b1518542d..8bf79d99f 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -8,8 +8,8 @@ on: - master env: - REGISTRY_IMAGE: ${{ env.REGISTRY_REPO }}/server - REGISTRY_IMAGE_ALT: ${{ env.REGISTRY_REPO }}/devel + REGISTRY_IMAGE: ${{ REGISTRY_REPO }}/server + REGISTRY_IMAGE_ALT: ${{ REGISTRY_REPO }}/devel jobs: build-prod: From 24f7efc1354c36904bd23fb50b8853fbd7de2138 Mon Sep 17 00:00:00 2001 From: bbk Date: Tue, 15 Aug 2023 12:36:42 +0200 Subject: [PATCH 03/10] actually it seems to be `$vars.` --- .github/workflows/docker-base.yml | 2 +- .github/workflows/docker-demo.yml | 2 +- .github/workflows/docker.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-base.yml b/.github/workflows/docker-base.yml index 7701e68cf..b3142c791 100644 --- a/.github/workflows/docker-base.yml +++ b/.github/workflows/docker-base.yml @@ -39,4 +39,4 @@ jobs: push: true file: extras/docker/base/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 - tags: ${{ REGISTRY_REPO }}/base:latest,${{ REGISTRY_REPO }}/base:2.2-dev + tags: ${{ vars.REGISTRY_REPO }}/base:latest,${{ vars.REGISTRY_REPO }}/base:2.2-dev diff --git a/.github/workflows/docker-demo.yml b/.github/workflows/docker-demo.yml index 40b7a7363..4a4ae37f6 100644 --- a/.github/workflows/docker-demo.yml +++ b/.github/workflows/docker-demo.yml @@ -41,4 +41,4 @@ jobs: push: true file: extras/docker/demo/Dockerfile platforms: linux/amd64,linux/arm64 - tags: ${{ REGISTRY_REPO }}/demo:latest,${{ REGISTRY_REPO }}/demo:2.2-dev,${{ REGISTRY_REPO }}/apache:latest,${{ REGISTRY_REPO }}/apache:2.2-dev + tags: ${{ vars.REGISTRY_REPO }}/demo:latest,${{ vars.REGISTRY_REPO }}/demo:2.2-dev,${{ vars.REGISTRY_REPO }}/apache:latest,${{ vars.REGISTRY_REPO }}/apache:2.2-dev diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8bf79d99f..b1b94191d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -8,8 +8,8 @@ on: - master env: - REGISTRY_IMAGE: ${{ REGISTRY_REPO }}/server - REGISTRY_IMAGE_ALT: ${{ REGISTRY_REPO }}/devel + REGISTRY_IMAGE: ${{ vars.REGISTRY_REPO }}/server + REGISTRY_IMAGE_ALT: ${{ vars.REGISTRY_REPO }}/devel jobs: build-prod: From 7b9dd02ab773c300be34292cf7c7de6286dc2924 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 11:45:28 +0000 Subject: [PATCH 04/10] Bump yarn from 1.22.19 to 1.22.21 Bumps [yarn](https://github.com/yarnpkg/yarn) from 1.22.19 to 1.22.21. - [Release notes](https://github.com/yarnpkg/yarn/releases) - [Changelog](https://github.com/yarnpkg/yarn/blob/master/CHANGELOG.md) - [Commits](https://github.com/yarnpkg/yarn/compare/v1.22.19...v1.22.21) --- updated-dependencies: - dependency-name: yarn dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 5370bee02..aa1dc22b0 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "masonry-layout": "^4.2.2", "popper.js": "^1.16.1", "shariff": "^3.3.0", - "yarn": "^1.22.19" + "yarn": "^1.22.21" }, "scripts": { "build:css:sass": "sass wger/core/static/scss/main.scss:wger/core/static/yarn/bootstrap-compiled.css" diff --git a/yarn.lock b/yarn.lock index 06b4b8c16..0f0c587f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -381,7 +381,7 @@ shariff@^3.3.0: "@fortawesome/fontawesome-free" "^5.8.2" jquery "^3.4.1" -yarn@^1.22.19: - version "1.22.19" - resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.19.tgz#4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447" - integrity sha512-/0V5q0WbslqnwP91tirOvldvYISzaqhClxzyUKXYxs07yUILIs5jx/k6CFe8bvKSkds5w+eiOqta39Wk3WxdcQ== +yarn@^1.22.21: + version "1.22.21" + resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.21.tgz#1959a18351b811cdeedbd484a8f86c3cc3bbaf72" + integrity sha512-ynXaJsADJ9JiZ84zU25XkPGOvVMmZ5b7tmTSpKURYwgELdjucAOydqIOrOfTxVYcNXe91xvLZwcRh68SR3liCg== From fcafbf5606e03b6b042e31482d85986c2b41ddae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Nov 2023 23:55:53 +0000 Subject: [PATCH 05/10] Bump wheel from 0.41.3 to 0.42.0 Bumps [wheel](https://github.com/pypa/wheel) from 0.41.3 to 0.42.0. - [Release notes](https://github.com/pypa/wheel/releases) - [Changelog](https://github.com/pypa/wheel/blob/main/docs/news.rst) - [Commits](https://github.com/pypa/wheel/compare/0.41.3...0.42.0) --- updated-dependencies: - dependency-name: wheel dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index aa7286fd8..d4ee30522 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -6,7 +6,7 @@ -r requirements.txt # Building/installing -wheel==0.41.3 +wheel==0.42.0 # for ingredient import script from OFF pymongo==4.6.0 From 80452ddfb864a5be0084acd801603c40c2f055a5 Mon Sep 17 00:00:00 2001 From: yoyomax80400 Date: Thu, 30 Nov 2023 12:43:14 +0000 Subject: [PATCH 06/10] Translated using Weblate (French) Currently translated at 93.1% (721 of 774 strings) Translation: wger Workout Manager/Web App Translate-URL: https://hosted.weblate.org/projects/wger/web/fr/ --- wger/locale/fr/LC_MESSAGES/django.po | 109 +++++++++------------------ 1 file changed, 36 insertions(+), 73 deletions(-) diff --git a/wger/locale/fr/LC_MESSAGES/django.po b/wger/locale/fr/LC_MESSAGES/django.po index 0e00f7bf0..9fd3714aa 100644 --- a/wger/locale/fr/LC_MESSAGES/django.po +++ b/wger/locale/fr/LC_MESSAGES/django.po @@ -22,15 +22,15 @@ msgstr "" "Project-Id-Version: wger Workout Manager\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-06-06 11:42+0200\n" -"PO-Revision-Date: 2023-05-30 17:48+0000\n" -"Last-Translator: Célian \n" +"PO-Revision-Date: 2023-12-01 13:05+0000\n" +"Last-Translator: yoyomax80400 \n" "Language-Team: French \n" "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 4.18-dev\n" +"X-Generator: Weblate 5.3-dev\n" #: config/models/gym_config.py:46 gym/templates/gym/list.html:53 msgid "Default gym" @@ -503,12 +503,7 @@ msgid "Something happened that caused an error." msgstr "Quelque-chose s'est passé et a causé un erreur." #: core/templates/base.html:12 core/templates/base_wide.html:10 -#, fuzzy, python-format -#| msgid "" -#| "You are\n" -#| " browsing the site as the user \"%(current_user)s\", all actions are " -#| "performed on their data.\n" -#| " " +#, python-format msgid "" "You are\n" " browsing the site as the user \"%(current_user)s\", all " @@ -516,9 +511,9 @@ msgid "" " " msgstr "" "Vous êtes\n" -" en train de naviguer sur le site en tant qu’utilisateur « " -"%(current_user)s », toutes les actions sont effectuées sur ses données.\n" -" " +" en train de naviguer sur le site en tant qu’utilisateur « %(current_user)" +"s », toutes les actions sont effectuées sur ses données.\n" +" " #: core/templates/base.html:16 core/templates/base_wide.html:14 #, python-format @@ -1075,11 +1070,11 @@ msgstr "L’équipe de %(site_name)s" #: core/templates/rest_framework/api.html:37 msgid "request info" -msgstr "" +msgstr "Demande d'info" #: core/templates/rest_framework/api.html:41 msgid "response info" -msgstr "" +msgstr "informations sur la réponse" #: core/templates/tags/pagination.html:7 core/templates/tags/pagination.html:11 msgid "previous" @@ -2157,7 +2152,7 @@ msgstr "Mollets" #: i18n.tpl:10 msgid "Cardio" -msgstr "" +msgstr "Cardio" #: i18n.tpl:11 msgid "Chest" @@ -2192,10 +2187,8 @@ msgid "Kilometers" msgstr "kilomètres" #: i18n.tpl:19 -#, fuzzy -#| msgid "Kilometers" msgid "Kilometers Per Hour" -msgstr "kilomètres" +msgstr "Kilomètres par heure" #: i18n.tpl:20 msgid "Lats" @@ -2215,7 +2208,7 @@ msgstr "Miles" #: i18n.tpl:24 msgid "Miles Per Hour" -msgstr "" +msgstr "Miles par heure\"" #: i18n.tpl:25 msgid "Minutes" @@ -2223,7 +2216,7 @@ msgstr "Minutes" #: i18n.tpl:26 msgid "Plates" -msgstr "" +msgstr "Plaques" #: i18n.tpl:27 msgid "Pull-up bar" @@ -2341,10 +2334,8 @@ msgstr "" "ensemble." #: manager/forms.py:143 nutrition/forms.py:248 -#, fuzzy -#| msgid "Also use ingredients in English" msgid "Also search for names in English" -msgstr "Afficher les ingrédients en anglais" +msgstr "Recherchez également des noms en anglais" #: manager/forms.py:171 manager/forms.py:176 manager/models/log.py:64 #: manager/models/log.py:92 manager/models/setting.py:59 @@ -2612,12 +2603,6 @@ msgstr "" "les uns après les autres." #: manager/templates/schedule/overview.html:39 -#, fuzzy -#| msgid "" -#| "You can indicate how long you want to do each workout\n" -#| "before jumping to the next. It is also possible to create a loop, so you\n" -#| "always do the same workouts in succession, e.g. A > B > C > A > B > C and " -#| "so on." msgid "" "You can indicate how long you want to do each workout\n" " before jumping to the next. It is also possible to create a loop, so " @@ -2679,13 +2664,7 @@ msgid "Start schedule" msgstr "Démarrer le programme" #: manager/templates/schedule/view.html:188 -#, fuzzy, python-format -#| msgid "" -#| "%(weeks)s Week\n" -#| " " -#| msgid_plural "" -#| "%(weeks)s Weeks\n" -#| " " +#, python-format msgid "" "%(weeks)s Week\n" " " @@ -2694,10 +2673,10 @@ msgid_plural "" " " msgstr[0] "" "%(weeks)s semaine\n" -" " +" " msgstr[1] "" "%(weeks)s semaines\n" -" " +" " #: manager/templates/schedule/view.html:222 msgid "Adding workouts" @@ -3010,16 +2989,12 @@ msgid "Height (in)" msgstr "Taille (cm)" #: nutrition/forms.py:117 -#, fuzzy -#| msgid "Weight log" msgid "Weight (kg)" -msgstr "Journal de pesée" +msgstr "\"Poids (kg)\"" #: nutrition/forms.py:118 -#, fuzzy -#| msgid "Weight log" msgid "Weight (lbs)" -msgstr "Journal de pesée" +msgstr "Poids (lbs)" #: nutrition/forms.py:129 msgid "Calculate" @@ -3592,15 +3567,15 @@ msgstr "" #: nutrition/views/bmi.py:89 msgid "Please make sure your height is within the appropriate range." -msgstr "" +msgstr "Veuillez vous assurer que votre taille est dans la plage appropriée." #: nutrition/views/bmi.py:92 msgid "140 to 230" -msgstr "" +msgstr "140 à 230" #: nutrition/views/bmi.py:94 msgid "56 to 90" -msgstr "" +msgstr "56 à 90" #: nutrition/views/ingredient.py:165 msgid "Add a new ingredient" @@ -3704,33 +3679,23 @@ msgid "Our goal" msgstr "Notre objectif" #: software/templates/about_us.html:53 -#, fuzzy -#| msgid "" -#| "The goal is to build an awesome\n" -#| "and flexible fitness manager, along with a comprehensive and complete " -#| "list of exercises and\n" -#| "ingredients, all released under a free license." msgid "" "The goal is to build an awesome\n" " and flexible fitness manager, along with a comprehensive and " "complete list of exercises and\n" " ingredients, all released under a free license." msgstr "" -"Le but est de construire un entraîneur de conditionnement physique " -"impressionnant et flexible, ainsi qu’une liste exhaustive et complète " -"d’exercices et d’ingrédients, tous publiés sous une licence libre." +"L'objectif est de créer un gestionnaire de fitness impressionnant et " +"flexible, ainsi qu’une liste exhaustive et complète d’exercices et d’" +"ingrédients, le tous publiés sous une licence libre." #: software/templates/features.html:11 -#, fuzzy -#| msgid "" -#| "wger Workout Manager is a free, open source web application that manages " -#| "your exercises and workouts. " msgid "" "wger Workout Manager is a free, open source web application that manages " "your exercises and workouts." msgstr "" -"wger Workout Manager est une application web open source gratuit qui gère " -"vos exercices et séances d’entraînement. " +"Le gestionnaire d'entraînement wger est une application web gratuite et open " +"source qui gère vos exercices et entraînements" #: software/templates/features.html:45 msgid "About" @@ -3738,40 +3703,38 @@ msgstr "À propos" #: software/templates/features.html:50 msgid "Mobile app" -msgstr "" +msgstr "Application mobile" #: software/templates/features.html:56 software/templates/features.html:312 msgid "Donate" -msgstr "" +msgstr "Faire un don" #: software/templates/features.html:61 msgid "Develop" -msgstr "" +msgstr "Développer" #: software/templates/features.html:66 software/templates/features.html:448 -#, fuzzy -#| msgid "Comment" msgid "Community" -msgstr "Commentaire" +msgstr "Communauté" #: software/templates/features.html:100 msgid "Track your
way to your
ideal body" -msgstr "" +msgstr "Suivez votre
progressions vers votre
corps idéal" #: software/templates/features.html:103 msgid "" "Join wger, the community-driven free and open-source fitness tracker" msgstr "" +"Rejoignez wger, le tracker de fitness gratuit et open source piloté " +"par la communauté" #: software/templates/features.html:113 -#, fuzzy -#| msgid "Get the code" msgid "Get Started" -msgstr "Récupérer le code" +msgstr "Commencer" #: software/templates/features.html:123 msgid "people
using wger" -msgstr "" +msgstr "Personnes
utilisant wger" #: software/templates/features.html:127 #, fuzzy From af30c2a1c6d3ee647af1d6b5de0c0edb42a6f992 Mon Sep 17 00:00:00 2001 From: bbkz Date: Sat, 2 Dec 2023 12:02:38 +0100 Subject: [PATCH 07/10] EMAIL_USE_TLS or EMAIL_USE_SSL EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True. --- extras/docker/development/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/docker/development/settings.py b/extras/docker/development/settings.py index 8ef55f014..9dc67df4f 100644 --- a/extras/docker/development/settings.py +++ b/extras/docker/development/settings.py @@ -79,7 +79,7 @@ EMAIL_HOST_USER = env.str("EMAIL_HOST_USER") EMAIL_HOST_PASSWORD = env.str("EMAIL_HOST_PASSWORD") EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True) - EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", True) + EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", False) EMAIL_TIMEOUT = 60 # Sender address used for sent emails From 7ae943b7bcfd570f8f51d0cf4e2070ebb544f885 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 23:45:15 +0000 Subject: [PATCH 08/10] Bump djangorestframework-simplejwt[crypto] from 5.3.0 to 5.3.1 Bumps [djangorestframework-simplejwt[crypto]](https://github.com/jazzband/djangorestframework-simplejwt) from 5.3.0 to 5.3.1. - [Release notes](https://github.com/jazzband/djangorestframework-simplejwt/releases) - [Changelog](https://github.com/jazzband/djangorestframework-simplejwt/blob/master/CHANGELOG.md) - [Commits](https://github.com/jazzband/djangorestframework-simplejwt/compare/v5.3.0...v5.3.1) --- updated-dependencies: - dependency-name: djangorestframework-simplejwt[crypto] dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b18c330a1..fe79a1116 100644 --- a/requirements.txt +++ b/requirements.txt @@ -43,7 +43,7 @@ flower==2.0.1 django-cors-headers==4.3.1 django-filter==23.4 djangorestframework~=3.14 -djangorestframework-simplejwt[crypto]==5.3.0 +djangorestframework-simplejwt[crypto]==5.3.1 # Not used anymore, but needed because some modules are imported in DB migration # files From 53a8de561e3bb9fb8583cb060d24076a3f4b0511 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sun, 26 Nov 2023 18:11:23 +0100 Subject: [PATCH 09/10] Bump minimum required app version --- wger/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wger/__init__.py b/wger/__init__.py index 08c3ecaa6..bd6b7bab1 100644 --- a/wger/__init__.py +++ b/wger/__init__.py @@ -7,8 +7,7 @@ # Local from .celery_configuration import app - -MIN_APP_VERSION = (1, 5, 6, 'final', 1) +MIN_APP_VERSION = (1, 6, 0, 'final', 1) VERSION = (2, 2, 0, 'alpha', 4) RELEASE = True From e81e99ed0ab5a44dd2ed5c39047eedbad56d2dfb Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 27 Nov 2023 20:22:03 +0100 Subject: [PATCH 10/10] Use a dataclass to save ingredient information --- .../commands/import-off-products.py | 25 +++--- wger/nutrition/models/ingredient.py | 7 +- wger/nutrition/off.py | 80 +++++++++++++------ wger/nutrition/tests/test_off.py | 64 +++++++++------ 4 files changed, 112 insertions(+), 64 deletions(-) diff --git a/wger/nutrition/management/commands/import-off-products.py b/wger/nutrition/management/commands/import-off-products.py index bc263a830..e9475d37b 100644 --- a/wger/nutrition/management/commands/import-off-products.py +++ b/wger/nutrition/management/commands/import-off-products.py @@ -25,7 +25,6 @@ from wger.nutrition.models import Ingredient from wger.nutrition.off import extract_info_from_off - logger = logging.getLogger(__name__) @@ -57,8 +56,8 @@ def add_arguments(self, parser): dest='mode', type=str, help='Script mode, "insert" or "update". Insert will insert the ingredients as new ' - 'entries in the database, while update will try to update them if they are ' - 'already present. Deault: insert' + 'entries in the database, while update will try to update them if they are ' + 'already present. Deault: insert' ) parser.add_argument( '--completeness', @@ -67,7 +66,7 @@ def add_arguments(self, parser): dest='completeness', type=float, help='Completeness threshold for importing the products. Products in OFF have ' - 'completeness score that ranges from 0 to 1.1. Default: 0.7' + 'completeness score that ranges from 0 to 1.1. Default: 0.7' ) def handle(self, **options): @@ -115,17 +114,24 @@ def handle(self, **options): ingredient_data = extract_info_from_off(product, languages[product['lang']]) except KeyError as e: # self.stdout.write(f'--> KeyError while extracting info from OFF: {e}') + # self.stdout.write( + # '***********************************************************************************************') + # self.stdout.write( + # '***********************************************************************************************') + # self.stdout.write( + # '***********************************************************************************************') + # pprint(product) # self.stdout.write(f'--> Product: {product}') counter['skipped'] += 1 continue # Some products have no name or name is too long, skipping - if not ingredient_data['name']: + if not ingredient_data.name: # self.stdout.write('--> Ingredient has no name field') counter['skipped'] += 1 continue - if not ingredient_data['common_name']: + if not ingredient_data.common_name: # self.stdout.write('--> Ingredient has no common name field') counter['skipped'] += 1 continue @@ -133,7 +139,7 @@ def handle(self, **options): # # Add entries as new products if self.mode == Mode.INSERT: - bulk_update_bucket.append(Ingredient(**ingredient_data)) + bulk_update_bucket.append(Ingredient(**ingredient_data.dict())) if len(bulk_update_bucket) > self.bulk_size: try: Ingredient.objects.bulk_create(bulk_update_bucket) @@ -165,7 +171,8 @@ def handle(self, **options): # one. While this might not be the most efficient query (there will always # be a SELECT first), it's ok because this script is run very rarely. obj, created = Ingredient.objects.update_or_create( - code=ingredient_data['code'], defaults=ingredient_data + code=ingredient_data.code, + defaults=ingredient_data.dict(), ) if created: @@ -177,7 +184,7 @@ def handle(self, **options): except Exception as e: self.stdout.write('--> Error while performing update_or_create') - self.stdout.write(e) + self.stdout.write(str(e)) counter['error'] += 1 continue diff --git a/wger/nutrition/models/ingredient.py b/wger/nutrition/models/ingredient.py index 36b312140..c84523b14 100644 --- a/wger/nutrition/models/ingredient.py +++ b/wger/nutrition/models/ingredient.py @@ -65,7 +65,6 @@ # Local from .ingredient_category import IngredientCategory - logger = logging.getLogger(__name__) @@ -481,13 +480,13 @@ def fetch_ingredient_from_off(cls, code: str): except KeyError: return None - if not ingredient_data['name']: + if not ingredient_data.name: return - if not ingredient_data['common_name']: + if not ingredient_data.common_name: return - ingredient = cls(**ingredient_data) + ingredient = cls(**ingredient_data.dict()) ingredient.save() logger.info(f'Ingredient found and saved to local database: {ingredient.uuid}') return ingredient diff --git a/wger/nutrition/off.py b/wger/nutrition/off.py index c033935bc..df713f974 100644 --- a/wger/nutrition/off.py +++ b/wger/nutrition/off.py @@ -13,13 +13,15 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from dataclasses import dataclass, asdict +from typing import Optional + # wger from wger.nutrition.consts import KJ_PER_KCAL from wger.nutrition.models import Source from wger.utils.constants import ODBL_LICENSE_ID from wger.utils.models import AbstractSubmissionModel - OFF_REQUIRED_TOP_LEVEL = [ 'product_name', 'code', @@ -28,12 +30,38 @@ OFF_REQUIRED_NUTRIMENTS = [ 'proteins_100g', 'carbohydrates_100g', - 'sugars_100g', 'fat_100g', 'saturated-fat_100g', ] +@dataclass +class IngredientData: + name: str + language_id: int + energy: float + protein: float + carbohydrates: float + carbohydrates_sugar: float + fat: float + fat_saturated: float + fibres: Optional[float] + sodium: Optional[float] + code: str + source_name: str + source_url: str + common_name: str + brand: str + status: str + license_id: int + license_author: str + license_title: str + license_object_url: str + + def dict(self): + return asdict(self) + + def extract_info_from_off(product_data, language: int): if not all(req in product_data for req in OFF_REQUIRED_TOP_LEVEL): raise KeyError('Missing required top-level key') @@ -63,9 +91,9 @@ def extract_info_from_off(product_data, language: int): code = product_data['code'] protein = product_data['nutriments']['proteins_100g'] carbs = product_data['nutriments']['carbohydrates_100g'] - sugars = product_data['nutriments']['sugars_100g'] + sugars = product_data['nutriments'].get('sugars_100g', 0) fat = product_data['nutriments']['fat_100g'] - saturated = product_data['nutriments']['saturated-fat_100g'] + saturated = product_data['nutriments'].get('saturated-fat_100g', 0) # these are optional sodium = product_data['nutriments'].get('sodium_100g', None) @@ -78,25 +106,25 @@ def extract_info_from_off(product_data, language: int): authors = ', '.join(product_data.get('editors_tags', ['open food facts'])) object_url = f'https://world.openfoodfacts.org/product/{code}/' - return { - 'name': name, - 'language_id': language, - 'energy': energy, - 'protein': protein, - 'carbohydrates': carbs, - 'carbohydrates_sugar': sugars, - 'fat': fat, - 'fat_saturated': saturated, - 'fibres': fibre, - 'sodium': sodium, - 'code': code, - 'source_name': source_name, - 'source_url': source_url, - 'common_name': common_name, - 'brand': brand, - 'status': AbstractSubmissionModel.STATUS_ACCEPTED, - 'license_id': ODBL_LICENSE_ID, - 'license_author': authors, - 'license_title': name, - 'license_object_url': object_url - } + return IngredientData( + name=name, + language_id=language, + energy=energy, + protein=protein, + carbohydrates=carbs, + carbohydrates_sugar=sugars, + fat=fat, + fat_saturated=saturated, + fibres=fibre, + sodium=sodium, + code=code, + source_name=source_name, + source_url=source_url, + common_name=common_name, + brand=brand, + status=AbstractSubmissionModel.STATUS_ACCEPTED, + license_id=ODBL_LICENSE_ID, + license_author=authors, + license_title=name, + license_object_url=object_url + ) diff --git a/wger/nutrition/tests/test_off.py b/wger/nutrition/tests/test_off.py index 07532df99..314511724 100644 --- a/wger/nutrition/tests/test_off.py +++ b/wger/nutrition/tests/test_off.py @@ -17,7 +17,10 @@ from django.test import SimpleTestCase # wger -from wger.nutrition.off import extract_info_from_off +from wger.nutrition.off import ( + extract_info_from_off, + IngredientData +) from wger.utils.constants import ODBL_LICENSE_ID from wger.utils.models import AbstractSubmissionModel @@ -54,30 +57,30 @@ def test_regular_response(self): Test that the function can read the regular case """ result = extract_info_from_off(self.off_data1, 1) - test = { - 'name': 'Foo with chocolate', - 'language_id': 1, - 'energy': 120, - 'protein': 10, - 'carbohydrates': 20, - 'carbohydrates_sugar': 30, - 'fat': 40, - 'fat_saturated': 11, - 'fibres': None, - 'sodium': 5, - 'code': '1234', - 'source_name': 'Open Food Facts', - 'source_url': 'https://world.openfoodfacts.org/api/v2/product/1234.json', - 'common_name': 'Foo with chocolate, 250g package', - 'brand': 'The bar company', - 'status': AbstractSubmissionModel.STATUS_ACCEPTED, - 'license_id': ODBL_LICENSE_ID, - 'license_author': 'open food facts, MrX', - 'license_title': 'Foo with chocolate', - 'license_object_url': 'https://world.openfoodfacts.org/product/1234/' - } + data = IngredientData( + name='Foo with chocolate', + language_id=1, + energy=120, + protein=10, + carbohydrates=20, + carbohydrates_sugar=30, + fat=40, + fat_saturated=11, + fibres=None, + sodium=5, + code='1234', + source_name='Open Food Facts', + source_url='https://world.openfoodfacts.org/api/v2/product/1234.json', + common_name='Foo with chocolate, 250g package', + brand='The bar company', + status=AbstractSubmissionModel.STATUS_ACCEPTED, + license_id=ODBL_LICENSE_ID, + license_author='open food facts, MrX', + license_title='Foo with chocolate', + license_object_url='https://world.openfoodfacts.org/product/1234/' + ) - self.assertDictEqual(result, test) + self.assertEqual(result, data) def test_convert_kj(self): """ @@ -90,7 +93,7 @@ def test_convert_kj(self): result = extract_info_from_off(self.off_data1, 1) # 120 / KJ_PER_KCAL - self.assertAlmostEqual(result['energy'], 28.6806, 3) + self.assertAlmostEqual(result.energy, 28.6806, 3) def test_no_energy(self): """ @@ -99,3 +102,14 @@ def test_no_energy(self): del self.off_data1['nutriments']['energy-kcal_100g'] self.assertRaises(KeyError, extract_info_from_off, self.off_data1, 1) + + def test_no_sugar_or_saturated_fat(self): + """ + No sugar or saturated fat available + """ + del self.off_data1['nutriments']['sugars_100g'] + del self.off_data1['nutriments']['saturated-fat_100g'] + result = extract_info_from_off(self.off_data1, 1) + + self.assertEqual(result.carbohydrates_sugar, 0) + self.assertEqual(result.fat_saturated, 0)