mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-11-21 17:11:30 -08:00
add delete to edit_feed
This commit is contained in:
parent
5d6ae12550
commit
bc41ba62b0
68
audio/feed_views.py
Normal file
68
audio/feed_views.py
Normal file
@ -0,0 +1,68 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from .forms import FeedForm
|
||||
from .models import Feed, rand_slug
|
||||
from django.contrib import messages
|
||||
from django.utils.text import slugify
|
||||
|
||||
|
||||
def new_feed(request):
|
||||
if not request.user.is_authenticated:
|
||||
return redirect('audio:home')
|
||||
if request.method == "POST":
|
||||
form = FeedForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
feed = form.save(commit=False)
|
||||
feed.user = request.user
|
||||
feed.save()
|
||||
return redirect('audio:home')
|
||||
else:
|
||||
form = FeedForm()
|
||||
return render(request, 'base_form.html', {'form': form})
|
||||
|
||||
|
||||
def confirm_delete_feed(request, pk):
|
||||
if not request.user.is_authenticated:
|
||||
return redirect('audio:home')
|
||||
feed = Feed.objects.get(id=pk)
|
||||
if not feed.user == request.user:
|
||||
return redirect('audio:home')
|
||||
if request.method == 'POST':
|
||||
feed.delete()
|
||||
messages.success(request, f'Feed {feed.title} deleted!', extra_tags='mb-0')
|
||||
return redirect('audio:feeds')
|
||||
return render(request, 'audio/delete_feed_confirmation.html', {
|
||||
'title': 'Delete Feed?',
|
||||
'heading': 'Delete Feed?',
|
||||
'feed': feed})
|
||||
|
||||
|
||||
def edit_feed(request, pk, title_slug):
|
||||
if not request.user.is_authenticated:
|
||||
return redirect('audio:home')
|
||||
slug = title_slug
|
||||
feed = Feed.objects.get(id=pk)
|
||||
otitle = feed.title
|
||||
if not feed.user == request.user:
|
||||
return redirect('audio:home')
|
||||
if request.method == "POST":
|
||||
form = FeedForm(request.POST, request.FILES, instance=feed)
|
||||
if form.is_valid():
|
||||
nfeed = form.save(commit=False)
|
||||
if nfeed.title != otitle:
|
||||
nfeed.slug = slugify(rand_slug() + "-" + nfeed.title)
|
||||
slug = nfeed.slug
|
||||
nfeed.save()
|
||||
return redirect('audio:feed', pk=pk, slug=slug)
|
||||
else:
|
||||
form = FeedForm(instance=feed)
|
||||
return render(
|
||||
request, 'base_form.html',
|
||||
{
|
||||
'form': form,
|
||||
'heading': 'Edit Feed?',
|
||||
'title': 'Edit Feed?',
|
||||
'submit': 'save',
|
||||
'form_data': 'TRUE',
|
||||
'edit_feed': True,
|
||||
'feed_pk': pk,
|
||||
})
|
20
audio/templates/audio/delete_feed_confirmation.html
Normal file
20
audio/templates/audio/delete_feed_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 {{ feed.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:feeds' %}">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,15 +1,19 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
from .episode_views import new_episode, edit_episode
|
||||
from .feed_views import new_feed, edit_feed, confirm_delete_feed
|
||||
from .audiorssfeed import AudioRssFeed
|
||||
|
||||
app_name = "audio"
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.home, name='home'),
|
||||
path('new-feed/', views.new_feed, name='new_feed'),
|
||||
path('new-feed/', new_feed, name='new_feed'),
|
||||
path('feeds/', views.feeds, name='feeds'),
|
||||
path('edit-feed/<str:pk>/<str:title_slug>', views.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('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('rss/<str:slug>.xml', AudioRssFeed(), name='rss'),
|
||||
|
@ -1,8 +1,6 @@
|
||||
from django.shortcuts import render, redirect, reverse
|
||||
from django.shortcuts import render, reverse
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from .forms import FeedForm
|
||||
from django.utils.text import slugify
|
||||
from .models import Feed, Episode, rand_slug
|
||||
from .models import Feed, Episode
|
||||
from tp.settings import IMAGES_URL, MP3_URL
|
||||
|
||||
|
||||
@ -47,48 +45,3 @@ def feeds(request):
|
||||
request,
|
||||
'audio/feeds.html',
|
||||
{'feeds': feeds, 'IMAGES_URL': IMAGES_URL})
|
||||
|
||||
|
||||
def new_feed(request):
|
||||
if not request.user.is_authenticated:
|
||||
return redirect('audio:home')
|
||||
if request.method == "POST":
|
||||
form = FeedForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
feed = form.save(commit=False)
|
||||
feed.user = request.user
|
||||
feed.save()
|
||||
return redirect('audio:home')
|
||||
else:
|
||||
form = FeedForm()
|
||||
return render(request, 'base_form.html', {'form': form})
|
||||
|
||||
|
||||
def edit_feed(request, pk, title_slug):
|
||||
if not request.user.is_authenticated:
|
||||
return redirect('audio:home')
|
||||
slug = title_slug
|
||||
feed = Feed.objects.get(id=pk)
|
||||
otitle = feed.title
|
||||
if not feed.user == request.user:
|
||||
return redirect('audio:home')
|
||||
if request.method == "POST":
|
||||
form = FeedForm(request.POST, request.FILES, instance=feed)
|
||||
if form.is_valid():
|
||||
nfeed = form.save(commit=False)
|
||||
if nfeed.title != otitle:
|
||||
nfeed.slug = slugify(rand_slug() + "-" + nfeed.title)
|
||||
slug = nfeed.slug
|
||||
nfeed.save()
|
||||
return redirect('audio:feed', pk=pk, slug=slug)
|
||||
else:
|
||||
form = FeedForm(instance=feed)
|
||||
return render(
|
||||
request, 'base_form.html',
|
||||
{
|
||||
'form': form,
|
||||
'heading': 'Edit Feed?',
|
||||
'title': 'Edit Feed?',
|
||||
'submit': 'save',
|
||||
'form_data': 'TRUE',
|
||||
})
|
||||
|
@ -36,8 +36,11 @@
|
||||
{% endif %}
|
||||
{% csrf_token %}
|
||||
{{ form | crispy }}
|
||||
<div class="mt-3">
|
||||
<div class="mt-3 d-flex justify-content-between">
|
||||
<input type="submit" class="btn btn-dark btn-lg" value="{{ submit }}">
|
||||
{% if edit_feed %}
|
||||
<a type="button" class="btn btn-lg btn-dark" href="{% url 'audio:confirm_delete_feed' pk=feed_pk %}">Delete Feed?</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form><br>
|
||||
{% if request.path == edit_profile_url %}
|
||||
|
Loading…
Reference in New Issue
Block a user