Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add render wrapper to inject mobile templates
Scott Peshakc2c4ee83a00b
diff --git a/wger/utils/helpers.py b/wger/utils/helpers.pyindex 8d0ef6625..2be09eb17 100644--- a/wger/utils/helpers.py+++ b/wger/utils/helpers.py@@ -35,6 +35,9 @@ from django.utils.http import (urlsafe_base64_encode)+from django.shortcuts import render+from django_user_agents.utils import get_user_agent+from django.template.exceptions import TemplateDoesNotExistlogger = logging.getLogger(__name__)@@ -235,3 +238,15 @@ def smart_capitalize(input):else:out.append(word)return ' '.join(out)+++def ua_aware_render(request, template, context):+ user_agent = get_user_agent(request)+ try_template = template+ if user_agent.is_mobile:+ try_template = 'mobile/' + template++ try:+ return render(request, try_template, context)+ except TemplateDoesNotExist:+ return render(request, template, context)