You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/11/11 21:12:09 UTC

[airavata-django-portal] branch master updated: AIRAVATA-3265 Redirect to direct url for PDF

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/master by this push:
     new 51e6b4a  AIRAVATA-3265 Redirect to direct url for PDF
51e6b4a is described below

commit 51e6b4a029bd94e26b58b087eb34c862d50a2932
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Nov 11 16:11:50 2019 -0500

    AIRAVATA-3265 Redirect to direct url for PDF
---
 django_airavata/wagtailapps/base/wagtail_hooks.py | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/django_airavata/wagtailapps/base/wagtail_hooks.py b/django_airavata/wagtailapps/base/wagtail_hooks.py
index 996a79e..124f976 100644
--- a/django_airavata/wagtailapps/base/wagtail_hooks.py
+++ b/django_airavata/wagtailapps/base/wagtail_hooks.py
@@ -1,9 +1,13 @@
+import logging
+
 import wagtail.admin.rich_text.editors.draftail.features as draftail_features
-from wagtail.admin.rich_text.converters.html_to_contentstate import (
+from django.shortcuts import redirect
+from wagtail.admin.rich_text.converters.html_to_contentstate import \
     InlineStyleElementHandler
-)
 from wagtail.core import hooks
 
+logger = logging.getLogger(__name__)
+
 
 @hooks.register('register_rich_text_features')
 def register_custom_style_feature(features):
@@ -37,3 +41,18 @@ def register_custom_style_feature(features):
         'contentstate', feature_name, db_conversion)
 
     features.default_features.append(feature_name)
+
+
+DIRECT_SERVE_FILE_EXTENSIONS = ["pdf"]
+
+
+@hooks.register('before_serve_document')
+def direct_serve_document(document, request):
+    try:
+        file_extension = document.file.name.split(".")[-1]
+        if (file_extension in DIRECT_SERVE_FILE_EXTENSIONS and
+                'download' not in request.GET):
+            return redirect(document.file.url)
+    except Exception as e:
+        logger.warning("direct_serve_document error: ", exc_info=e)
+        return None