Opening ths subtitle using absolute path and open function
authorsaksham1115 <saksham115@gmail.com>
Wed, 29 Jun 2016 11:18:34 +0000 (11:18 +0000)
committersaksham1115 <saksham115@gmail.com>
Tue, 19 Jul 2016 17:29:09 +0000 (17:29 +0000)
mediagoblin/edit/views.py
mediagoblin/tools/subtitles.py

index 33643bf8de6f00b1b5afed3fefdb89dafc5bcf69..ff5c0881637a80e5422247002a7316cb61988b04 100644 (file)
@@ -580,13 +580,14 @@ def edit_metadata(request, media):
          'media':media})
 
 
-from mediagoblin.tools.subtitles import get_path
+from mediagoblin.tools.subtitles import open_subtitle
 
 @require_active_login
 @path_subtitle
 def custom_subtitles(request,path=None):
-    form = forms.CustomizeSubtitlesForm(request.form)
-    path = get_path(path)
+    text = open_subtitle(path)
+    form = forms.CustomizeSubtitlesForm(request.form,
+                                         subtitle=text)
     return render_to_response(
         request,
         "mediagoblin/edit/custom_subtitles.html",
index 7002cdfceff234ec178022e79ecbeb67812dab1b..bfb4a7ea1a6b1c119c1266a7977c55b307076c09 100644 (file)
@@ -1,4 +1,4 @@
-import ast
+import ast,os
 
 def get_path(path):
        """
@@ -7,4 +7,20 @@ def get_path(path):
     to
     x = ["A", "B", "C", "D"] 
     """
-       return ast.literal_eval(path)
\ No newline at end of file
+       return ast.literal_eval(path)
+
+def open_subtitle(path):
+       temp = ['user_dev','media','public']
+       path = list(get_path(path))
+       file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary
+       """
+       Creating the absolute path for the subtitle file
+       """
+       subtitle_path = file_path[:-3] + temp + path
+       subtitle_path = "/" + os.path.join(*subtitle_path)
+       """
+       Opening the file using the absolute path
+       """
+       subtitle = open(subtitle_path,"r")
+       text = subtitle.read()
+       return text
\ No newline at end of file