Self hosted FLOSS fitness/workout, nutrition and weight tracker
Use a constant for the currently active navigation tab
Roland Geider88f4f24273d9
diff --git a/exercises/views.py b/exercises/views.pyindex ddcd08812..b6514471d 100644--- a/exercises/views.py+++ b/exercises/views.py@@ -47,6 +47,8 @@ from exercises.models import ExerciseCategoryfrom workout_manager.generic_views import YamlFormMixinfrom workout_manager.generic_views import YamlDeleteMixin+from workout_manager.constants import EXERCISE_TAB+logger = logging.getLogger('workout_manager.custom')@@ -65,7 +67,7 @@ class ExerciseCommentEditView(YamlFormMixin, UpdateView):Generic view to update an existing exercise comment"""- active_tab = 'exercises'+ active_tab = EXERCISE_TABmodel = ExerciseCommentform_class = ExerciseCommentFormtitle = ugettext_lazy('Edit exercise comment')@@ -87,7 +89,7 @@ class ExerciseCommentAddView(YamlFormMixin, CreateView):Generic view to add a new exercise comment"""- active_tab = 'exercises'+ active_tab = EXERCISE_TABmodel = ExerciseCommentform_class = ExerciseCommentFormtitle = ugettext_lazy('Add exercise comment')@@ -134,7 +136,7 @@ def exercise_overview(request):template_data.update(csrf(request))template_data['categories'] = ExerciseCategory.objects.filter(language = language.id)- template_data['active_tab'] = 'exercises'+ template_data['active_tab'] = EXERCISE_TABreturn render_to_response('overview.html',template_data,@@ -151,7 +153,7 @@ def exercise_view(request, id, comment_id=None):# Load the exercise itselfexercise = get_object_or_404(Exercise, pk=id)template_data['exercise'] = exercise- template_data['active_tab'] = 'exercises'+ template_data['active_tab'] = EXERCISE_TAB# Create the backgrounds that show what muscles the exercise works onbackgrounds_back = []@@ -186,8 +188,7 @@ class ExercisesEditAddView(YamlFormMixin):Generic view to subclass from for exercise adding and editing, since they share allthis settings"""- active_tab = 'exercises'-+ active_tab = EXERCISE_TABmodel = Exerciseform_fields = ['name',@@ -238,6 +239,7 @@ class ExerciseDeleteView(YamlDeleteMixin, DeleteView):"""model = Exercise+ active_tab = EXERCISE_TABsuccess_url = reverse_lazy('exercises.views.exercise_overview')delete_message = ugettext_lazy('This will delete the exercise from all workouts.')@@ -303,7 +305,7 @@ class ExerciseCategoryAddView(YamlFormMixin, CreateView):Generic view to add a new exercise category"""- active_tab = 'exercises'+ active_tab = EXERCISE_TABmodel = ExerciseCategoryform_class = ExerciseCategoryFormsuccess_url = reverse_lazy('exercises.views.exercise_overview')@@ -321,7 +323,7 @@ class ExerciseCategoryUpdateView(YamlFormMixin, UpdateView):Generic view to update an existing exercise category"""- active_tab = 'exercises'+ active_tab = EXERCISE_TABmodel = ExerciseCategoryform_class = ExerciseCategoryFormsuccess_url = reverse_lazy('exercises.views.exercise_overview')diff --git a/manager/views.py b/manager/views.pyindex 5bddeaf26..f82b9d38f 100644--- a/manager/views.py+++ b/manager/views.py@@ -62,6 +62,10 @@ from reportlab.lib.pagesizes import A4, cm, landscape, portraitfrom reportlab.platypus import Paragraph, SimpleDocTemplate, Tablefrom reportlab.lib import colors+from workout_manager.constants import WORKOUT_TAB+from workout_manager.constants import USER_TAB++logger = logging.getLogger('workout_manager.custom')# ************************@@ -75,7 +79,7 @@ def index(request):"""template_data = {}- template_data['active_tab'] = 'user'+ template_data['active_tab'] = USER_TAB# Load the last workout, if one existstry:@@ -144,7 +148,7 @@ def login(request):template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'user'+ template_data['active_tab'] = USER_TABtemplate_data['form'] = AuthenticationForm()@@ -191,7 +195,7 @@ def change_password(request):template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'user'+ template_data['active_tab'] = USER_TABif request.method == 'POST':form = PasswordChangeForm(request.user, data=request.POST)@@ -224,7 +228,7 @@ def registration(request):"""template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'user'+ template_data['active_tab'] = USER_TABif request.method == 'POST':form = UserCreationForm(data=request.POST)@@ -254,7 +258,7 @@ def preferences(request):"""template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'user'+ template_data['active_tab'] = USER_TABif request.method == 'POST':@@ -289,7 +293,7 @@ def overview(request):"""template_data = {}- template_data['active_tab'] = 'workout'+ template_data['active_tab'] = WORKOUT_TABlatest_trainings = TrainingSchedule.objects.filter(user=request.user)template_data['workouts'] = latest_trainings@@ -303,7 +307,7 @@ def view_workout(request, id):"""Show the workout with the given ID"""template_data = {}- template_data['active_tab'] = 'workout'+ template_data['active_tab'] = WORKOUT_TABworkout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)template_data['workout'] = workout@@ -627,7 +631,7 @@ def edit_workout(request, id):"""template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'workout'+ template_data['active_tab'] = WORKOUT_TAB# Load workoutworkout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)@@ -696,7 +700,7 @@ def edit_day(request, id, day_id=None):"""template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'workout'+ template_data['active_tab'] = WORKOUT_TAB# Load workoutworkout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)@@ -813,7 +817,7 @@ def edit_set(request, id, day_id, set_id=None):template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'workout'+ template_data['active_tab'] = WORKOUT_TAB# Load workoutworkout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)@@ -1033,7 +1037,7 @@ class SettingForm(ModelForm):def edit_setting(request, id, set_id, exercise_id, setting_id=None):template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'workout'+ template_data['active_tab'] = WORKOUT_TAB# Load workoutworkout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)diff --git a/nutrition/views.py b/nutrition/views.pyindex 4e9589c0e..7ab6b13c1 100644--- a/nutrition/views.py+++ b/nutrition/views.py@@ -51,6 +51,8 @@ from reportlab.lib import colorsfrom manager.utils import load_languagefrom manager.utils import load_ingredient_languages+from workout_manager.constants import NUTRITION_TAB+logger = logging.getLogger('workout_manager.custom')@@ -67,7 +69,7 @@ class PlanForm(ModelForm):def overview(request):template_data = {}template_data.update(csrf(request))- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TABplans = NutritionPlan.objects.filter(user = request.user)template_data['plans'] = plans@@ -104,7 +106,7 @@ def view(request, id):"""Show the nutrition plan with the given ID"""template_data = {}- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TABplan = get_object_or_404(NutritionPlan, pk=id, user=request.user)template_data['plan'] = plan@@ -126,7 +128,7 @@ def edit_plan(request, id):"""Edits a nutrition plan"""template_data = {}- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TAB# Load the planplan = get_object_or_404(NutritionPlan, pk=id, user=request.user)@@ -297,7 +299,7 @@ def edit_meal(request, id, meal_id):"""Form to add a meal to a plan"""template_data = {}- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TAB# Load the planplan = get_object_or_404(NutritionPlan, pk=id, user=request.user)@@ -338,7 +340,7 @@ def add_meal(request, id, meal_id=None):"""Form to add a meal to a plan"""template_data = {}- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TAB# Load the planplan = get_object_or_404(NutritionPlan, pk=id, user=request.user)@@ -394,7 +396,7 @@ def edit_meal_item(request, id, meal_id, item_id=None):"""Form to add a meal to a plan"""template_data = {}- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TAB# Load the planplan = get_object_or_404(NutritionPlan, pk=id, user=request.user)@@ -467,7 +469,7 @@ def ingredient_overview(request):"""template_data = {}- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TAB# Filter the ingredients the user will see by its language# (the user can also want to see ingredients in English, see load_ingredient_languages)@@ -483,7 +485,7 @@ def ingredient_overview(request):def ingredient_view(request, id):template_data = {}- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TABingredient = get_object_or_404(Ingredient, pk=id)template_data['ingredient'] = ingredient@@ -524,7 +526,7 @@ def ingredient_edit(request, id=None):"""template_data = {}- template_data['active_tab'] = 'nutrition'+ template_data['active_tab'] = NUTRITION_TAB# Load the ingredientif id:diff --git a/weight/views.py b/weight/views.pyindex 5f93254d0..d6868cdba 100644--- a/weight/views.py+++ b/weight/views.py@@ -40,6 +40,7 @@ from django.views.generic import UpdateViewfrom weight.models import WeightEntryfrom workout_manager.generic_views import YamlFormMixin+from workout_manager.constants import WEIGHT_TABlogger = logging.getLogger('workout_manager.custom')@@ -53,7 +54,7 @@ class WeightAddView(YamlFormMixin, CreateView):"""Generic view to add a new weight entry"""- active_tab = 'weight'+ active_tab = WEIGHT_TABmodel = WeightEntryform_class = WeightFormcustom_js = '''$(document).ready(function () {@@ -77,7 +78,7 @@ class WeightUpdateView(YamlFormMixin, UpdateView):"""Generic view to edit an existing weight entry"""- active_tab = 'weight'+ active_tab = WEIGHT_TABmodel = WeightEntryform_class = WeightFormcustom_js = '''$(document).ready(function () {@@ -124,7 +125,7 @@ def overview(request):* http://d3js.org/"""template_data = {}- template_data['active_tab'] = 'weight'+ template_data['active_tab'] = WEIGHT_TABmin_date = WeightEntry.objects.filter(user = request.user).aggregate(Min('creation_date'))['creation_date__min']max_date = WeightEntry.objects.filter(user = request.user).aggregate(Max('creation_date'))['creation_date__max']diff --git a/workout_manager/constants.py b/workout_manager/constants.pynew file mode 100644index 000000000..4e72ec708--- /dev/null+++ b/workout_manager/constants.py@@ -0,0 +1,22 @@+# -*- coding: utf-8 -*-++# This file is part of Workout Manager.+#+# 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.+#+# 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+++WORKOUT_TAB = 'workout'+EXERCISE_TAB = 'exercises'+WEIGHT_TAB = 'weight'+NUTRITION_TAB = 'nutrition'+USER_TAB = 'user'