Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Merge branch 'master' into feature/flexible-routines

Roland Geider215bea5ad7e0
diff --cc wger/exercises/management/commands/read-exercise-cleanup.py
index 770b1e874,25c11adca..42305ad28
--- a/wger/exercises/management/commands/read-exercise-cleanup.py
+++ b/wger/exercises/management/commands/read-exercise-cleanup.py
@@@ -30,12 -30,12 +30,12 @@@ from wger.exercises.models import
Alias,
Equipment,
Exercise,
- ExerciseBase,
ExerciseCategory,
ExerciseVideo,
+ Translation,
Variation,
)
- from wger.utils.constants import CC_BY_SA_4_ID
+ from wger.utils.constants import CC_BY_SA_4_LICENSE_ID
UUID_NEW = 'NEW'
diff --cc wger/exercises/tests/test_exercise.py
index 265fd8ed4,64f9caf4d..693f7531d
--- a/wger/exercises/tests/test_exercise.py
+++ b/wger/exercises/tests/test_exercise.py
@@@ -24,14 -24,14 +24,14 @@@ from wger.core.tests.base_testcase impo
from wger.exercises.models import (
DeletionLog,
Exercise,
- ExerciseBase,
+ Translation,
)
- from wger.utils.constants import CC_BY_SA_4_ID
+ from wger.utils.constants import CC_BY_SA_4_LICENSE_ID
-class ExerciseBaseTestCase(WgerTestCase):
+class ExerciseTestCase(WgerTestCase):
"""
- Test the different features of an exercise and its base
+ Test the different features of an exercise
"""
@staticmethod
@@@ -152,5 -152,5 +152,5 @@@ class ExerciseCustomApiTestCase(Exercis
response = self.client.post(self.url, data=self.data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- exercise = ExerciseBase.objects.get(pk=self.pk)
+ exercise = Exercise.objects.get(pk=self.pk)
- self.assertEqual(exercise.license_id, CC_BY_SA_4_ID)
+ self.assertEqual(exercise.license_id, CC_BY_SA_4_LICENSE_ID)
diff --cc wger/exercises/tests/test_exercise_translation.py
index 6a509050c,3c3b4aaf1..b5f412962
--- a/wger/exercises/tests/test_exercise_translation.py
+++ b/wger/exercises/tests/test_exercise_translation.py
@@@ -28,9 -36,9 +28,9 @@@ from wger.core.tests.base_testcase impo
from wger.exercises.models import (
Exercise,
Muscle,
+ Translation,
)
- from wger.utils.constants import CC_BY_SA_4_ID
-from wger.utils.cache import cache_mapper
+ from wger.utils.constants import CC_BY_SA_4_LICENSE_ID
class ExerciseRepresentationTestCase(WgerTestCase):
@@@ -223,8 -369,8 +223,8 @@@ class ExerciseTranslationCustomApiTestC
response = self.client.post(self.url, data=self.data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- exercise = Exercise.objects.get(pk=self.pk)
- self.assertEqual(exercise.license_id, CC_BY_SA_4_LICENSE_ID)
+ translation = Translation.objects.get(pk=self.pk)
- self.assertEqual(translation.license_id, CC_BY_SA_4_ID)
++ self.assertEqual(translation.license_id, CC_BY_SA_4_LICENSE_ID)
def test_patch_clean_html(self):
"""
diff --cc wger/nutrition/management/commands/sync-ingredients.py
index 58f0f0f14,08bc6371c..4b455191c
--- a/wger/nutrition/management/commands/sync-ingredients.py
+++ b/wger/nutrition/management/commands/sync-ingredients.py
@@@ -12,23 -12,63 +12,55 @@@
#
# You should have received a copy of the GNU Affero General Public License
+ # Django
+ from django.conf import settings
+ from django.core.exceptions import ValidationError
+ from django.core.management.base import (
+ BaseCommand,
+ CommandError,
+ )
+ from django.core.validators import URLValidator
+
# wger
+from wger.core.api.min_server_version import check_min_server_version
+from wger.core.management.wger_command import WgerCommand
from wger.nutrition.sync import sync_ingredients
+ from wger.utils.validators import validate_language_code
-class Command(BaseCommand):
+class Command(WgerCommand):
"""
Synchronizes ingredient data from a wger instance to the local database
"""
- remote_url = settings.WGER_SETTINGS['WGER_INSTANCE']
-
help = """Synchronizes ingredient data from a wger instance to the local database"""
+ def add_arguments(self, parser):
- parser.add_argument(
- '--remote-url',
- action='store',
- dest='remote_url',
- default=settings.WGER_SETTINGS['WGER_INSTANCE'],
- help=f'Remote URL to fetch the ingredients from (default: WGER_SETTINGS'
- f'["WGER_INSTANCE"] - {settings.WGER_SETTINGS["WGER_INSTANCE"]})',
- )
++ super().add_arguments(parser)
++
+ parser.add_argument(
+ '-l',
+ '--languages',
+ action='store',
+ dest='languages',
+ default=None,
+ help='Specify a comma-separated subset of languages to sync. Example: en,fr,es',
+ )
+
def handle(self, **options):
+ super().handle(**options)
+
remote_url = options['remote_url']
+ languages = options['languages']
+
- try:
- val = URLValidator()
- val(remote_url)
- self.remote_url = remote_url
- except ValidationError:
- raise CommandError('Please enter a valid URL')
+ check_min_server_version(remote_url)
+ try:
+ self.languages = languages
+ if self.languages is not None:
+ for language in self.languages.split(','):
+ validate_language_code(language)
+ except ValidationError as e:
+ raise CommandError('\n'.join([str(arg) for arg in e.args if arg is not None]))
+
+
- sync_ingredients(self.stdout.write, self.remote_url, self.style.SUCCESS)
+ sync_ingredients(self.stdout.write, self.remote_url, self.languages, self.style.SUCCESS)
diff --cc wger/settings_global.py
index 0deb93c0a,a1b696c61..a9f0773af
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@@ -538,11 -537,11 +537,12 @@@ WGER_SETTINGS =
'ALLOW_GUEST_USERS': True,
'ALLOW_REGISTRATION': True,
'ALLOW_UPLOAD_VIDEOS': False,
- 'DOWNLOAD_INGREDIENTS_FROM': DOWNLOAD_INGREDIENT_WGER,
'EMAIL_FROM': 'wger Workout Manager <[email protected]>',
'EXERCISE_CACHE_TTL': 3600,
+ 'DOWNLOAD_INGREDIENTS_FROM': DOWNLOAD_INGREDIENT_WGER,
'INGREDIENT_CACHE_TTL': 604800, # one week
+ 'INGREDIENT_IMAGE_CHECK_INTERVAL': datetime.timedelta(weeks=12),
+ 'ROUTINE_CACHE_TTL': 4 * 604800, # one month
'MIN_ACCOUNT_AGE_TO_TRUST': 21,
'SYNC_EXERCISES_CELERY': False,
'SYNC_EXERCISE_IMAGES_CELERY': False,