Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Set active tab with a context processor, not on each view

Roland Geider70a4e25e5b8f
diff --git a/exercises/views.py b/exercises/views.py
index 40d458f2b..e5cdfa0e5 100644
--- a/exercises/views.py
+++ b/exercises/views.py
@@ -30,7 +30,6 @@ from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.decorators import permission_required
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
-from django.utils.datastructures import SortedDict
from django.views.generic import DeleteView
from django.views.generic import CreateView
@@ -47,7 +46,6 @@ from exercises.models import Muscle
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')
@@ -67,7 +65,6 @@ class ExerciseCommentEditView(YamlFormMixin, UpdateView):
Generic view to update an existing exercise comment
"""
- active_tab = EXERCISE_TAB
model = ExerciseComment
form_class = ExerciseCommentForm
title = ugettext_lazy('Edit exercise comment')
@@ -89,7 +86,6 @@ class ExerciseCommentAddView(YamlFormMixin, CreateView):
Generic view to add a new exercise comment
"""
- active_tab = EXERCISE_TAB
model = ExerciseComment
form_class = ExerciseCommentForm
title = ugettext_lazy('Add exercise comment')
@@ -135,7 +131,6 @@ def exercise_overview(request):
template_data.update(csrf(request))
template_data['categories'] = ExerciseCategory.objects.filter(language=language.id)
- template_data['active_tab'] = EXERCISE_TAB
return render_to_response('overview.html',
template_data,
@@ -159,7 +154,6 @@ class MuscleListView(ListView):
'''
context = super(MuscleListView, self).get_context_data(**kwargs)
context['language'] = load_language()
- context['active_tab'] = EXERCISE_TAB
return context
@@ -175,7 +169,6 @@ def exercise_view(request, id, slug=None):
# Load the exercise itself
exercise = get_object_or_404(Exercise, pk=id)
template_data['exercise'] = exercise
- template_data['active_tab'] = EXERCISE_TAB
# Create the backgrounds that show what muscles the exercise works on
backgrounds_back = []
@@ -225,7 +218,6 @@ class ExercisesEditAddView(YamlFormMixin):
Generic view to subclass from for exercise adding and editing, since they
share all this settings
"""
- active_tab = EXERCISE_TAB
model = Exercise
form_fields = ['name',
@@ -282,7 +274,6 @@ 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.')
@@ -350,7 +341,6 @@ class ExerciseCategoryAddView(YamlFormMixin, CreateView):
Generic view to add a new exercise category
"""
- active_tab = EXERCISE_TAB
model = ExerciseCategory
form_class = ExerciseCategoryForm
success_url = reverse_lazy('exercises.views.exercise_overview')
@@ -368,7 +358,6 @@ class ExerciseCategoryUpdateView(YamlFormMixin, UpdateView):
Generic view to update an existing exercise category
"""
- active_tab = EXERCISE_TAB
model = ExerciseCategory
form_class = ExerciseCategoryForm
success_url = reverse_lazy('exercises.views.exercise_overview')
diff --git a/manager/context_processor.py b/manager/context_processor.py
index aef21605a..f0b56c4e0 100644
--- a/manager/context_processor.py
+++ b/manager/context_processor.py
@@ -1,15 +1,15 @@
# 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
# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.
@@ -18,17 +18,42 @@ from workout_manager import get_version
from manager.utils import load_language
+from workout_manager import constants
+
+
def processor(request):
- return {
+
+ context = {
# Application version
- 'version' : get_version(),
-
+ 'version': get_version(),
+
# Do not track header
'DNT': request.META.get('HTTP_DNT', False),
-
+
# User language
'language': load_language(),
-
+
# The current request
'request': request
}
+
+ # Pseudo-intelligent navigation here
+ if '/software/' in request.get_full_path():
+ context['active_tab'] = constants.SOFTWARE_TAB
+
+ elif '/exercise/' in request.get_full_path():
+ context['active_tab'] = constants.EXERCISE_TAB
+
+ elif '/nutrition/' in request.get_full_path():
+ context['active_tab'] = constants.NUTRITION_TAB
+
+ elif '/weight/' in request.get_full_path():
+ context['active_tab'] = constants.WEIGHT_TAB
+
+ elif '/workout/' in request.get_full_path():
+ context['active_tab'] = constants.WORKOUT_TAB
+
+ else:
+ context['active_tab'] = constants.USER_TAB
+
+ return context
diff --git a/manager/views.py b/manager/views.py
index eb59e9c4e..800ef336c 100644
--- a/manager/views.py
+++ b/manager/views.py
@@ -76,8 +76,6 @@ from manager.forms import DemoUserForm
from manager.utils import load_language
-from workout_manager.constants import WORKOUT_TAB
-from workout_manager.constants import USER_TAB
from workout_manager.generic_views import YamlFormMixin
from workout_manager.generic_views import YamlDeleteMixin
@@ -96,7 +94,6 @@ def index(request):
"""
template_data = {}
- template_data['active_tab'] = USER_TAB
# Load the last workout, if one exists
try:
@@ -156,8 +153,7 @@ def login(request):
"""
return django_loginview(request,
- template_name='user/login.html',
- extra_context={'active_tab': USER_TAB})
+ template_name='user/login.html')
def logout(request):
@@ -172,7 +168,6 @@ def registration(request):
"""
template_data = {}
template_data.update(csrf(request))
- template_data['active_tab'] = USER_TAB
if request.method == 'POST':
form = RegistrationForm(data=request.POST)
@@ -210,7 +205,6 @@ def create_demo_user(request):
template_data = {}
template_data.update(csrf(request))
- template_data['active_tab'] = USER_TAB
if request.method == 'POST':
form = DemoUserForm(data=request.POST)
@@ -297,7 +291,6 @@ def preferences(request):
"""
template_data = {}
template_data.update(csrf(request))
- template_data['active_tab'] = USER_TAB
# Process the preferences form
if request.method == 'POST':
@@ -371,7 +364,6 @@ def overview(request):
"""
template_data = {}
- template_data['active_tab'] = WORKOUT_TAB
latest_trainings = TrainingSchedule.objects.filter(user=request.user)
template_data['workouts'] = latest_trainings
@@ -386,7 +378,6 @@ def view_workout(request, id):
"""Show the workout with the given ID
"""
template_data = {}
- template_data['active_tab'] = WORKOUT_TAB
workout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)
template_data['workout'] = workout
@@ -510,7 +501,6 @@ class WorkoutDeleteView(YamlDeleteMixin, DeleteView):
Generic view to delete a workout routine
"""
- active_tab = WORKOUT_TAB
model = TrainingSchedule
success_url = reverse_lazy('manager.views.overview')
title = ugettext_lazy('Delete workout')
@@ -522,7 +512,6 @@ class WorkoutEditView(YamlFormMixin, UpdateView):
Generic view to update an existing workout routine
"""
- active_tab = WORKOUT_TAB
model = TrainingSchedule
form_class = WorkoutForm
title = ugettext_lazy('Edit workout')
@@ -537,7 +526,6 @@ class DayView(YamlFormMixin):
Base generic view for exercise day
"""
- active_tab = WORKOUT_TAB
model = Day
form_class = DayForm
@@ -649,7 +637,6 @@ def edit_set(request, id, day_id, set_id=None):
template_data = {}
template_data.update(csrf(request))
- template_data['active_tab'] = WORKOUT_TAB
# Load workout
workout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)
@@ -858,7 +845,6 @@ def api_edit_set(request):
def edit_setting(request, id, set_id, exercise_id, setting_id=None):
template_data = {}
template_data.update(csrf(request))
- template_data['active_tab'] = WORKOUT_TAB
# Load workout
workout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)
@@ -967,7 +953,6 @@ class WorkoutLogUpdateView(YamlFormMixin, UpdateView):
"""
Generic view to edit an existing workout log weight entry
"""
- active_tab = WORKOUT_TAB
model = WorkoutLog
form_class = WorkoutLogForm
custom_js = '''$(document).ready(function () {
@@ -992,7 +977,6 @@ def workout_log_add(request, pk):
template_data = {}
template_data.update(csrf(request))
- template_data['active_tab'] = WORKOUT_TAB
# Load the day and check ownership
day = get_object_or_404(Day, pk=pk)
@@ -1104,9 +1088,6 @@ class WorkoutLogDetailView(DetailView):
# Call the base implementation first to get a context
context = super(WorkoutLogDetailView, self).get_context_data(**kwargs)
- # Active tab
- context['active_tab'] = WORKOUT_TAB
-
# Prepare the entries for rendering and the D3 chart
workout_log = {}
entry = WorkoutLog()
diff --git a/nutrition/views.py b/nutrition/views.py
index 480a47d40..cc9cf2fee 100644
--- a/nutrition/views.py
+++ b/nutrition/views.py
@@ -50,7 +50,6 @@ from manager.utils import load_language
from manager.utils import load_ingredient_languages
from workout_manager import get_version
-from workout_manager.constants import NUTRITION_TAB
from workout_manager.generic_views import YamlFormMixin
from workout_manager.generic_views import YamlDeleteMixin
from workout_manager import helpers
@@ -73,7 +72,6 @@ class PlanForm(ModelForm):
def overview(request):
template_data = {}
template_data.update(csrf(request))
- template_data['active_tab'] = NUTRITION_TAB
plans = NutritionPlan.objects.filter(user=request.user)
template_data['plans'] = plans
@@ -101,7 +99,6 @@ class PlanDeleteView(YamlDeleteMixin, DeleteView):
Generic view to delete a nutritional plan
"""
- active_tab = NUTRITION_TAB
model = NutritionPlan
success_url = reverse_lazy('nutrition.views.overview')
title = ugettext_lazy('Delete nutritional plan?')
@@ -113,7 +110,6 @@ class PlanEditView(YamlFormMixin, UpdateView):
Generic view to update an existing nutritional plan
"""
- active_tab = NUTRITION_TAB
model = NutritionPlan
form_class = PlanForm
title = ugettext_lazy('Add a new nutritional plan')
@@ -125,7 +121,6 @@ def view(request, id):
"""Show the nutrition plan with the given ID
"""
template_data = {}
- template_data['active_tab'] = NUTRITION_TAB
plan = get_object_or_404(NutritionPlan, pk=id, user=request.user)
template_data['plan'] = plan
@@ -317,7 +312,6 @@ class MealCreateView(YamlFormMixin, CreateView):
Generic view to add a new meal to a nutrition plan
"""
- active_tab = NUTRITION_TAB
model = Meal
form_class = MealForm
title = ugettext_lazy('Add new meal')
@@ -346,7 +340,6 @@ class MealEditView(YamlFormMixin, UpdateView):
Generic view to update an existing meal
"""
- active_tab = NUTRITION_TAB
model = Meal
form_class = MealForm
title = ugettext_lazy('Edit meal')
@@ -398,7 +391,6 @@ 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_TAB
# Load the plan
plan = get_object_or_404(NutritionPlan, pk=id, user=request.user)
@@ -469,7 +461,6 @@ def ingredient_overview(request):
"""
template_data = {}
- 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)
@@ -489,7 +480,6 @@ def ingredient_overview(request):
def ingredient_view(request, id):
template_data = {}
- template_data['active_tab'] = NUTRITION_TAB
ingredient = get_object_or_404(Ingredient, pk=id)
template_data['ingredient'] = ingredient
@@ -529,7 +519,6 @@ class IngredientEditView(YamlFormMixin, UpdateView):
Generic view to update an existing ingredient
"""
- active_tab = NUTRITION_TAB
model = Ingredient
form_class = IngredientForm
title = ugettext_lazy('Add a new ingredient')
@@ -541,7 +530,6 @@ class IngredientCreateView(YamlFormMixin, CreateView):
Generic view to add a new ingredient
"""
- active_tab = NUTRITION_TAB
model = Ingredient
form_class = IngredientForm
title = ugettext_lazy('Add a new ingredient')
diff --git a/weight/views.py b/weight/views.py
index 28e82be0e..543f39cec 100644
--- a/weight/views.py
+++ b/weight/views.py
@@ -45,7 +45,6 @@ from weight.models import WeightEntry
from weight import helpers
from workout_manager.generic_views import YamlFormMixin
-from workout_manager.constants import WEIGHT_TAB
from workout_manager.constants import DATE_FORMATS
@@ -64,7 +63,6 @@ class WeightAddView(YamlFormMixin, CreateView):
"""
Generic view to add a new weight entry
"""
- active_tab = WEIGHT_TAB
model = WeightEntry
form_class = WeightForm
custom_js = '''$(document).ready(function () {
@@ -87,7 +85,6 @@ class WeightUpdateView(YamlFormMixin, UpdateView):
"""
Generic view to edit an existing weight entry
"""
- active_tab = WEIGHT_TAB
model = WeightEntry
form_class = WeightForm
custom_js = '''$(document).ready(function () {
@@ -135,7 +132,6 @@ def overview(request):
* http://d3js.org/
"""
template_data = {}
- 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']
@@ -210,7 +206,6 @@ class WeightCsvImportFormPreview(FormPreview):
return {'form': form,
'stage_field': self.unused_name('stage'),
'state': self.state,
- 'active_tab': WEIGHT_TAB,
'form_action': reverse('weight-import-csv')}
def process_preview(self, request, form, context):
diff --git a/workout_manager/constants.py b/workout_manager/constants.py
index 7b336f8c3..c571f8279 100644
--- a/workout_manager/constants.py
+++ b/workout_manager/constants.py
@@ -1,17 +1,17 @@
# -*- 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
@@ -20,15 +20,16 @@ WORKOUT_TAB = 'workout'
EXERCISE_TAB = 'exercises'
WEIGHT_TAB = 'weight'
NUTRITION_TAB = 'nutrition'
+SOFTWARE_TAB = 'software'
USER_TAB = 'user'
# Valid date formats
DATE_FORMATS = [
- '%d.%m.%Y', # '25.10.2012'
- '%d.%m.%y', # '25.10.12'
-
- '%m/%d/%Y', # '10/25/2012'
- '%m/%d/%y', # '10/25/12'
-
- '%Y-%m-%d', # '2012-10-25'
- ]
\ No newline at end of file
+ '%d.%m.%Y', # '25.10.2012'
+ '%d.%m.%y', # '25.10.12'
+
+ '%m/%d/%Y', # '10/25/2012'
+ '%m/%d/%y', # '10/25/12'
+
+ '%Y-%m-%d', # '2012-10-25'
+ ]
diff --git a/workout_manager/urls.py b/workout_manager/urls.py
index 575ccf2f6..b024ac7cc 100644
--- a/workout_manager/urls.py
+++ b/workout_manager/urls.py
@@ -1,14 +1,15 @@
-from django.conf.urls import patterns, include, url
+from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
admin.autodiscover()
urlpatterns = i18n_patterns('',
- url(r'^admin/', include(admin.site.urls)),
+ url(r'^admin/', include(admin.site.urls)),
url(r'^', include('manager.urls')),
url(r'exercise/', include('exercises.urls')),
url(r'weight/', include('weight.urls')),
url(r'nutrition/', include('nutrition.urls')),
+ url(r'software/', include('software.urls', namespace='software', app_name='software')),
url(r'^browserid/', include('django_browserid.urls')),
)