Saing subtitle after edit

This commit is contained in:
saksham1115 2016-07-11 06:46:12 +00:00
parent 1ba4556b90
commit a8902a5edb
2 changed files with 15 additions and 2 deletions

View 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",

View 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
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)