Saing subtitle after edit
authorsaksham1115 <saksham115@gmail.com>
Mon, 11 Jul 2016 06:46:12 +0000 (06:46 +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 ff5c0881637a80e5422247002a7316cb61988b04..9ab4a60cfa790915008f35ae45e8b6acb8114e26 100644 (file)
@@ -580,7 +580,7 @@ def edit_metadata(request, media):
          'media':media})
 
 
-from mediagoblin.tools.subtitles import open_subtitle
+from mediagoblin.tools.subtitles import open_subtitle,save_subtitle
 
 @require_active_login
 @path_subtitle
@@ -588,6 +588,10 @@ def custom_subtitles(request,path=None):
     text = open_subtitle(path)
     form = forms.CustomizeSubtitlesForm(request.form,
                                          subtitle=text)
+    if request.method == 'POST' and form.validate():
+        subtitle_data = form.subtitle.data
+        save_subtitle(path,subtitle_data)
+
     return render_to_response(
         request,
         "mediagoblin/edit/custom_subtitles.html",
index 2888fe99591fa263c037e1c83ebfacb12e1622e3..7fcf5f111c0a72e9c6be0fc8a573a1b29c4385d0 100644 (file)
@@ -11,4 +11,13 @@ def open_subtitle(path):
        subtitle_path = "/" + os.path.join(*subtitle_path)
        subtitle = open(subtitle_path,"r") # Opening the file using the absolute path
        text = subtitle.read()
-       return text
\ No newline at end of file
+       return text
+
+def save_subtitle(path,text):
+       temp = ['user_dev','media','public']
+       path = list(get_path(path))
+       file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary
+       subtitle_path = file_path[:-3] + temp + path # Creating the absolute path for the subtitle file
+       subtitle_path = "/" + os.path.join(*subtitle_path)
+       subtitle = open(subtitle_path,"w") # Opening the file using the absolute path
+       subtitle.write(text)
\ No newline at end of file