Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Replace django_mobile with django_user_agents

Scott Peshakd9c562612aa7
diff --git a/wger/core/templates/mobile/misc/contact.html b/wger/core/templates/mobile/misc/contact.html
index d5e4f3f63..e7ed175c9 100644
--- a/wger/core/templates/mobile/misc/contact.html
+++ b/wger/core/templates/mobile/misc/contact.html
@@ -21,20 +21,20 @@ you might also be interested <a href="{{contribute}}">in contributing</a>.{% end
<h4>{% trans "Feedback form" %}</h4>
<p>{% blocktrans %}A simple contact form. Remember that
if you want an answer, you need to include some way to contact you.{% endblocktrans %}</p>
-<p><a {% auto_link_css flavour %} href="{{feedback}}" data-ajax="false">{% trans "Open feedback form" %}</a></p>
+<p><a {% auto_link_css request.user_agent.is_mobile %} href="{{feedback}}" data-ajax="false">{% trans "Open feedback form" %}</a></p>
<h4>{% trans "Twitter" %}</h4>
<p>{% blocktrans %}We are also on twitter. Write us and tell us what
you think! Except patches, don't send patches via twitter.{% endblocktrans %}</p>
<p><a href="https://twitter.com/wger_de"
target="_blank"
- {% auto_link_css flavour %}>{% trans "tweet to @wger_de" %}</a></p>
+ {% auto_link_css request.user_agent.is_mobile %}>{% trans "tweet to @wger_de" %}</a></p>
<h4>{% trans "Forum / Mailing list" %}</h4>
<p>{% blocktrans %}Use the public group to get support for your
local wger installation, discuss issues or your new idea, etc.
(no registration needed){% endblocktrans %}</p>
-<p><a href="https://groups.google.com/group/wger" {% auto_link_css flavour %}>{% trans "Go to mailing list" %}</a></p>
+<p><a href="https://groups.google.com/group/wger" {% auto_link_css request.user_agent.is_mobile %}>{% trans "Go to mailing list" %}</a></p>
{% endblock %}
diff --git a/wger/core/templates/mobile/template.html b/wger/core/templates/mobile/template.html
index 93d8037d3..998d85db3 100644
--- a/wger/core/templates/mobile/template.html
+++ b/wger/core/templates/mobile/template.html
@@ -192,20 +192,20 @@
<div class="btn-group btn-group-justified" style="margin-top: 1em;">
{% if user.is_authenticated %}
<div class="btn-group">
- <a href="{% url 'core:index' %}" {% auto_link_css flavour %}>{% trans "Dashboard" %}</a>
+ <a href="{% url 'core:index' %}" {% auto_link_css request.user_agent.is_mobile %}>{% trans "Dashboard" %}</a>
</div>
<div class="btn-group">
- <a href="{% url 'manager:workout:overview' %}" {% auto_link_css flavour %}>{% trans "Workouts" %}</a>
+ <a href="{% url 'manager:workout:overview' %}" {% auto_link_css request.user_agent.is_mobile %}>{% trans "Workouts" %}</a>
</div>
<div class="btn-group">
- <a href="{% url 'nutrition:plan:overview' %}" {% auto_link_css flavour %}>{% trans "Nutrition" %}</a>
+ <a href="{% url 'nutrition:plan:overview' %}" {% auto_link_css request.user_agent.is_mobile %}>{% trans "Nutrition" %}</a>
</div>
{% else %}
<div class="btn-group">
- <a href="{% url 'core:user:login' %}" {% auto_link_css flavour %}>{% trans "Login" %}</a>
+ <a href="{% url 'core:user:login' %}" {% auto_link_css request.user_agent.is_mobile %}>{% trans "Login" %}</a>
</div>
<div class="btn-group">
- <a href="{% url 'software:features' %}" {% auto_link_css flavour %}>{% trans "Features" %}</a>
+ <a href="{% url 'software:features' %}" {% auto_link_css request.user_agent.is_mobile %}>{% trans "Features" %}</a>
</div>
{% endif %}
</div>
diff --git a/wger/core/templates/navigation.html b/wger/core/templates/navigation.html
index ab874d2fe..e61945042 100644
--- a/wger/core/templates/navigation.html
+++ b/wger/core/templates/navigation.html
@@ -1,7 +1,7 @@
{% load i18n cache wger_extras %}
<nav id="nav">
<div>
- <div class="navbar {% if flavour == 'full' %}navbar-inverse{% else %}navbar-default{% endif %}">
+ <div class="navbar {% if request.user_agent.is_pc %}navbar-inverse{% else %}navbar-default{% endif %}">
<div class="container">
<div class="navbar-header" >
<a class="navbar-toggle hidden-xs" data-toggle="collapse" data-target="#main-navbar-navigation">
@@ -10,7 +10,7 @@
<span class="icon-bar"></span>
</a>
</div>
- <div class="navbar-collapse {% if flavour == 'full' %}collapse{% endif %}" id="main-navbar-navigation">
+ <div class="navbar-collapse {% if request.user_agent.is_pc %}collapse{% endif %}" id="main-navbar-navigation">
<ul class="nav navbar-nav">
{# #}
{# User tab #}
diff --git a/wger/core/templatetags/wger_extras.py b/wger/core/templatetags/wger_extras.py
index 80a2e92ed..c06247f75 100644
--- a/wger/core/templatetags/wger_extras.py
+++ b/wger/core/templatetags/wger_extras.py
@@ -136,15 +136,15 @@ def get_item(dictionary, key):
@register.simple_tag
-def auto_link_css(flavour='full', css=''):
+def auto_link_css(mobile=False, css=''):
'''
Adds the appropriate classes to a sidebar link depending on the site version
- :param flavour: flavour of the site: 'mobile' or 'full'
+ :param mobile: true if mobile version of site
:param css: the CSS class, if any, of the link
:return: the complete CSS classes, wrapped in class="foo"
'''
- css = css + ' btn btn-default btn-block' if flavour == 'mobile' else css
+ css = css + ' btn btn-default btn-block' if mobile else css
return mark_safe('class="{0}"'.format(css))
diff --git a/wger/exercises/templates/exercise/view.html b/wger/exercises/templates/exercise/view.html
index 8d8be4f0c..4af37fb40 100644
--- a/wger/exercises/templates/exercise/view.html
+++ b/wger/exercises/templates/exercise/view.html
@@ -339,7 +339,7 @@ $(document).ready(function() {
{% if user.is_authenticated and not user.userprofile.is_temporary and not perms.exercises %}
<h4>{% trans "Options" %}</h4>
<p>
- <a href="{% url 'exercise:exercise:correct' exercise.id %}" {% auto_link_css flavour %}>
+ <a href="{% url 'exercise:exercise:correct' exercise.id %}" {% auto_link_css request.user_agent.is_mobile %}>
<span class="{% fa_class 'pencil-square-o' %}"></span>
{% trans "Submit a correction" %}
</a>
diff --git a/wger/gym/templates/gym/new_user.html b/wger/gym/templates/gym/new_user.html
index 5136a3f75..3e003cd70 100644
--- a/wger/gym/templates/gym/new_user.html
+++ b/wger/gym/templates/gym/new_user.html
@@ -53,7 +53,7 @@ cannot be recovered later.{% endblocktrans %}
</p>
<p>
- <a href="{% url 'gym:gym:new-user-data-export' %}" {% auto_link_css flavour %}>
+ <a href="{% url 'gym:gym:new-user-data-export' %}" {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Export user data" %}
</a>
</p>
diff --git a/wger/manager/templates/mobile/schedule/view.html b/wger/manager/templates/mobile/schedule/view.html
index aecda9983..5dcdc3f48 100644
--- a/wger/manager/templates/mobile/schedule/view.html
+++ b/wger/manager/templates/mobile/schedule/view.html
@@ -173,7 +173,7 @@ than once.{% endblocktrans %}</small></p>
application for example google calendar, outlook or iCal. This will create
an appointment for each training day with the appropriate exercises.{% endblocktrans %}</p>
<p>
- <a href="{% url 'manager:schedule:ical' schedule.id uid token %}" {% auto_link_css flavour %}>
+ <a href="{% url 'manager:schedule:ical' schedule.id uid token %}" {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Export calendar file" %}
</a>
</p>
@@ -289,4 +289,4 @@ an appointment for each training day with the appropriate exercises.{% endblockt
{% endif %}
</ul>
</div>
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/wger/manager/templates/mobile/tags/render_day.html b/wger/manager/templates/mobile/tags/render_day.html
index f02692ed0..f853096b0 100644
--- a/wger/manager/templates/mobile/tags/render_day.html
+++ b/wger/manager/templates/mobile/tags/render_day.html
@@ -13,27 +13,27 @@
<a href="{% url 'manager:day:log' day.obj.id %}"
title="{% trans 'Add weight log to this day' %}"
class="btn btn-default btn-block"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans 'Add weight log to this day' %}
</a>
{% if day.set_list|length > 0 %}
<a href="{% url 'manager:workout:timer' day.obj.id %}"
title="{% trans 'Start gym mode' %}"
class="btn btn-default btn-block"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Start gym mode" %}
</a>
{% endif %}
<a href="{% url 'manager:day:edit' day.obj.id %}"
title="{% trans 'Edit' %}"
class="btn btn-default btn-block"
- {% auto_link_css flavour "wger-modal-dialog" %}>
+ {% auto_link_css request.user_agent.is_mobile "wger-modal-dialog" %}>
{% trans 'Edit' %}
</a>
<a href="{% url 'manager:day:delete' day.obj.id %}"
title="{% trans 'Delete' %}"
class="btn btn-default btn-block"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Delete" %}
</a>
</div>
@@ -62,13 +62,13 @@
<a href="{% url 'manager:set:edit' set.obj.id %}"
title="{% trans 'Edit' %}"
class="btn btn-default btn-block"
- {% auto_link_css flavour "wger-modal-dialog" %}>
+ {% auto_link_css request.user_agent.is_mobile "wger-modal-dialog" %}>
{% trans "Edit" %}
</a>
<a href="{% url 'manager:set:delete' set.obj.id %}"
title="{% trans 'Delete' %}"
class="btn btn-default btn-block"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Delete" %}
</a>
@@ -77,7 +77,7 @@
<a href="{{ exercise.obj.get_absolute_url }}"
title="{{ exercise.obj.name }}"
class="btn btn-default btn-block"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{{ exercise.obj.name }}
</a>
{% endfor %}
diff --git a/wger/manager/templates/mobile/workout/view.html b/wger/manager/templates/mobile/workout/view.html
index c5d70971c..009004eba 100644
--- a/wger/manager/templates/mobile/workout/view.html
+++ b/wger/manager/templates/mobile/workout/view.html
@@ -74,13 +74,13 @@ $(document).ready(function() {
<p style="margin-top:2em;">
{% if is_owner %}
- <a href="{% url 'manager:day:add' workout.id %}" {% auto_link_css flavour "wger-modal-dialog" %}>
+ <a href="{% url 'manager:day:add' workout.id %}" {% auto_link_css request.user_agent.is_mobile "wger-modal-dialog" %}>
{% trans "Add training day" %}
</a>
<a id="exercise-comments-toggle"
href="{% url 'core:user:preferences' %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Show/Hide exercise comments" %}
</a>
{% endif %}
@@ -138,7 +138,7 @@ $(document).ready(function() {
application for example google calendar, outlook or iCal. This will create
an appointment for each training day with the appropriate exercises.{% endblocktrans %}</p>
<p>
- <a href="{% url 'manager:workout:ical' workout.id uid token %}" {% auto_link_css flavour %}>
+ <a href="{% url 'manager:workout:ical' workout.id uid token %}" {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Export calendar file" %}
</a>
</p>
diff --git a/wger/manager/views/set.py b/wger/manager/views/set.py
index f38c98b90..92de29ac4 100644
--- a/wger/manager/views/set.py
+++ b/wger/manager/views/set.py
@@ -34,6 +34,7 @@ from django.shortcuts import (
get_object_or_404,
render
)
+from django_user_agents.utils import get_user_agent
# wger
from wger.config.models import LanguageConfig
@@ -77,11 +78,12 @@ def create(request, day_pk):
if day.get_owner_object().user != request.user:
return HttpResponseForbidden()
- # Select the correct form depending on the flavour of the request.
+ # Select the correct form depending on the user-agent.
# The difference is that the mobile form doesn't use the autocompleter for
# exercises, but 2 dropdowns, one to filter by category and one to select
# the exercises themselves.
- if request.flavour == 'mobile':
+ user_agent = get_user_agent(request)
+ if user_agent.is_mobile:
form_class = SetFormMobile
else:
form_class = SetForm
@@ -92,7 +94,7 @@ def create(request, day_pk):
# For the mobile dropdown list we need to manually filter the exercises
# by language and status
- if request.flavour == 'mobile':
+ if user_agent.is_mobile:
languages = load_item_languages(LanguageConfig.SHOW_ITEM_EXERCISES)
form.fields['exercise_list'].queryset = Exercise.objects.accepted() \
.filter(language__in=languages)
diff --git a/wger/nutrition/templates/bmi/form.html b/wger/nutrition/templates/bmi/form.html
index 90038f4e3..9df10a4b6 100644
--- a/wger/nutrition/templates/bmi/form.html
+++ b/wger/nutrition/templates/bmi/form.html
@@ -26,14 +26,14 @@ div.bmi-legend {
<script>
$(document).ready(function () {
- wgerRenderBodyMassIndex({% if flavour == 'mobile'%}$('#content').width() * 0.95{% endif %});
+ wgerRenderBodyMassIndex({% if request.user_agent.is_mobile %}$('#content').width() * 0.95{% endif %});
/*
* Process the form
*/
$("#bmi-form").click(function(e){
e.preventDefault();
- wgerRenderBodyMassIndex({% if flavour == 'mobile'%}$('#content').width() * 0.95{% endif %});
+ wgerRenderBodyMassIndex({% if request.user_agent.is_mobile %}$('#content').width() * 0.95{% endif %});
});
});
diff --git a/wger/nutrition/templates/ingredient/overview.html b/wger/nutrition/templates/ingredient/overview.html
index 5386562a2..a28e94cc7 100644
--- a/wger/nutrition/templates/ingredient/overview.html
+++ b/wger/nutrition/templates/ingredient/overview.html
@@ -35,7 +35,7 @@
{% for ingredient in ingredients_list %}
<a class="list-group-item"
href="{{ ingredient.get_absolute_url }}">
- {% if flavour == 'mobile' %}
+ {% if request.user_agent.is_mobile %}
<span class="glyphicon glyphicon-chevron-right pull-right"></span>
{% endif %}
{{ ingredient.name }}
diff --git a/wger/nutrition/templates/ingredient/view.html b/wger/nutrition/templates/ingredient/view.html
index aa1b10f61..56b385d84 100644
--- a/wger/nutrition/templates/ingredient/view.html
+++ b/wger/nutrition/templates/ingredient/view.html
@@ -243,14 +243,14 @@ the search.{% endblocktrans %}
<li>
<a href="{% url 'nutrition:ingredient:edit' ingredient.id %}"
title="{% trans 'Edit ingredient' %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
<span class="{% fa_class 'pencil-square-o' %}"></span>
{% trans 'Edit ingredient' %}</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a href="{% url 'nutrition:ingredient:delete' ingredient.id %}"
- title="{% trans 'Delete ingredient' %}" {% auto_link_css flavour "wger-modal-dialog" %}>
+ title="{% trans 'Delete ingredient' %}" {% auto_link_css request.user_agent.is_mobile "wger-modal-dialog" %}>
<span class="{% fa_class 'trash' %}"></span>
{% trans 'Delete' %}</a>
</li>
diff --git a/wger/nutrition/templates/mobile/plan/view.html b/wger/nutrition/templates/mobile/plan/view.html
index 0bda54188..6be76c422 100644
--- a/wger/nutrition/templates/mobile/plan/view.html
+++ b/wger/nutrition/templates/mobile/plan/view.html
@@ -63,17 +63,17 @@ $(document).ready(function() {
<div class="modal-body">
<a href="{% url 'nutrition:meal:delete' meal.id %}"
title="{% trans 'Delete' %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Delete meal" %}
</a>
<a href="{% url 'nutrition:meal:edit' meal.id %}"
title="{% trans 'Edit' %}"
- {% auto_link_css flavour "wger-modal-dialog" %}>
+ {% auto_link_css request.user_agent.is_mobile "wger-modal-dialog" %}>
{% trans "Edit meal" %}
</a>
<a href="{% url 'nutrition:meal_item:add' meal.id %}"
title="{% trans 'Add' %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Add item to meal" %}
</a>
</div>
@@ -135,12 +135,12 @@ $(document).ready(function() {
<a href="{% url 'nutrition:meal_item:delete' item.id %}"
title="{% trans 'Delete' %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Delete" %}
</a>
<a href="{% url 'nutrition:meal_item:edit' item.id %}"
title="{% trans 'Edit' %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css request.user_agent.is_mobile %}>
{% trans "Edit" %}
</a>
</div>
@@ -202,7 +202,7 @@ $(document).ready(function() {
{% empty %}
{% if is_owner %}
<a href="{% url 'nutrition:meal:add' plan.id %}"
- {% auto_link_css flavour "wger-modal-dialog" %}>
+ {% auto_link_css request.user_agent.is_mobile "wger-modal-dialog" %}>
{% trans "No meals for this plan." %}<br>
{% trans "Add one now." %}
</a>
@@ -212,7 +212,7 @@ $(document).ready(function() {
{% if is_owner %}
<p style="margin-top:2em;">
<a href="{% url 'nutrition:meal:add' plan.id %}"
- {% auto_link_css flavour "wger-modal-dialog" %}>{% trans "Add a new meal" %}</a>
+ {% auto_link_css request.user_agent.is_mobile "wger-modal-dialog" %}>{% trans "Add a new meal" %}</a>
</p>
{% endif %}
diff --git a/wger/settings_global.py b/wger/settings_global.py
index 746fe7dd8..c7dcecf3b 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -67,8 +67,7 @@ INSTALLED_APPS = (
# The sitemaps app
'django.contrib.sitemaps',
- # Django mobile
- 'django_mobile',
+ 'django_user_agents',
# thumbnails
'easy_thumbnails',
@@ -120,6 +119,8 @@ MIDDLEWARE = (
# Javascript Header. Sends helper headers for AJAX
'wger.utils.middleware.JavascriptAJAXRedirectionMiddleware',
+ 'django_user_agents.middleware.UserAgentMiddleware',
+
# Custom authentication middleware. Creates users on-the-fly for certain paths
'wger.utils.middleware.WgerAuthenticationMiddleware',
@@ -129,10 +130,6 @@ MIDDLEWARE = (
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.locale.LocaleMiddleware',
-
- # Django mobile
- 'django_mobile.middleware.MobileDetectionMiddleware',
- 'django_mobile.middleware.SetFlavourMiddleware',
)
AUTHENTICATION_BACKENDS = (
@@ -157,16 +154,10 @@ TEMPLATES = [
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
- # Django mobile
- 'django_mobile.context_processors.flavour',
-
# Breadcrumbs
'django.template.context_processors.request'
],
'loaders': [
- # Django mobile
- 'django_mobile.loader.Loader',
-
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
@@ -383,6 +374,8 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
+USER_AGENTS_CACHE = 'default'
+
#
# Application specific configuration options
#
diff --git a/wger/weight/templates/overview.html b/wger/weight/templates/overview.html
index c1793b69f..82e346b23 100644
--- a/wger/weight/templates/overview.html
+++ b/wger/weight/templates/overview.html
@@ -105,7 +105,7 @@
</a>
</li>
<li>
- <a href="{% url 'weight:import-csv' %}" {% auto_link_css flavour %}>
+ <a href="{% url 'weight:import-csv' %}" {% auto_link_css request.user_agent.is_mobile %}>
<span class="{% fa_class 'upload' %}"></span>
{% trans "Import from spreadsheet" %}
</a>