-
-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1546 from wger-project/feature/sync-ingredients
Add sync method for ingredients
- Loading branch information
Showing
11 changed files
with
320 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
IMAGE_ENDPOINT = "ingredient-image" | ||
INGREDIENTS_ENDPOINT = "ingredient" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# This file is part of wger Workout Manager. | ||
# | ||
# wger Workout Manager is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# wger Workout Manager is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# 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.exercises.sync import ( | ||
handle_deleted_entries, | ||
sync_categories, | ||
sync_equipment, | ||
sync_exercises, | ||
sync_languages, | ||
sync_licenses, | ||
sync_muscles, | ||
) | ||
from wger.nutrition.sync import sync_ingredients | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
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"]})' | ||
) | ||
|
||
def handle(self, **options): | ||
remote_url = options['remote_url'] | ||
|
||
try: | ||
val = URLValidator() | ||
val(remote_url) | ||
self.remote_url = remote_url | ||
except ValidationError: | ||
raise CommandError('Please enter a valid URL') | ||
|
||
sync_ingredients(self.stdout.write, self.remote_url, self.style.SUCCESS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.