mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-12-22 13:02:49 -08:00
add link for more from feed, add updating of slug if episode or feed title change
This commit is contained in:
parent
9d47561b0b
commit
d1653e5ac0
@ -1,19 +1,26 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from .forms import EpisodeForm
|
||||
from .models import Feed, Episode
|
||||
from .models import Feed, Episode, rand_slug
|
||||
from django.utils.text import slugify
|
||||
|
||||
|
||||
def edit_episode(request, pk, title_slug):
|
||||
if not request.user.is_authenticated:
|
||||
return redirect('audio:home')
|
||||
slug = title_slug
|
||||
episode = Episode.objects.get(id=pk)
|
||||
otitle = episode.title
|
||||
if not episode.user == request.user:
|
||||
return redirect('audio:home')
|
||||
if request.method == "POST":
|
||||
form = EpisodeForm(request.POST, request.FILES, instance=episode)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('audio:episode', pk=pk, slug=title_slug)
|
||||
nepisode = form.save(commit=False)
|
||||
if nepisode.title != otitle:
|
||||
nepisode.slug = slugify(rand_slug() + "-" + nepisode.title)
|
||||
slug = nepisode.slug
|
||||
nepisode.save()
|
||||
return redirect('audio:episode', pk=pk, slug=slug)
|
||||
else:
|
||||
form = EpisodeForm(instance=episode)
|
||||
return render(
|
||||
|
@ -66,6 +66,11 @@
|
||||
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% if is_episode %}
|
||||
<div class="text-center">
|
||||
More from <a href="{% url 'audio:feed' pk=feed.id slug=feed.slug %}">{{ feed.title }}</a>?
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-0 col-sm-3">
|
||||
</div>
|
||||
@ -74,33 +79,3 @@
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% for j in episodes %}
|
||||
<div class="container text-center">
|
||||
<h3>
|
||||
{{ j.title }}
|
||||
</h3>
|
||||
<a href="{% url 'audio:episode' pk=j.pk slug=j.slug %}">{{ j.title }}</a>
|
||||
<p>
|
||||
{{ j.pub_date }}
|
||||
</p>
|
||||
<p>
|
||||
{{ j.description }}
|
||||
</p>
|
||||
<div class="container w-25 h-25">
|
||||
<img class="w-50 h-50" src="{{ IMAGES_URL }}{{ j.image }}">
|
||||
</div>
|
||||
<a href="{% url 'audio:rss' slug=j.feed.slug %}">RSS</a><br>
|
||||
<audio controls class="btn btn-dark">
|
||||
<source src="{{ MP3_URL }}{{ j.mp3 }}" type="audio/mpeg">
|
||||
Your browser does not support the audio tag.
|
||||
</audio>
|
||||
{% if user.is_authenticated %}
|
||||
{% if user == j.user %}
|
||||
<div class="container w-25 h-25 mt-3">
|
||||
<a href="{% url 'audio:edit_episode' pk=j.pk title_slug=j.slug %}">Edit Episode?</a><br>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -1,7 +1,8 @@
|
||||
from django.shortcuts import render, redirect, reverse
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from .forms import FeedForm
|
||||
from .models import Feed, Episode
|
||||
from django.utils.text import slugify
|
||||
from .models import Feed, Episode, rand_slug
|
||||
from tp.settings import IMAGES_URL, MP3_URL
|
||||
|
||||
|
||||
@ -34,7 +35,7 @@ def episode(request, pk, slug):
|
||||
{
|
||||
'episodes': (episode, ), 'IMAGES_URL': IMAGES_URL, 'is_episode': True,
|
||||
'MP3_URL': MP3_URL, 'title': episode.title, 'heading': episode.title,
|
||||
'ogtitle': episode.title, 'ogurl': og_url, 'ogmp3': episode.mp3
|
||||
'ogtitle': episode.title, 'ogurl': og_url, 'ogmp3': episode.mp3, 'feed': episode.feed
|
||||
})
|
||||
|
||||
|
||||
@ -64,14 +65,20 @@ def new_feed(request):
|
||||
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():
|
||||
feed.save()
|
||||
return redirect('audio:feed', pk=pk, slug=title_slug)
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user