diff options
author | saksham1115 <saksham115@gmail.com> | 2016-07-16 09:44:21 +0000 |
---|---|---|
committer | saksham1115 <saksham115@gmail.com> | 2016-07-19 17:29:25 +0000 |
commit | 5b42f9341a92344245dd503d2c128670d8097e22 (patch) | |
tree | c7ea7d9648bae6aec534bbe6121827890d88d186 /mediagoblin/plugins | |
parent | 443a8e18c82591975e85b597c3d07c86d047f7c2 (diff) | |
download | mediagoblin-5b42f9341a92344245dd503d2c128670d8097e22.tar.lz mediagoblin-5b42f9341a92344245dd503d2c128670d8097e22.tar.xz mediagoblin-5b42f9341a92344245dd503d2c128670d8097e22.zip |
Removed dependence on absolute path for editing
Diffstat (limited to 'mediagoblin/plugins')
-rw-r--r-- | mediagoblin/plugins/custom_subtitles/tools.py | 47 | ||||
-rw-r--r-- | mediagoblin/plugins/custom_subtitles/views.py | 40 |
2 files changed, 42 insertions, 45 deletions
diff --git a/mediagoblin/plugins/custom_subtitles/tools.py b/mediagoblin/plugins/custom_subtitles/tools.py index efafbeec..2cc5157f 100644 --- a/mediagoblin/plugins/custom_subtitles/tools.py +++ b/mediagoblin/plugins/custom_subtitles/tools.py @@ -1,20 +1,41 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from mediagoblin import mg_globals import os def get_path(path): - temp = ['user_dev','media','public'] - path = list(eval(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) - return subtitle_path + path = eval(path) # Converting string to a tuple + return path def open_subtitle(path): - subtitle_path = get_path(path) - subtitle = open(subtitle_path,"r") # Opening the file using the absolute path - text = subtitle.read() - return text + subtitle_public_filepath = get_path(path) + subtitle_public_file = mg_globals.public_store.get_file( + subtitle_public_filepath, 'rb') + try: + text = subtitle_public_file.read().decode('utf-8') + return text + finally: + subtitle_public_file.close() def save_subtitle(path,text): - subtitle_path = get_path(path) - subtitle = open(subtitle_path,"w") # Opening the file using the absolute path - subtitle.write(text)
\ No newline at end of file + subtitle_public_filepath = get_path(path) + subtitle_public_file = mg_globals.public_store.get_file( + subtitle_public_filepath, 'wb') + try: + subtitle_public_file.write(text) + finally: + subtitle_public_file.close()
\ No newline at end of file diff --git a/mediagoblin/plugins/custom_subtitles/views.py b/mediagoblin/plugins/custom_subtitles/views.py index ce540af0..e647df59 100644 --- a/mediagoblin/plugins/custom_subtitles/views.py +++ b/mediagoblin/plugins/custom_subtitles/views.py @@ -104,12 +104,16 @@ def edit_subtitles(request, media): @path_subtitle def custom_subtitles(request,media,path=None): text="" -# text = open_subtitle(path) + 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) + save_subtitle(path,subtitle_data) + messages.add_message( + request, + messages.SUCCESS, + ("Subtitle file changed!!!")) return render_to_response( request, "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", @@ -125,38 +129,10 @@ def custom_subtitles(request,media,path=None): index += 1 print media.subtitle_files.pop(delete_container) media.save()""" - + return render_to_response( request, "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", {"path": path, "media": media, - "form": form }) - -@require_active_login -@get_media_entry_by_id -@user_may_delete_media -@path_subtitle -def delete_subtitles(request,media,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) - - """delete_container = None - index = 0 - for subtitle in media.subtitle_files: - if subtitle["name"] == "Two And A Half Men S02E02.srt": - delete_container = index - index += 1 - print media.subtitle_files.pop(delete_container) - media.save()""" - - return render_to_response( - request, - "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", - {"path": path, - "media": media, - "form": form }) + "form": form })
\ No newline at end of file |