misc: edit programs in site
This commit is contained in:
parent
1674266890
commit
c8b0d1c5fb
|
@ -2,6 +2,18 @@
|
||||||
{% comment %}Detail page of a show{% endcomment %}
|
{% comment %}Detail page of a show{% endcomment %}
|
||||||
{% load i18n aircox %}
|
{% load i18n aircox %}
|
||||||
|
|
||||||
|
{% block top-nav-tools %}
|
||||||
|
{% has_perm page page.change_permission_codename simple=True as can_edit %}
|
||||||
|
{% if can_edit %}
|
||||||
|
<a class="navbar-item" href="{% url 'program-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 content-container %}
|
||||||
{% with schedules=program.schedule_set.all %}
|
{% with schedules=program.schedule_set.all %}
|
||||||
{% if schedules %}
|
{% if schedules %}
|
||||||
|
|
23
aircox/templates/aircox/program_form.html
Normal file
23
aircox/templates/aircox/program_form.html
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{% extends "aircox/basepage_detail.html" %}
|
||||||
|
{% load static i18n humanize honeypot aircox %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block top-nav-tools %}
|
||||||
|
<a class="navbar-item" href="{% url 'program-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 %}
|
|
@ -1,5 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db()
|
@pytest.mark.django_db()
|
||||||
|
@ -23,3 +24,13 @@ def test_group_can_change_program(user, client, program):
|
||||||
user = User.objects.get(pk=user.pk) # reload user in order to have permissions set
|
user = User.objects.get(pk=user.pk) # reload user in order to have permissions set
|
||||||
assert program.editors in user.groups.all()
|
assert program.editors in user.groups.all()
|
||||||
assert user.has_perm("aircox.%s" % program.change_permission_codename)
|
assert user.has_perm("aircox.%s" % program.change_permission_codename)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db()
|
||||||
|
def test_group_change_program(user, client, program):
|
||||||
|
client.force_login(user)
|
||||||
|
response = client.get(reverse("program-edit", kwargs={"pk": program.pk}))
|
||||||
|
assert response.status_code == 403
|
||||||
|
user.groups.add(program.editors)
|
||||||
|
response = client.get(reverse("program-edit", kwargs={"pk": program.pk}))
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
17
aircox/tests/test_program.py
Normal file
17
aircox/tests/test_program.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import pytest
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db()
|
||||||
|
def test_edit_program(user, client, program):
|
||||||
|
client.force_login(user)
|
||||||
|
response = client.get(reverse("program-detail", kwargs={"slug": program.slug}))
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert "🖉 ".encode() not in response.content
|
||||||
|
user.groups.add(program.editors)
|
||||||
|
response = client.get(reverse("program-detail", kwargs={"slug": program.slug}))
|
||||||
|
assert "🖉 ".encode() in response.content
|
||||||
|
assert b"foobar" not in response.content
|
||||||
|
response = client.post(reverse("program-edit", kwargs={"pk": program.pk}), {"content": "foobar"})
|
||||||
|
response = client.get(reverse("program-detail", kwargs={"slug": program.slug}))
|
||||||
|
assert b"foobar" in response.content
|
|
@ -117,6 +117,11 @@ urls = [
|
||||||
path(_("podcasts/"), views.PodcastListView.as_view(), name="podcast-list"),
|
path(_("podcasts/"), views.PodcastListView.as_view(), name="podcast-list"),
|
||||||
path(_("podcasts/c/<slug:category_slug>/"), views.PodcastListView.as_view(), name="podcast-list"),
|
path(_("podcasts/c/<slug:category_slug>/"), views.PodcastListView.as_view(), name="podcast-list"),
|
||||||
# ---- others
|
# ---- others
|
||||||
|
path(
|
||||||
|
_("program/<pk>/edit/"),
|
||||||
|
views.ProgramUpdateView.as_view(),
|
||||||
|
name="program-edit",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"errors/no-station",
|
"errors/no-station",
|
||||||
views.errors.NoStationErrorView.as_view(),
|
views.errors.NoStationErrorView.as_view(),
|
||||||
|
|
|
@ -16,6 +16,7 @@ from .program import (
|
||||||
ProgramListView,
|
ProgramListView,
|
||||||
ProgramPageDetailView,
|
ProgramPageDetailView,
|
||||||
ProgramPageListView,
|
ProgramPageListView,
|
||||||
|
ProgramUpdateView,
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
@ -41,6 +42,7 @@ __all__ = (
|
||||||
"ProgramListView",
|
"ProgramListView",
|
||||||
"ProgramPageDetailView",
|
"ProgramPageDetailView",
|
||||||
"ProgramPageListView",
|
"ProgramPageListView",
|
||||||
|
"ProgramUpdateView",
|
||||||
"attached",
|
"attached",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import DetailView, ListView
|
from django.views.generic import DetailView, ListView
|
||||||
|
from django.views.generic.edit import UpdateView
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from honeypot.decorators import check_honeypot
|
from honeypot.decorators import check_honeypot
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ __all__ = [
|
||||||
"BasePageDetailView",
|
"BasePageDetailView",
|
||||||
"PageDetailView",
|
"PageDetailView",
|
||||||
"PageListView",
|
"PageListView",
|
||||||
|
"PageUpdateView",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,3 +182,10 @@ class PageDetailView(BasePageDetailView):
|
||||||
comment.page = self.object
|
comment.page = self.object
|
||||||
comment.save()
|
comment.save()
|
||||||
return self.get(request, *args, **kwargs)
|
return self.get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class PageUpdateView(BaseView, UpdateView):
|
||||||
|
context_object_name = "page"
|
||||||
|
|
||||||
|
def get_page(self):
|
||||||
|
return self.object
|
||||||
|
|
|
@ -46,6 +46,24 @@ class ProgramDetailView(BaseProgramMixin, PageDetailView):
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_template_names(self):
|
||||||
|
return super().get_template_names() + ["aircox/program_detail.html"]
|
||||||
|
|
||||||
|
|
||||||
|
class ProgramUpdateView(UserPassesTestMixin, BaseProgramMixin, PageUpdateView):
|
||||||
|
model = Program
|
||||||
|
fields = ["content"]
|
||||||
|
|
||||||
|
def get_sidebar_queryset(self):
|
||||||
|
return super().get_sidebar_queryset().filter(parent=self.program)
|
||||||
|
|
||||||
|
def test_func(self):
|
||||||
|
program = self.get_object()
|
||||||
|
return self.request.user.has_perm("aircox.%s" % program.change_permission_codename)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse("program-detail", kwargs={"slug": self.get_object().slug})
|
||||||
|
|
||||||
|
|
||||||
class ProgramListView(PageListView):
|
class ProgramListView(PageListView):
|
||||||
model = Program
|
model = Program
|
||||||
|
|
Loading…
Reference in New Issue
Block a user