Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add edit views for gym user configurations

Roland Geidercf8a0a9f2fd6
diff --git a/wger/core/fixtures/groups.json b/wger/core/fixtures/groups.json
index 818102b72..c6b7c7e4f 100644
--- a/wger/core/fixtures/groups.json
+++ b/wger/core/fixtures/groups.json
@@ -195,6 +195,11 @@
"gym",
"gymconfig"
],
+ [
+ "change_gymuserconfig",
+ "gym",
+ "gymuserconfig"
+ ],
[
"add_ingredient",
"nutrition",
@@ -326,6 +331,11 @@
"change_gymadminconfig",
"gym",
"gymadminconfig"
+ ],
+ [
+ "change_gymuserconfig",
+ "gym",
+ "gymuserconfig"
]
]
}
diff --git a/wger/core/templates/user/overview.html b/wger/core/templates/user/overview.html
index 1cab0d9f6..ddcf28284 100644
--- a/wger/core/templates/user/overview.html
+++ b/wger/core/templates/user/overview.html
@@ -231,6 +231,38 @@
{% endif %}
</table>
+{# #}
+{# Gym configuration #}
+{# #}
+
+<div class="btn-group pull-right">
+ <button type="button" class="btn btn-default dropdown-toggle btn-xs" data-toggle="dropdown">
+ {% trans "Actions" %} <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu" role="menu">
+ <li>
+ <a href="{% url 'gym:user_config:edit' current_user.gymuserconfig.pk %}" class="wger-modal-dialog">{% trans "Edit"%}</a>
+ </li>
+ </ul>
+</div>
+
+
+<h4>{% trans "Configuration" %}</h4>
+<table class="table">
+ <tr>
+ <th>{% trans 'Include in inactive overview' %}</th>
+ <td>
+ {% if current_user.gymuserconfig.include_inactive %}
+ <span class="glyphicon glyphicon-ok"></span>
+ {% else %}
+ <span class="glyphicon glyphicon-remove"></span>
+ {% endif %}
+ </td>
+ </tr>
+</table>
+
+
+
<a href="{% url 'gym:gym:user-list' current_user.userprofile.gym.pk %}" {% auto_link_css flavour %}>
<img src="{% static 'images/icons/list.svg' %}"
width="32"
diff --git a/wger/gym/models.py b/wger/gym/models.py
index 670e5e452..f904ba4d7 100644
--- a/wger/gym/models.py
+++ b/wger/gym/models.py
@@ -205,6 +205,7 @@ class GymUserConfig(AbstractGymUserConfigModel, m.Model):
def get_owner_object(self):
'''
- Returns the object that has owner information
+ While the model has a user foreign key, this is editable by all
+ trainers in the gym.
'''
- return self
+ return None
diff --git a/wger/gym/tests/test_user_config.py b/wger/gym/tests/test_user_config.py
new file mode 100644
index 000000000..002cce292
--- /dev/null
+++ b/wger/gym/tests/test_user_config.py
@@ -0,0 +1,36 @@
+# This file is part of wger Workout Manager.
+#
+# wger 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.
+#
+# wger 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 datetime
+
+from django.core.urlresolvers import reverse
+
+from wger.manager.tests.testcase import WorkoutManagerTestCase
+from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase
+from wger.manager.tests.testcase import WorkoutManagerEditTestCase
+
+from wger.gym.models import GymUserConfig
+
+
+class EditConfigTestCase(WorkoutManagerEditTestCase):
+ '''
+ Tests editing an admin config
+ '''
+
+ object_class = GymUserConfig
+ url = 'gym:user_config:edit'
+ pk = 1
+ user_success = 'trainer1'
+ user_fail = 'member1'
+ data = {'include_inactive': False}
diff --git a/wger/gym/urls.py b/wger/gym/urls.py
index bf2123c5e..9f129be18 100644
--- a/wger/gym/urls.py
+++ b/wger/gym/urls.py
@@ -20,6 +20,7 @@ from django.conf.urls import patterns, url, include
from wger.gym.views import gym
from wger.gym.views import config
from wger.gym.views import admin_config
+from wger.gym.views import user_config
# 'sub patterns' for gyms
@@ -65,6 +66,13 @@ patterns_adminconfig = patterns('',
name='edit'),
)
+# 'sub patterns' for gym user config
+patterns_userconfig = patterns('',
+ url(r'^(?P<pk>\d+)/edit$',
+ user_config.ConfigUpdateView.as_view(),
+ name='edit'),
+)
+
#
# All patterns for this app
#
@@ -73,4 +81,5 @@ urlpatterns = patterns('',
url(r'^', include(patterns_gym, namespace="gym")),
url(r'^config/', include(patterns_gymconfig, namespace="config")),
url(r'^admin-config/', include(patterns_adminconfig, namespace="admin_config")),
+ url(r'^user-config/', include(patterns_userconfig, namespace="user_config")),
)
diff --git a/wger/gym/views/user_config.py b/wger/gym/views/user_config.py
new file mode 100644
index 000000000..33faf81a2
--- /dev/null
+++ b/wger/gym/views/user_config.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+
+# This file is part of wger Workout Manager.
+#
+# wger 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.
+#
+# wger 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
+
+from django.core.urlresolvers import reverse
+from django.http.response import HttpResponseForbidden
+from django.utils.translation import ugettext as _
+from django.views.generic import UpdateView
+
+from wger.gym.models import GymUserConfig
+from wger.utils.generic_views import WgerFormMixin
+
+
+logger = logging.getLogger('wger.custom')
+
+
+class ConfigUpdateView(WgerFormMixin, UpdateView):
+ '''
+ View to update an existing user gym configuration
+ '''
+
+ model = GymUserConfig
+ permission_required = 'gym.change_gymuserconfig'
+
+ def get_success_url(self):
+ '''
+ Return to the gym user overview
+ '''
+ return reverse('gym:gym:user-list', kwargs={'pk': self.object.gym.pk})
+
+ def get_context_data(self, **kwargs):
+ '''
+ Send some additional data to the template
+ '''
+ context = super(ConfigUpdateView, self).get_context_data(**kwargs)
+ context['form_action'] = reverse('gym:user_config:edit', kwargs={'pk': self.object.id})
+ context['title'] = _('Configuration')
+ return context