misc: add in-site episode management for animators
This commit is contained in:
		@ -3,6 +3,18 @@
 | 
			
		||||
{% load i18n aircox %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{% block top-nav-tools %}
 | 
			
		||||
{% has_perm page page.program.change_permission_codename simple=True as can_edit %}
 | 
			
		||||
{% if can_edit %}
 | 
			
		||||
<a class="navbar-item" href="{% url 'episode-edit' page.pk %}" target="_self">
 | 
			
		||||
    <span class="icon is-small">
 | 
			
		||||
        <i class="fa fa-pen"></i>
 | 
			
		||||
    </span> 
 | 
			
		||||
    <span>{% translate "Edit" %}</span>
 | 
			
		||||
</a>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content-container %}
 | 
			
		||||
{{ block.container }}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										30
									
								
								aircox/templates/aircox/episode_form.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								aircox/templates/aircox/episode_form.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
			
		||||
{% extends "aircox/basepage_detail.html" %}
 | 
			
		||||
{% load static i18n humanize honeypot aircox %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{% block head_extra %}
 | 
			
		||||
  {{ form.media }}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block init-scripts %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block top-nav-tools %}
 | 
			
		||||
<a class="navbar-item" href="{% url 'episode-detail' object.slug %}" target="_self">
 | 
			
		||||
    <span class="icon is-small">
 | 
			
		||||
        <i class="fa fa-eye"></i>
 | 
			
		||||
    </span> 
 | 
			
		||||
    <span>{% translate "View" %}</span>
 | 
			
		||||
</a>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block main %}
 | 
			
		||||
<form method="post" enctype="multipart/form-data">{% csrf_token %}
 | 
			
		||||
    <table>
 | 
			
		||||
        {{ form.as_table }}
 | 
			
		||||
        {% render_honeypot_field "website" %}
 | 
			
		||||
    </table>
 | 
			
		||||
    <br/>
 | 
			
		||||
    <input type="submit" value="Update" class="button is-success">
 | 
			
		||||
</form>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@ -25,12 +25,31 @@
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
{% if not object.content %}
 | 
			
		||||
    {% with object.parent.content as content %}
 | 
			
		||||
    {{ block.super }}
 | 
			
		||||
    {% endwith %}
 | 
			
		||||
{% else %}
 | 
			
		||||
    {{ block.super }}
 | 
			
		||||
{% block actions %}
 | 
			
		||||
{% if object.sound_set.public.count %}
 | 
			
		||||
<button class="button" @click="player.playButtonClick($event)"
 | 
			
		||||
        data-sounds="{{ object.podcasts|json }}">
 | 
			
		||||
    <span class="icon is-small">
 | 
			
		||||
        <span class="fas fa-play"></span>
 | 
			
		||||
    </span>
 | 
			
		||||
</button>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block actions %}
 | 
			
		||||
{% has_perm page object.program.change_permission_codename simple=True as can_edit %}
 | 
			
		||||
{% if can_edit %}
 | 
			
		||||
  <a class="button" href="{% url 'episode-edit' object.pk %}" target="_self">
 | 
			
		||||
    <span class="icon is-small"><i class="fas fa-pen" alt="{% trans 'edit' %}"></i></span>
 | 
			
		||||
  </a>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% if object.sound_set.public.count %}
 | 
			
		||||
<button class="button" @click="player.playButtonClick($event)"
 | 
			
		||||
        data-sounds="{{ object.podcasts|json }}">
 | 
			
		||||
    <span class="icon is-small">
 | 
			
		||||
        <span class="fas fa-play"></span>
 | 
			
		||||
    </span>
 | 
			
		||||
</button>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
@ -61,6 +61,11 @@ urls = [
 | 
			
		||||
        views.EpisodeDetailView.as_view(),
 | 
			
		||||
        name="episode-detail",
 | 
			
		||||
    ),
 | 
			
		||||
   path(
 | 
			
		||||
        _("episode/<pk>/edit/"),
 | 
			
		||||
        views.EpisodeUpdateView.as_view(),
 | 
			
		||||
        name="episode-edit",
 | 
			
		||||
    ),
 | 
			
		||||
    path(_("podcasts/"), views.PodcastListView.as_view(), name="podcast-list"),
 | 
			
		||||
    path(_("podcasts/c/<slug:category_slug>/"), views.PodcastListView.as_view(), name="podcast-list"),
 | 
			
		||||
    # ---- timetable
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,7 @@ from . import admin, errors
 | 
			
		||||
from .article import ArticleDetailView, ArticleListView
 | 
			
		||||
from .base import BaseAPIView, BaseView
 | 
			
		||||
from .diffusion import DiffusionListView, TimeTableView
 | 
			
		||||
from .episode import EpisodeDetailView, EpisodeListView, PodcastListView
 | 
			
		||||
from .episode import EpisodeDetailView, EpisodeListView, PodcastListView, EpisodeUpdateView
 | 
			
		||||
from .home import HomeView
 | 
			
		||||
from .log import LogListAPIView, LogListView
 | 
			
		||||
from .page import (
 | 
			
		||||
@ -32,6 +32,7 @@ __all__ = (
 | 
			
		||||
    "EpisodeDetailView",
 | 
			
		||||
    "EpisodeListView",
 | 
			
		||||
    "PodcastListView",
 | 
			
		||||
    "EpisodeUpdateView",
 | 
			
		||||
    "HomeView",
 | 
			
		||||
    "LogListAPIView",
 | 
			
		||||
    "LogListView",
 | 
			
		||||
 | 
			
		||||
@ -1,14 +1,24 @@
 | 
			
		||||
from django.shortcuts import reverse
 | 
			
		||||
from django.contrib.auth.mixins import UserPassesTestMixin
 | 
			
		||||
from django.forms import ModelForm, FileField
 | 
			
		||||
from django.urls import reverse
 | 
			
		||||
 | 
			
		||||
from ckeditor.fields import RichTextField
 | 
			
		||||
from filer.models.filemodels import File
 | 
			
		||||
 | 
			
		||||
from aircox.controllers.sound_file import SoundFile
 | 
			
		||||
 | 
			
		||||
from ..filters import EpisodeFilters
 | 
			
		||||
from ..models import Episode, Program, StaticPage
 | 
			
		||||
from .page import PageListView
 | 
			
		||||
from .program import ProgramPageDetailView
 | 
			
		||||
from .program import ProgramPageDetailView, BaseProgramMixin
 | 
			
		||||
from .page import PageUpdateView
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__all__ = (
 | 
			
		||||
    "EpisodeDetailView",
 | 
			
		||||
    "EpisodeListView",
 | 
			
		||||
    "PodcastListView",
 | 
			
		||||
    "EpisodeUpdateView",
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -39,3 +49,36 @@ class EpisodeListView(PageListView):
 | 
			
		||||
class PodcastListView(EpisodeListView):
 | 
			
		||||
    attach_to_value = StaticPage.Target.PODCASTS
 | 
			
		||||
    queryset = Episode.objects.published().with_podcasts().order_by("-pub_date")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class EpisodeForm(ModelForm):
 | 
			
		||||
    content = RichTextField()
 | 
			
		||||
    new_podcast = FileField(required=False)
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = Episode
 | 
			
		||||
        fields = ["content"]
 | 
			
		||||
 | 
			
		||||
    def save(self, commit=True):
 | 
			
		||||
        file_obj = self.cleaned_data["new_podcast"]
 | 
			
		||||
        if file_obj:
 | 
			
		||||
            obj, _ = File.objects.get_or_create(original_filename=file_obj.name, file=file_obj)
 | 
			
		||||
            sound_file = SoundFile(obj.path)
 | 
			
		||||
            sound_file.sync(
 | 
			
		||||
                program=self.instance.program, episode=self.instance, type=0, is_public=True, is_downloadable=True
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class EpisodeUpdateView(UserPassesTestMixin, BaseProgramMixin, PageUpdateView):
 | 
			
		||||
    model = Episode
 | 
			
		||||
    form_class = EpisodeForm
 | 
			
		||||
 | 
			
		||||
    def get_sidebar_queryset(self):
 | 
			
		||||
        return super().get_sidebar_queryset().filter(parent=self.program)
 | 
			
		||||
 | 
			
		||||
    def test_func(self):
 | 
			
		||||
        program = self.get_object().program
 | 
			
		||||
        return self.request.user.has_perm("aircox.%s" % program.change_permission_codename)
 | 
			
		||||
 | 
			
		||||
    def get_success_url(self):
 | 
			
		||||
        return reverse("episode-detail", kwargs={"slug": self.get_object().slug})
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user