Added the feature for deleting the subtitle
This commit is contained in:
parent
5b42f9341a
commit
eaeed602d3
@ -28,7 +28,10 @@ def setup_plugin():
|
|||||||
'mediagoblin.plugins.custom_subtitles.views:custom_subtitles'),
|
'mediagoblin.plugins.custom_subtitles.views:custom_subtitles'),
|
||||||
('mediagoblin.plugins.custom_subtitles.subtitles',
|
('mediagoblin.plugins.custom_subtitles.subtitles',
|
||||||
'/u/<string:user>/m/<int:media_id>/subtitles/',
|
'/u/<string:user>/m/<int:media_id>/subtitles/',
|
||||||
'mediagoblin.plugins.custom_subtitles.views:edit_subtitles')]
|
'mediagoblin.plugins.custom_subtitles.views:edit_subtitles'),
|
||||||
|
('mediagoblin.plugins.custom_subtitles.delete_subtitles',
|
||||||
|
'/u/<string:user>/m/<int:media_id>/delete/<string:path>',
|
||||||
|
'mediagoblin.plugins.custom_subtitles.views:delete_subtitles')]
|
||||||
|
|
||||||
pluginapi.register_routes(routes)
|
pluginapi.register_routes(routes)
|
||||||
|
|
||||||
|
@ -35,6 +35,11 @@
|
|||||||
<div class="form_box edit_box">
|
<div class="form_box edit_box">
|
||||||
{{ wtforms_util.render_divs(form) }}
|
{{ wtforms_util.render_divs(form) }}
|
||||||
<div class="form_submit_buttons">
|
<div class="form_submit_buttons">
|
||||||
|
{% set delete_url = request.urlgen('mediagoblin.plugins.custom_subtitles.delete_subtitles',
|
||||||
|
user= media.get_actor.username,
|
||||||
|
media_id=media.id,
|
||||||
|
path=path) %}
|
||||||
|
<a class="button_action button_warning" href="{{ delete_url }}">{% trans %}Delete Subtitle{% endtrans %}</a>
|
||||||
<input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" />
|
<input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" />
|
||||||
{{ csrf_token }}
|
{{ csrf_token }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -35,7 +35,7 @@ from mediagoblin.tools.response import (render_to_response,
|
|||||||
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
|
||||||
from mediagoblin.plugins.custom_subtitles.tools import open_subtitle,save_subtitle
|
from mediagoblin.plugins.custom_subtitles.tools import open_subtitle,save_subtitle,get_path
|
||||||
|
|
||||||
UNSAFE_MIMETYPES = [
|
UNSAFE_MIMETYPES = [
|
||||||
'text/html',
|
'text/html',
|
||||||
@ -121,18 +121,36 @@ def custom_subtitles(request,media,path=None):
|
|||||||
"media": media,
|
"media": media,
|
||||||
"form": form })
|
"form": form })
|
||||||
|
|
||||||
"""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(
|
return render_to_response(
|
||||||
request,
|
request,
|
||||||
"mediagoblin/plugins/custom_subtitles/custom_subtitles.html",
|
"mediagoblin/plugins/custom_subtitles/custom_subtitles.html",
|
||||||
{"path": path,
|
{"path": path,
|
||||||
"media": media,
|
"media": media,
|
||||||
"form": form })
|
"form": form })
|
||||||
|
|
||||||
|
|
||||||
|
@require_active_login
|
||||||
|
@get_media_entry_by_id
|
||||||
|
@user_may_delete_media
|
||||||
|
@path_subtitle
|
||||||
|
def delete_subtitles(request,media,path=None):
|
||||||
|
|
||||||
|
path = get_path(path)
|
||||||
|
mg_globals.public_store.delete_file(path)
|
||||||
|
delete_container = None
|
||||||
|
index = 0
|
||||||
|
for subtitle in media.subtitle_files:
|
||||||
|
if str(subtitle["filepath"]) == str(path):
|
||||||
|
delete_container = index
|
||||||
|
index += 1
|
||||||
|
media.subtitle_files.pop(delete_container)
|
||||||
|
media.save()
|
||||||
|
break
|
||||||
|
|
||||||
|
messages.add_message(
|
||||||
|
request,
|
||||||
|
messages.SUCCESS,
|
||||||
|
("Subtitle file deleted!!!"))
|
||||||
|
|
||||||
|
return redirect(request,
|
||||||
|
location=media.url_for_self(request.urlgen))
|
Loading…
x
Reference in New Issue
Block a user