mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-11-22 01:21:30 -08:00
add delete to edit_episode
This commit is contained in:
parent
bc41ba62b0
commit
daa3247b73
@ -1,4 +1,5 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
from django.contrib import messages
|
||||||
from .forms import EpisodeForm
|
from .forms import EpisodeForm
|
||||||
from .models import Feed, Episode, rand_slug
|
from .models import Feed, Episode, rand_slug
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
@ -31,9 +32,27 @@ def edit_episode(request, pk, title_slug):
|
|||||||
'title': 'Edit Episode?',
|
'title': 'Edit Episode?',
|
||||||
'submit': 'save',
|
'submit': 'save',
|
||||||
'form_data': 'TRUE',
|
'form_data': 'TRUE',
|
||||||
|
'edit_episode': True,
|
||||||
|
'episode_pk': pk,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def confirm_delete_episode(request, pk):
|
||||||
|
if not request.user.is_authenticated:
|
||||||
|
return redirect('audio:home')
|
||||||
|
episode = Episode.objects.get(id=pk)
|
||||||
|
if not episode.user == request.user:
|
||||||
|
return redirect('audio:home')
|
||||||
|
if request.method == 'POST':
|
||||||
|
episode.delete()
|
||||||
|
messages.success(request, f'Episode {episode.title} deleted!', extra_tags='mb-0')
|
||||||
|
return redirect('audio:feed', pk=episode.feed.pk, slug=episode.feed.slug)
|
||||||
|
return render(request, 'audio/delete_episode_confirmation.html', {
|
||||||
|
'title': 'Delete Episode?',
|
||||||
|
'heading': 'Delete Episode?',
|
||||||
|
'episode': episode})
|
||||||
|
|
||||||
|
|
||||||
def new_episode(request, feed_pk, feed_title_slug):
|
def new_episode(request, feed_pk, feed_title_slug):
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return redirect('audio:home')
|
return redirect('audio:home')
|
||||||
|
20
audio/templates/audio/delete_episode_confirmation.html
Normal file
20
audio/templates/audio/delete_episode_confirmation.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{% include "base_navbar.html" %}
|
||||||
|
<div style="height: 10vh;"></div>
|
||||||
|
{% include "base_heading.html" %}
|
||||||
|
<div style="height: 30vh;" class="">
|
||||||
|
<h4 class="text-center mb-0 mt-5">Delete {{ episode.title }}?</h4>
|
||||||
|
<div class="h-100 col-sm-12 col-xs-12 d-flex justify-content-center align-content-center row p-0 mx-0">
|
||||||
|
<form method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="submit" class="btn btn-dark btn-lg mb-4" value="Delete"><br>
|
||||||
|
<a type="button" class="btn btn-lg btn-dark mt-3" href="{% url 'audio:feed' pk=episode.feed.pk slug=episode.feed.slug %}">Cancel</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -1,6 +1,6 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
from .episode_views import new_episode, edit_episode
|
from .episode_views import new_episode, edit_episode, confirm_delete_episode
|
||||||
from .feed_views import new_feed, edit_feed, confirm_delete_feed
|
from .feed_views import new_feed, edit_feed, confirm_delete_feed
|
||||||
from .audiorssfeed import AudioRssFeed
|
from .audiorssfeed import AudioRssFeed
|
||||||
|
|
||||||
@ -13,6 +13,7 @@ urlpatterns = [
|
|||||||
path('edit-feed/<str:pk>/<str:title_slug>', edit_feed, name='edit_feed'),
|
path('edit-feed/<str:pk>/<str:title_slug>', edit_feed, name='edit_feed'),
|
||||||
|
|
||||||
path('confirm-delete-feed/<str:pk>', confirm_delete_feed, name='confirm_delete_feed'),
|
path('confirm-delete-feed/<str:pk>', confirm_delete_feed, name='confirm_delete_feed'),
|
||||||
|
path('confirm-delete-episode/<str:pk>', confirm_delete_episode, name='confirm_delete_episode'),
|
||||||
|
|
||||||
path('new-episode/<str:feed_pk>/<str:feed_title_slug>', new_episode, name='new_episode'),
|
path('new-episode/<str:feed_pk>/<str:feed_title_slug>', new_episode, name='new_episode'),
|
||||||
path('edit-episode/<str:pk>/<str:title_slug>', edit_episode, name='edit_episode'),
|
path('edit-episode/<str:pk>/<str:title_slug>', edit_episode, name='edit_episode'),
|
||||||
|
@ -40,6 +40,8 @@
|
|||||||
<input type="submit" class="btn btn-dark btn-lg" value="{{ submit }}">
|
<input type="submit" class="btn btn-dark btn-lg" value="{{ submit }}">
|
||||||
{% if edit_feed %}
|
{% if edit_feed %}
|
||||||
<a type="button" class="btn btn-lg btn-dark" href="{% url 'audio:confirm_delete_feed' pk=feed_pk %}">Delete Feed?</a>
|
<a type="button" class="btn btn-lg btn-dark" href="{% url 'audio:confirm_delete_feed' pk=feed_pk %}">Delete Feed?</a>
|
||||||
|
{% elif edit_episode %}
|
||||||
|
<a type="button" class="btn btn-lg btn-dark" href="{% url 'audio:confirm_delete_episode' pk=episode_pk %}">Delete Episode?</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</form><br>
|
</form><br>
|
||||||
|
Loading…
Reference in New Issue
Block a user