Skip to content

armgit / wger

Public Imported from GitHub
0

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.py
index ddcd08812..b6514471d 100644
--- a/exercises/views.py
+++ b/exercises/views.py
@@ -47,6 +47,8 @@ from exercises.models import ExerciseCategory
from workout_manager.generic_views import YamlFormMixin
from 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_TAB
model = ExerciseComment
form_class = ExerciseCommentForm
title = 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_TAB
model = ExerciseComment
form_class = ExerciseCommentForm
title = 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_TAB
return render_to_response('overview.html',
template_data,
@@ -151,7 +153,7 @@ def exercise_view(request, id, comment_id=None):
# Load the exercise itself
exercise = 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 on
backgrounds_back = []
@@ -186,8 +188,7 @@ class ExercisesEditAddView(YamlFormMixin):
Generic view to subclass from for exercise adding and editing, since they share all
this settings
"""
- active_tab = 'exercises'
-
+ active_tab = EXERCISE_TAB
model = Exercise
form_fields = ['name',
@@ -238,6 +239,7 @@ class ExerciseDeleteView(YamlDeleteMixin, DeleteView):
"""
model = Exercise
+ active_tab = EXERCISE_TAB
success_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_TAB
model = ExerciseCategory
form_class = ExerciseCategoryForm
success_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_TAB
model = ExerciseCategory
form_class = ExerciseCategoryForm
success_url = reverse_lazy('exercises.views.exercise_overview')
diff --git a/manager/views.py b/manager/views.py
index 5bddeaf26..f82b9d38f 100644
--- a/manager/views.py
+++ b/manager/views.py
@@ -62,6 +62,10 @@ from reportlab.lib.pagesizes import A4, cm, landscape, portrait
from reportlab.platypus import Paragraph, SimpleDocTemplate, Table
from 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 exists
try:
@@ -144,7 +148,7 @@ def login(request):
template_data = {}
template_data.update(csrf(request))
- template_data['active_tab'] = 'user'
+ template_data['active_tab'] = USER_TAB
template_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_TAB
if 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_TAB
if 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_TAB
if request.method == 'POST':
@@ -289,7 +293,7 @@ def overview(request):
"""
template_data = {}
- template_data['active_tab'] = 'workout'
+ template_data['active_tab'] = WORKOUT_TAB
latest_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_TAB
workout = 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 workout
workout = 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 workout
workout = 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 workout
workout = 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 workout
workout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)
diff --git a/nutrition/views.py b/nutrition/views.py
index 4e9589c0e..7ab6b13c1 100644
--- a/nutrition/views.py
+++ b/nutrition/views.py
@@ -51,6 +51,8 @@ from reportlab.lib import colors
from manager.utils import load_language
from 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_TAB
plans = 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_TAB
plan = 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 plan
plan = 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 plan
plan = 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 plan
plan = 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 plan
plan = 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_TAB
ingredient = 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 ingredient
if id:
diff --git a/weight/views.py b/weight/views.py
index 5f93254d0..d6868cdba 100644
--- a/weight/views.py
+++ b/weight/views.py
@@ -40,6 +40,7 @@ from django.views.generic import UpdateView
from weight.models import WeightEntry
from workout_manager.generic_views import YamlFormMixin
+from workout_manager.constants import WEIGHT_TAB
logger = 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_TAB
model = WeightEntry
form_class = WeightForm
custom_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_TAB
model = WeightEntry
form_class = WeightForm
custom_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_TAB
min_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.py
new file mode 100644
index 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'