Skip to content

armgit / wger

Public Imported from GitHub
0

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.py
index 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 License
import logging
@@ -25,12 +25,11 @@ from django.views.generic.edit import ModelFormMixin
logger = 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 = False
submit_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 context
context = super(YamlFormMixin, self).get_context_data(**kwargs)
-
+
# CSRF token
context.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 model
else:
context['form_fields'] = kwargs['form']
-
+
# Drop down lists get a special CSS class, there doesn't seem to be
# another way of detecting them
context['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 title
context['title'] = self.title
-
+
# Text used in the submit button
context['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/deletable
objects and return a HttpResponseForbidden response if the user
is not the owner.
"""
-
+
# These seem to be necessary for calling get_object
self.kwargs = kwargs
self.request = request
-
- # For new objects, we have to manually load the owner object
+
+ # For new objects, we have to manually load the owner object
if 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 along
if owner_object and owner_object.user != self.request.user:
return HttpResponseForbidden()
-
+
# Dispatch normally
return 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 context
context = super(YamlDeleteMixin, self).get_context_data(**kwargs)
-
+
# CSRF token
context.update(csrf(self.request))
-
+
# Active tab, on top navigation
context['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 title
context['title'] = self.title
-
+
# Additional delete message
context['delete_message'] = self.delete_message
-
+
return context
-
-
+
+
def dispatch(self, request, *args, **kwargs):
"""
Custom dispatch method.
-
+
This basically only checks for ownerships of editable/deletable
objects and return a HttpResponseForbidden response if the user
is not the owner.
"""
-
+
# These seem to be necessary if for calling get_object
self.kwargs = kwargs
self.request = request
owner_object = self.get_object().get_owner_object()
-
+
# Nothing to see, please move along
if owner_object and owner_object.user != self.request.user:
return HttpResponseForbidden()
-
+
# Dispatch normally
return super(YamlDeleteMixin, self).dispatch(request, *args, **kwargs)
-
+