From 68a7a6e8523ced98c0afb5bfbea9bf6922ad909d Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Fri, 17 Jul 2015 19:01:23 +0200 Subject: [PATCH] detect iOS for download / streaming --- example/settings.py | 14 ++++++++++++++ setup.py | 1 + teleforma/exam/views.py | 1 - teleforma/templates/teleforma/course_media.html | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/example/settings.py b/example/settings.py index 534a6796..b840468a 100644 --- a/example/settings.py +++ b/example/settings.py @@ -111,6 +111,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.locale.LocaleMiddleware', 'pagination.middleware.PaginationMiddleware', + 'django_user_agents.middleware.UserAgentMiddleware', ) ROOT_URLCONF = 'urls' @@ -151,6 +152,7 @@ INSTALLED_APPS = ( # 'telecaster', 'extra_views', 'captcha', + 'django_user_agents', ) TEMPLATE_CONTEXT_PROCESSORS = ( @@ -217,3 +219,15 @@ SOUTH_MIGRATION_MODULES = { SUIT_CONFIG = { 'ADMIN_NAME': 'TeleForma Admin', } + +# Cache backend is optional, but recommended to speed up user agent parsing +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': '127.0.0.1:11211', + } +} + +# Name of cache backend to cache user agents. If it not specified default +# cache alias will be used. Set to `None` to disable caching. +USER_AGENTS_CACHE = 'default' diff --git a/setup.py b/setup.py index 278c7e6c..b695542f 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ setup( 'django-simple-captcha', 'django-suit', 'django-nvd3', + 'django-user-agents', ], platforms=['OS Independent'], license='CeCILL v2', diff --git a/teleforma/exam/views.py b/teleforma/exam/views.py index 86a6f261..83645477 100644 --- a/teleforma/exam/views.py +++ b/teleforma/exam/views.py @@ -66,7 +66,6 @@ class ScriptsView(ListView): context = super(ScriptsView, self).get_context_data(**kwargs) context['period'] = Period.objects.get(id=self.kwargs['period_id']) context['upload'] = getattr(settings, 'TELEFORMA_EXAM_SCRIPT_UPLOAD', True) - print self.request.user_agent.device return context @method_decorator(login_required) diff --git a/teleforma/templates/teleforma/course_media.html b/teleforma/templates/teleforma/course_media.html index 076032c6..a0755ad7 100644 --- a/teleforma/templates/teleforma/course_media.html +++ b/teleforma/templates/teleforma/course_media.html @@ -59,7 +59,7 @@ $(document).ready(function(){ {% block module-action %} {% if media.item.file and media.is_published or user.is_superuser or user.is_staff %} - {% if not "video" in media.mime_type or perms.telemeta.can_play_all_items %} + {% if not "video" in media.mime_type or perms.telemeta.can_play_all_items or request.user_agent.os.family == 'iOS' %}
 {% trans "Download" %}
-- 2.39.5