Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add option to show gym name in header

Roland Geider82be1168d310
diff --git a/docs/changelog.rst b/docs/changelog.rst
index d06a01cdb..9f6d9ccbd 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -28,6 +28,7 @@ New features:
* Big ingredient list in Dutch, many thanks to alphafitness.club!
* Add repetition (minutes, kilometer, etc.) and weight options (kg, lb, plates, until failure) to sets `#216`_ and `#217`_
* Allow administrators to deactivate the guest user account `#330`_
+* Add option to show the gym name in the header instead of the application name, part of `#214`_
* Exercise names are now capitalized, making them more consistent `#232`_
* Much improved landing page (thanks `@DeveloperMal`_) `#307`_
* Add extended PDF options to schedules as well (thanks `@alelevinas`_ ) `#272`_
@@ -57,6 +58,7 @@ Other improvements and bugfixes: `#25`_, `#243`_, `#279`_, `#275`_, `#270`_,
.. _#79: https://github.com/wger-project/wger/issues/79
.. _#188: https://github.com/wger-project/wger/issues/188
.. _#201: https://github.com/wger-project/wger/issues/201
+.. _#214: https://github.com/wger-project/wger/issues/214
.. _#216: https://github.com/wger-project/wger/issues/216
.. _#217: https://github.com/wger-project/wger/issues/217
.. _#232: https://github.com/wger-project/wger/issues/232
diff --git a/wger/config/tests/test_custom_header.py b/wger/config/tests/test_custom_header.py
new file mode 100644
index 000000000..7520da6dc
--- /dev/null
+++ b/wger/config/tests/test_custom_header.py
@@ -0,0 +1,66 @@
+# -*- 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
+# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.
+
+from django.core.urlresolvers import reverse
+
+from wger.gym.models import Gym
+from wger.core.tests.base_testcase import WorkoutManagerTestCase
+
+
+class GymNameHeaderTestCase(WorkoutManagerTestCase):
+ '''
+ Test case for showing gym name on application header
+ '''
+
+ def check_header(self, gym=None):
+
+ response = self.client.get(reverse('core:dashboard'))
+ self.assertEqual(response.context['custom_header'], gym)
+
+ def test_custom_header_gym_members(self):
+ '''
+ Test the custom header for gym members
+ '''
+
+ # Gym 1, custom header activated
+ gym = Gym.objects.get(pk=1)
+ self.assertTrue(gym.config.show_name)
+ for username in ('test',
+ 'member1',
+ 'member2',
+ 'member3',
+ 'member4',
+ 'member5'):
+ self.user_login(username)
+ self.check_header(gym=gym.name)
+
+ # Gym 2, custom header deactivated
+ gym = Gym.objects.get(pk=2)
+ self.assertFalse(gym.config.show_name)
+ for username in ('trainer4',
+ 'trainer5',
+ 'demo',
+ 'member6',
+ 'member7',):
+ self.user_login(username)
+ self.check_header(gym=None)
+
+ def test_custom_header_anonymous_user(self):
+ '''
+ Test the custom header for logged out users
+ '''
+ self.check_header(gym=None)
diff --git a/wger/core/templates/mobile/template.html b/wger/core/templates/mobile/template.html
index b6f06a5c0..c0a07eef6 100644
--- a/wger/core/templates/mobile/template.html
+++ b/wger/core/templates/mobile/template.html
@@ -105,7 +105,12 @@
<span class="glyphicon glyphicon-th-list"></span>
</button>
<span class="center-block application-name">
- wger
+ {# Show application's name or user's gym #}
+ {% if custom_header %}
+ {{ custom_header }}
+ {% else %}
+ wger
+ {% endif %}
</span>
</div>
diff --git a/wger/core/templates/template.html b/wger/core/templates/template.html
index 5d1e75090..6642681e2 100644
--- a/wger/core/templates/template.html
+++ b/wger/core/templates/template.html
@@ -100,8 +100,13 @@
<div class="container">
<div class="row">
<div class="col-md-9" style="padding-bottom: 0.5em;">
- <span class="name">wger</span>
- <span class="regular">| Workout Manager</span>
+ {# Show application's name or user's gym #}
+ {% if custom_header %}
+ <span class="name">{{ custom_header }}</span>
+ {% else %}
+ <span class="name">wger</span>
+ <span class="regular">| Workout Manager</span>
+ {% endif %}
</div>
<div class="col-md-3">
<a href="{% url 'core:contact' %}">{% trans "Get in touch" %}</a>
diff --git a/wger/gym/fixtures/gym-config.json b/wger/gym/fixtures/gym-config.json
index bb1697d05..4b6e96ca7 100644
--- a/wger/gym/fixtures/gym-config.json
+++ b/wger/gym/fixtures/gym-config.json
@@ -4,7 +4,8 @@
"model": "gym.gymconfig",
"fields": {
"gym": 1,
- "weeks_inactive": 8
+ "weeks_inactive": 8,
+ "show_name": false
}
}
]
diff --git a/wger/gym/fixtures/test-gymsconfig.json b/wger/gym/fixtures/test-gymsconfig.json
index 37db12af8..a0266f502 100644
--- a/wger/gym/fixtures/test-gymsconfig.json
+++ b/wger/gym/fixtures/test-gymsconfig.json
@@ -4,7 +4,8 @@
"model": "gym.gymconfig",
"fields": {
"gym": 1,
- "weeks_inactive": 7
+ "weeks_inactive": 7,
+ "show_name": true
}
},
{
@@ -12,7 +13,8 @@
"model": "gym.gymconfig",
"fields": {
"gym": 3,
- "weeks_inactive": 4
+ "weeks_inactive": 4,
+ "show_name": true
}
},
{
@@ -20,7 +22,8 @@
"model": "gym.gymconfig",
"fields": {
"gym": 2,
- "weeks_inactive": 2
+ "weeks_inactive": 2,
+ "show_name": false
}
}
]
\ No newline at end of file
diff --git a/wger/gym/migrations/0007_auto_20170123_0920.py b/wger/gym/migrations/0007_auto_20170123_0920.py
new file mode 100644
index 000000000..fe7b62099
--- /dev/null
+++ b/wger/gym/migrations/0007_auto_20170123_0920.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.12 on 2017-01-23 08:20
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gym', '0006_auto_20160214_1013'),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name='gym',
+ options={'ordering': ['name'], 'permissions': (('gym_trainer', 'Trainer: can see the users for a gym'), ('manage_gym', 'Admin: can manage users for a gym'), ('manage_gyms', 'Admin: can administrate the different gyms'))},
+ ),
+ migrations.AddField(
+ model_name='gymconfig',
+ name='show_name',
+ field=models.BooleanField(default=False, verbose_name='Show name of the gym in the header'),
+ ),
+ migrations.AlterField(
+ model_name='contract',
+ name='options',
+ field=models.ManyToManyField(blank=True, to='gym.ContractOption', verbose_name='Options'),
+ ),
+ migrations.AlterField(
+ model_name='gymadminconfig',
+ name='overview_inactive',
+ field=models.BooleanField(default=True, help_text='Receive email overviews of inactive members', verbose_name='Overview of inactive members'),
+ ),
+ migrations.AlterField(
+ model_name='gymconfig',
+ name='weeks_inactive',
+ field=models.PositiveIntegerField(default=4, help_text='Number of weeks since the last time a user logged his presence to be considered inactive', verbose_name='Reminder of inactive members'),
+ ),
+ ]
diff --git a/wger/gym/models.py b/wger/gym/models.py
index 1ab3387a5..a5f7ab94e 100644
--- a/wger/gym/models.py
+++ b/wger/gym/models.py
@@ -136,6 +136,13 @@ class GymConfig(m.Model):
Reminder of inactive members
'''
+ show_name = m.BooleanField(verbose_name=_('Show name in header'),
+ help_text=_('Show the name of the gym in the site header'),
+ default=False)
+ '''
+ Show name of the current user's gym in the header, instead of 'wger'
+ '''
+
def __str__(self):
'''
Return a more human-readable representation
diff --git a/wger/gym/templates/gym/member_list.html b/wger/gym/templates/gym/member_list.html
index 2d7e2ac9f..972574be5 100644
--- a/wger/gym/templates/gym/member_list.html
+++ b/wger/gym/templates/gym/member_list.html
@@ -154,6 +154,10 @@
<td>{% trans "Inactive members" %}</td>
<td style="text-align: right;">{{gym.config.weeks_inactive}} {% trans 'weeks' %}</td>
</tr>
+ <tr>
+ <td>{% trans "Show name in header" %}</td>
+ <td style="text-align: right;">{{gym.config.show_name}}</td>
+ </tr>
</table>
diff --git a/wger/gym/tests/test_config.py b/wger/gym/tests/test_config.py
index 5d5fb4859..a9a11df98 100644
--- a/wger/gym/tests/test_config.py
+++ b/wger/gym/tests/test_config.py
@@ -12,8 +12,9 @@
#
# 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/>.
+from django.core.urlresolvers import reverse
-from wger.core.tests.base_testcase import WorkoutManagerEditTestCase
+from wger.core.tests.base_testcase import WorkoutManagerEditTestCase, WorkoutManagerTestCase
from wger.gym.models import GymConfig
@@ -25,7 +26,7 @@ class EditGymConfigTestCase(WorkoutManagerEditTestCase):
pk = 1
object_class = GymConfig
url = 'gym:config:edit'
- data = {'weeks_inactive': 10}
+ data = {'weeks_inactive': 10, 'show_name': True}
user_success = ('admin',
'manager1',
'manager2')
diff --git a/wger/utils/context_processor.py b/wger/utils/context_processor.py
index 980e719ef..9ccad60b6 100644
--- a/wger/utils/context_processor.py
+++ b/wger/utils/context_processor.py
@@ -17,6 +17,7 @@ from django.conf import settings
from django.templatetags.static import static
from wger import get_version
+from wger.config.models import GymConfig
from wger.utils import constants
from wger.utils.language import load_language
@@ -51,7 +52,6 @@ def processor(request):
'request_absolute_path': request.build_absolute_uri(),
'image_absolute_path': request.build_absolute_uri(static_path),
-
# Translation links
'i18n_path': i18n_path,
@@ -66,6 +66,9 @@ def processor(request):
# Used for logged in trainers
'trainer_identity': request.session.get('trainer.identity'),
+
+ # current gym, if available
+ 'custom_header': get_custom_header(request),
}
# Pseudo-intelligent navigation here
@@ -91,3 +94,26 @@ def processor(request):
context['active_tab'] = constants.USER_TAB
return context
+
+
+def get_custom_header(request):
+ '''
+ Loads the custom header for the application, if available
+
+ Currently the header can only be overwritten to use the user's current gym
+ '''
+
+ # Current gym
+ current_gym = None
+ if request.user.is_authenticated() and request.user.userprofile.gym:
+ current_gym = request.user.userprofile.gym
+ else:
+ global_gymconfig = GymConfig.objects.get(pk=1)
+ if global_gymconfig.default_gym:
+ current_gym = global_gymconfig.default_gym
+
+ # Put the custom header together
+ custom_header = None
+ if current_gym and current_gym.config.show_name:
+ custom_header = current_gym.name
+ return custom_header