Self hosted FLOSS fitness/workout, nutrition and weight tracker
Don't set the active tab from within the generic view
Roland Geider3547044ee6b4
diff --git a/wger/workout_manager/generic_views.py b/wger/workout_manager/generic_views.pyindex f1549ed3e..966476edd 100644--- a/wger/workout_manager/generic_views.py+++ b/wger/workout_manager/generic_views.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 Licenseimport logging@@ -25,12 +25,11 @@ from django.views.generic.edit import ModelFormMixinlogger = logging.getLogger('workout_manager.custom')+class YamlFormMixin(ModelFormMixin):template_name = 'form.html'-- active_tab = ''+form_fields = []- active_tab = ''select_lists = []custom_js = ''form_action = ''@@ -38,37 +37,34 @@ class YamlFormMixin(ModelFormMixin):title = ''owner_object = Falsesubmit_text = ugettext_lazy('Save')-+def get_context_data(self, **kwargs):'''Set necessary template data to correctly render the form'''-+# Call the base implementation first to get a contextcontext = super(YamlFormMixin, self).get_context_data(**kwargs)-+# CSRF tokencontext.update(csrf(self.request))-- # Active tab, on top navigation- context['active_tab'] = self.active_tab-+# Custom order for form fields. The list comprehension is to avoid# weird problems with django's template when accessing the fields with "form.fieldname"if self.form_fields:context['form_fields'] = [kwargs['form'][i] for i in self.form_fields]-+# Use the the order as defined in the modelelse:context['form_fields'] = kwargs['form']-+# Drop down lists get a special CSS class, there doesn't seem to be# another way of detecting themcontext['select_lists'] = self.select_lists-+# Custom JS code on form (autocompleter, editor, etc.)context['custom_js'] = self.custom_js-+# When viewing the page on it's own, this is not necessary, but when# opening it on a modal dialog, we need to make sure the POST request# reaches the correct controller@@ -76,30 +72,29 @@ class YamlFormMixin(ModelFormMixin):context['form_action'] = reverse(self.form_action_urlname, kwargs={'pk': self.object.id})elif self.form_action:context['form_action'] = self.form_action-+# Set the titlecontext['title'] = self.title-+# Text used in the submit buttoncontext['submit_text'] = self.submit_text--- return context-++ return context+def dispatch(self, request, *args, **kwargs):"""Custom dispatch method.-+This basically only checks for ownerships of editable/deletableobjects and return a HttpResponseForbidden response if the useris not the owner."""-+# These seem to be necessary for calling get_objectself.kwargs = kwargsself.request = request-- # For new objects, we have to manually load the owner object++ # For new objects, we have to manually load the owner objectif self.owner_object:owner_object = self.owner_object['class'].objects.get(pk = kwargs[self.owner_object['pk']])else:@@ -108,41 +103,41 @@ class YamlFormMixin(ModelFormMixin):owner_object = self.get_object().get_owner_object()except AttributeError:owner_object = False-+# Nothing to see, please move alongif owner_object and owner_object.user != self.request.user:return HttpResponseForbidden()-+# Dispatch normallyreturn super(YamlFormMixin, self).dispatch(request, *args, **kwargs)---+++class YamlDeleteMixin(ModelFormMixin):template_name = 'delete.html'-+active_tab = ''form_action = ''form_action_urlname = ''title = ''delete_message = ''template_name = 'delete.html'--++def get_context_data(self, **kwargs):'''Set necessary template data to correctly render the form'''-+# Call the base implementation first to get a contextcontext = super(YamlDeleteMixin, self).get_context_data(**kwargs)-+# CSRF tokencontext.update(csrf(self.request))-+# Active tab, on top navigationcontext['active_tab'] = self.active_tab-+# When viewing the page on it's own, this is not necessary, but when# opening it on a modal dialog, we need to make sure the POST request# reaches the correct controller@@ -150,35 +145,35 @@ class YamlDeleteMixin(ModelFormMixin):context['form_action'] = reverse(self.form_action_urlname, kwargs={'pk': self.object.id})elif self.form_action:context['form_action'] = self.form_action--++# Set the titlecontext['title'] = self.title-+# Additional delete messagecontext['delete_message'] = self.delete_message-+return context--++def dispatch(self, request, *args, **kwargs):"""Custom dispatch method.-+This basically only checks for ownerships of editable/deletableobjects and return a HttpResponseForbidden response if the useris not the owner."""-+# These seem to be necessary if for calling get_objectself.kwargs = kwargsself.request = requestowner_object = self.get_object().get_owner_object()-+# Nothing to see, please move alongif owner_object and owner_object.user != self.request.user:return HttpResponseForbidden()-+# Dispatch normallyreturn super(YamlDeleteMixin, self).dispatch(request, *args, **kwargs)-+