From b2ba593dbeeeee620ae8bb079eaf168e5dc7f0bf Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sat, 6 Aug 2016 11:22:11 +0000 Subject: [PATCH] Using subtitle id instead of subitle path in the url --- mediagoblin/plugins/subtitles/__init__.py | 4 +-- .../plugins/subtitles/custom_subtitles.html | 4 +-- .../subtitles/subtitle_media_block.html | 2 +- mediagoblin/plugins/subtitles/tools.py | 10 +++---- mediagoblin/plugins/subtitles/views.py | 26 +++++++++++-------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/mediagoblin/plugins/subtitles/__init__.py b/mediagoblin/plugins/subtitles/__init__.py index 75b0dbc4..d6f74668 100644 --- a/mediagoblin/plugins/subtitles/__init__.py +++ b/mediagoblin/plugins/subtitles/__init__.py @@ -24,13 +24,13 @@ def setup_plugin(): routes = [ ('mediagoblin.plugins.subtitles.customize', - '/u//m//customize/', + '/u//m//customize/', 'mediagoblin.plugins.subtitles.views:custom_subtitles'), ('mediagoblin.plugins.subtitles.subtitles', '/u//m//subtitles/', 'mediagoblin.plugins.subtitles.views:edit_subtitles'), ('mediagoblin.plugins.subtitles.delete_subtitles', - '/u//m//delete/', + '/u//m//delete/', 'mediagoblin.plugins.subtitles.views:delete_subtitles')] pluginapi.register_routes(routes) diff --git a/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/custom_subtitles.html b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/custom_subtitles.html index 2184b85e..8bd56461 100644 --- a/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/custom_subtitles.html +++ b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/custom_subtitles.html @@ -31,14 +31,14 @@
+ id=id) }}" method="POST" enctype="multipart/form-data">
{{ wtforms_util.render_divs(form) }}
{% set delete_url = request.urlgen('mediagoblin.plugins.subtitles.delete_subtitles', user= media.get_actor.username, media_id=media.id, - path=path) %} + id=id) %} {% trans %}Delete Subtitle{% endtrans %} {{ csrf_token }} diff --git a/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html index b516655a..fd0fd24e 100644 --- a/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html +++ b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html @@ -26,7 +26,7 @@ + id=subtitle.id ) }}"> {{- subtitle.name -}} {%- endfor %} diff --git a/mediagoblin/plugins/subtitles/tools.py b/mediagoblin/plugins/subtitles/tools.py index d9a5cb38..af32f270 100644 --- a/mediagoblin/plugins/subtitles/tools.py +++ b/mediagoblin/plugins/subtitles/tools.py @@ -17,19 +17,15 @@ from mediagoblin import mg_globals import os -def get_path(path): - path = eval(path) # Converting string to a tuple - return path - def open_subtitle(path): - subtitle_public_filepath = get_path(path) + subtitle_public_filepath = path with mg_globals.public_store.get_file( subtitle_public_filepath, 'rb') as subtitle_public_file: text = subtitle_public_file.read().decode('utf-8','ignore') return text def save_subtitle(path,text): - subtitle_public_filepath = get_path(path) + subtitle_public_filepath = path with mg_globals.public_store.get_file( subtitle_public_filepath, 'wb') as subtitle_public_file: - subtitle_public_file.write(text) + subtitle_public_file.write(text.encode('utf-8','ignore')) \ No newline at end of file diff --git a/mediagoblin/plugins/subtitles/views.py b/mediagoblin/plugins/subtitles/views.py index 9bab6ce6..a7f5cee5 100644 --- a/mediagoblin/plugins/subtitles/views.py +++ b/mediagoblin/plugins/subtitles/views.py @@ -35,7 +35,7 @@ from mediagoblin.tools.response import (render_to_response, import mimetypes -from mediagoblin.plugins.subtitles.tools import open_subtitle,save_subtitle,get_path +from mediagoblin.plugins.subtitles.tools import open_subtitle,save_subtitle UNSAFE_MIMETYPES = [ 'text/html', @@ -46,7 +46,7 @@ UNSAFE_MIMETYPES = [ @require_active_login def edit_subtitles(request, media): allowed_extensions = ['aqt','gsub','jss','sub','ttxt','pjs','psb', - 'rt','smi','rst','stl','ssf','srt','ssa','ass','usf','vtt','lrc'] + 'rt','smi','stl','ssf','srt','ssa','ass','usf','vtt','lrc'] form = forms.EditSubtitlesForm(request.form) # Add any subtitles @@ -116,8 +116,12 @@ def edit_subtitles(request, media): @require_active_login @get_media_entry_by_id @user_may_delete_media -def custom_subtitles(request,media,path=None): - path = request.matchdict['path'] +def custom_subtitles(request,media,id=None): + id = request.matchdict['id'] + path = "" + for subtitle in media.subtitle_files: + if subtitle["id"] == id: + path = subtitle["filepath"] text="" text = open_subtitle(path) form = forms.CustomizeSubtitlesForm(request.form, @@ -135,7 +139,7 @@ def custom_subtitles(request,media,path=None): return render_to_response( request, "mediagoblin/plugins/subtitles/custom_subtitles.html", - {"path": path, + {"id": id, "media": media, "form": form }) @@ -144,18 +148,18 @@ def custom_subtitles(request,media,path=None): @get_media_entry_by_id @user_may_delete_media def delete_subtitles(request,media): - path = request.matchdict['path'] - path = get_path(path) - mg_globals.public_store.delete_file(path) + id = request.matchdict['id'] delete_container = None index = 0 for subtitle in media.subtitle_files: - if str(subtitle["filepath"]) == str(path): + if subtitle["id"] == id: + path = subtitle["filepath"] + mg_globals.public_store.delete_file(path) delete_container = index - index += 1 media.subtitle_files.pop(delete_container) media.save() break + index += 1 messages.add_message( request, @@ -163,4 +167,4 @@ def delete_subtitles(request,media): ("Subtitle file deleted!!!")) return redirect(request, - location=media.url_for_self(request.urlgen)) + location=media.url_for_self(request.urlgen)) \ No newline at end of file -- 2.25.1