Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add fixtures for gym and associated configurations
Roland Geider5594e8169b65
diff --git a/wger/gym/fixtures/gym-config.json b/wger/gym/fixtures/gym-config.jsonnew file mode 100644index 000000000..bb1697d05--- /dev/null+++ b/wger/gym/fixtures/gym-config.json@@ -0,0 +1,10 @@+[+ {+ "pk": 1,+ "model": "gym.gymconfig",+ "fields": {+ "gym": 1,+ "weeks_inactive": 8+ }+ }+]diff --git a/wger/gym/fixtures/gym.json b/wger/gym/fixtures/gym.jsonnew file mode 100644index 000000000..b430be8ba--- /dev/null+++ b/wger/gym/fixtures/gym.json@@ -0,0 +1,15 @@+[+ {+ "pk": 1,+ "model": "gym.gym",+ "fields": {+ "city": "",+ "name": "Default gym",+ "phone": "",+ "street": "",+ "owner": "",+ "email": "",+ "zip_code": null+ }+ }+]\ No newline at end of filediff --git a/wger/gym/management/commands/gym-user-config.py b/wger/gym/management/commands/gym-user-config.pynew file mode 100644index 000000000..7f7b20f31--- /dev/null+++ b/wger/gym/management/commands/gym-user-config.py@@ -0,0 +1,54 @@+# -*- coding: utf-8 *-*++# 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++from django.contrib.auth.models import User+from django.core.exceptions import ObjectDoesNotExist+from django.core.management.base import BaseCommand++from wger.gym.helpers import is_any_gym_admin+from wger.gym.models import GymUserConfig, GymAdminConfig+++class Command(BaseCommand):+ '''+ Check that all gym trainers and users have configurations+ '''+ help = 'Check that all gym trainers and users have configurations'++ def handle(self, *args, **options):+ '''+ Process all users+ '''++ for user in User.objects.all():+ if is_any_gym_admin(user):+ try:+ user.gymadminconfig+ except ObjectDoesNotExist:+ config = GymAdminConfig()+ config.user = user+ config.gym = user.userprofile.gym+ config.save()++ else:+ if user.userprofile.gym_id:+ try:+ user.gymuserconfig+ except ObjectDoesNotExist:+ config = GymUserConfig()+ config.user = user+ config.gym = user.userprofile.gym+ config.save()diff --git a/wger/main.py b/wger/main.pyindex ed0eef549..fe3717802 100755--- a/wger/main.py+++ b/wger/main.py@@ -353,6 +353,7 @@ def init_south():execute_from_command_line(["", "migrate", "wger.manager", "0001", "--fake"])execute_from_command_line(["", "migrate", "wger.nutrition", "0001", "--fake"])execute_from_command_line(["", "migrate", "wger.weight", "0001", "--fake"])+ execute_from_command_line(["", "migrate", "wger.gym", "0001"])def run_south():@@ -365,6 +366,7 @@ def run_south():execute_from_command_line(["", "migrate", "wger.exercises"])execute_from_command_line(["", "migrate", "wger.nutrition"])execute_from_command_line(["", "migrate", "wger.weight"])+ execute_from_command_line(["", "migrate", "wger.gym"])# Other appsexecute_from_command_line(["", "migrate", "easy_thumbnails"])@@ -407,6 +409,12 @@ def load_fixtures():call_command("loaddata", path + "weight_units.json")call_command("loaddata", path + "ingredient_units.json")+ # Gym+ path = os.path.join(current_dir, 'gym', 'fixtures/')+ call_command("loaddata", path + "gym.json")+ call_command("loaddata", path + "gym-config.json")+ call_command("loaddata", path + "gym-adminconfig.json")+def run_syncdb():'''@@ -453,7 +461,10 @@ def create_or_reset_admin_user():except User.DoesNotExist:print("Created default admin user")- execute_from_command_line(["", "loaddata", "users"])+ os.chdir(os.path.dirname(inspect.stack()[0][1]))+ current_dir = os.getcwd()+ path = os.path.join(current_dir, 'core', 'fixtures/')+ call_command("loaddata", path + "users.json")def start_wger(addr, port, start_browser_url=None, extra_args=[]):