2021-02-24 20:13:54 -08:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from .forms import EpisodeForm
|
2021-03-02 21:34:32 -08:00
|
|
|
from .models import Feed, Episode, rand_slug
|
|
|
|
from django.utils.text import slugify
|
2021-02-24 20:13:54 -08:00
|
|
|
|
|
|
|
|
|
|
|
def edit_episode(request, pk, title_slug):
|
|
|
|
if not request.user.is_authenticated:
|
|
|
|
return redirect('audio:home')
|
2021-03-02 21:34:32 -08:00
|
|
|
slug = title_slug
|
2021-02-24 20:13:54 -08:00
|
|
|
episode = Episode.objects.get(id=pk)
|
2021-03-02 21:34:32 -08:00
|
|
|
otitle = episode.title
|
2021-02-24 20:13:54 -08:00
|
|
|
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():
|
2021-03-02 21:34:32 -08:00
|
|
|
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)
|
2021-02-24 20:13:54 -08:00
|
|
|
else:
|
|
|
|
form = EpisodeForm(instance=episode)
|
|
|
|
return render(
|
|
|
|
request, 'base_form.html',
|
|
|
|
{
|
|
|
|
'form': form,
|
|
|
|
'heading': 'Edit Episode?',
|
|
|
|
'title': 'Edit Episode?',
|
|
|
|
'submit': 'save',
|
|
|
|
'form_data': 'TRUE',
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
def new_episode(request, feed_pk, feed_title_slug):
|
|
|
|
if not request.user.is_authenticated:
|
|
|
|
return redirect('audio:home')
|
|
|
|
feed = Feed.objects.get(id=feed_pk)
|
|
|
|
if not feed.user == request.user:
|
|
|
|
return redirect('audio:home')
|
|
|
|
if request.method == "POST":
|
|
|
|
form = EpisodeForm(request.POST, request.FILES)
|
|
|
|
if form.is_valid():
|
|
|
|
episode = form.save(commit=False)
|
|
|
|
episode.user = request.user
|
|
|
|
episode.feed = feed
|
|
|
|
episode.save()
|
2021-02-24 22:25:38 -08:00
|
|
|
return redirect('audio:feed', pk=feed_pk, slug=feed_title_slug)
|
2021-02-24 20:13:54 -08:00
|
|
|
else:
|
|
|
|
form = EpisodeForm()
|
|
|
|
return render(
|
|
|
|
request, 'base_form.html',
|
|
|
|
{
|
|
|
|
'form': form,
|
|
|
|
'heading': 'New Episode?',
|
|
|
|
'title': 'New Episode?',
|
|
|
|
'submit': 'submit',
|
|
|
|
'form_data': 'TRUE',
|
|
|
|
})
|