Repository: fossasia/open-event-server

Issue:
Link for Video/Slides/Audio missing - Implement option a) Upload or b) Link
Currently the link for video, slides, audio cannot be provided as only an upload option is available in the sessions form. 

Please provide an option either link or upload.

![screenshot from 2017-04-14 14-05-25](https://cloud.githubusercontent.com/assets/1583873/25042857/b2d80162-211b-11e7-9032-376a505150c0.png)



Discussion:

Resolving patch:
diff --git a/app/helpers/data.py b/app/helpers/data.py
--- a/app/helpers/data.py
+++ b/app/helpers/data.py
@@ -25,7 +25,8 @@
     trigger_session_state_change_notifications
 from app.helpers.oauth import OAuth, FbOAuth, InstagramOAuth, TwitterOAuth
 from app.helpers.sessions_speakers.speakers import save_speaker
-from app.helpers.storage import upload, UPLOAD_PATHS, UploadedFile, upload_local
+from app.helpers.storage import upload, UPLOAD_PATHS, UploadedFile, upload_local, \
+    is_external_file
 from app.helpers import helpers as Helper
 from app.helpers.data_getter import DataGetter
 from app.helpers.system_mails import MAILS
@@ -210,13 +211,13 @@ def add_session_to_event(request, event_id, state=None, use_current_user=True, n
         video_file = ''
         audio_file = ''
 
-        if slide_temp_url:
+        if slide_temp_url and not is_external_file(slide_temp_url):
             slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1])
 
-        if video_temp_url:
+        if video_temp_url and not is_external_file(video_temp_url):
             video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1])
 
-        if audio_temp_url:
+        if audio_temp_url and not is_external_file(audio_temp_url):
             audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1])
 
         if not state:
@@ -259,27 +260,36 @@ def add_session_to_event(request, event_id, state=None, use_current_user=True, n
         if state == 'pending':
             trigger_new_session_notifications(new_session.id, event=event)
 
-        if slide_temp_url != "" and slide_file:
-            slide_url = upload(
-                slide_file,
-                UPLOAD_PATHS['sessions']['slides'].format(
-                    event_id=int(event_id), id=int(new_session.id)
-                ))
-            new_session.slides = slide_url
-        if audio_temp_url != "" and audio_file:
-            audio_url = upload(
-                audio_file,
-                UPLOAD_PATHS['sessions']['audio'].format(
-                    event_id=int(event_id), id=int(new_session.id)
-                ))
-            new_session.audio = audio_url
-        if video_temp_url != "" and video_file:
-            video_url = upload(
-                video_file,
-                UPLOAD_PATHS['sessions']['video'].format(
+        if slide_temp_url:
+            if slide_file:
+                slide_file = upload(
+                    slide_file,
+                    UPLOAD_PATHS['sessions']['slides'].format(
                     event_id=int(event_id), id=int(new_session.id)
                 ))
-            new_session.video = video_url
+            else:
+                slide_file = slide_temp_url
+            new_session.slides = slide_file
+        if audio_temp_url:
+            if audio_file:
+                audio_file = upload(
+                    audio_file,
+                    UPLOAD_PATHS['sessions']['audio'].format(
+                        event_id=int(event_id), id=int(new_session.id)
+                    ))
+            else:
+                audio_file = audio_temp_url
+            new_session.audio = audio_file
+        if video_temp_url:
+            if video_file:
+                video_file = upload(
+                    video_file,
+                    UPLOAD_PATHS['sessions']['video'].format(
+                        event_id=int(event_id), id=int(new_session.id)
+                    ))
+            else:
+                video_file = video_temp_url
+            new_session.video = video_file
         record_activity('create_session', session=new_session, event_id=event_id)
         update_version(event_id, False, 'sessions_ver')
 
@@ -366,42 +376,43 @@ def edit_session(request, session, speaker=None):
             slide_temp_url = form.get('slides_url')
             video_temp_url = form.get('video_url')
             audio_temp_url = form.get('audio_url')
+
             slide_file = ''
             video_file = ''
             audio_file = ''
 
-            if slide_temp_url and slide_temp_url != session.slides:
+            if slide_temp_url and slide_temp_url != session.slides and not is_external_file(slide_temp_url):
                 slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1])
 
-            if video_temp_url and video_temp_url != session.video:
+            if video_temp_url and video_temp_url != session.video and not is_external_file(video_temp_url):
                 video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1])
 
-            if audio_temp_url and audio_temp_url != session.audio:
+            if audio_temp_url and audio_temp_url != session.audio and not is_external_file(audio_temp_url):
                 audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1])
 
             form_state = form.get('state', 'draft')
 
-            if slide_temp_url != "" and slide_temp_url != session.slides and slide_file:
+            if slide_file:
                 slide_temp_url = upload(slide_file,
-                                        UPLOAD_PATHS['sessions']['slides'].format(
-                                            event_id=int(event_id), id=int(session.id)
-                                        ))
-            if audio_temp_url != "" and audio_temp_url != session.audio and audio_file:
-                audio_temp_url = upload(
-                    audio_file,
-                    UPLOAD_PATHS['sessions']['audio'].format(
-                        event_id=int(event_id), id=int(session.id)
-                    ))
-            if video_temp_url != "" and video_temp_url != session.video and video_file:
+                                    UPLOAD_PATHS['sessions']['slides'].format(
+                                        event_id=int(event_id), id=int(session.id)
+                                    ))
+            if video_file:
                 video_temp_url = upload(
                     video_file,
                     UPLOAD_PATHS['sessions']['video'].format(
                         event_id=int(event_id), id=int(session.id)
                     ))
+            if audio_file:
+                audio_temp_url = upload(
+                    audio_file,
+                    UPLOAD_PATHS['sessions']['audio'].format(
+                        event_id=int(event_id), id=int(session.id)
+                    ))
 
-            session.slides = slide_temp_url
             session.audio = audio_temp_url
             session.video = video_temp_url
+            session.slides = slide_temp_url
 
             if form_state == 'pending' and session.state != 'pending' and \
                     session.state != 'accepted' and session.state != 'rejected' and session.state != 'confirmed':
diff --git a/app/helpers/flask_ext/jinja/filters.py b/app/helpers/flask_ext/jinja/filters.py
--- a/app/helpers/flask_ext/jinja/filters.py
+++ b/app/helpers/flask_ext/jinja/filters.py
@@ -135,3 +135,10 @@ def filename_from_url(url):
         if url:
             return url.rsplit('/', 1)[1]
         return ""
+
+    @app.template_filter('is_external_url')
+    def is_external_url(url):
+        if url:
+            if ('http://' in url) or ('https://' in url):
+                return "external_url"
+        return "no_external_url"
diff --git a/app/helpers/storage.py b/app/helpers/storage.py
--- a/app/helpers/storage.py
+++ b/app/helpers/storage.py
@@ -219,6 +219,9 @@ def upload_to_gs(bucket_name, client_id, client_secret, file, key, acl='public-r
         return gs_url + k.key
     return False
 
+def is_external_file(filename):
+    return ('http://' in filename) or ('https://' in filename)
+
 
 # ########
 # HELPERS


Test patch: