mirror of
https://github.com/ae-utbm/sith.git
synced 2025-04-25 02:48:01 +00:00
fix com admin pages
This commit is contained in:
parent
98e470fa2a
commit
b0e24350e2
@ -19,7 +19,7 @@ import pytest
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.test import TestCase
|
from django.test import Client, TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import html
|
from django.utils import html
|
||||||
from django.utils.timezone import localtime, now
|
from django.utils.timezone import localtime, now
|
||||||
@ -323,7 +323,7 @@ class TestNewsCreation(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_feed(client):
|
def test_feed(client: Client):
|
||||||
"""Smoke test that checks that the atom feed is working"""
|
"""Smoke test that checks that the atom feed is working"""
|
||||||
Site.objects.clear_cache()
|
Site.objects.clear_cache()
|
||||||
with assertNumQueries(2):
|
with assertNumQueries(2):
|
||||||
@ -332,3 +332,22 @@ def test_feed(client):
|
|||||||
resp = client.get(reverse("com:news_feed"))
|
resp = client.get(reverse("com:news_feed"))
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert resp.headers["Content-Type"] == "application/rss+xml; charset=utf-8"
|
assert resp.headers["Content-Type"] == "application/rss+xml; charset=utf-8"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"url",
|
||||||
|
[
|
||||||
|
reverse("com:poster_list"),
|
||||||
|
reverse("com:poster_create"),
|
||||||
|
reverse("com:poster_moderate_list"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_poster_management_views_crash_test(client: Client, url: str):
|
||||||
|
"""Test that poster management views work"""
|
||||||
|
user = baker.make(
|
||||||
|
User, groups=[Group.objects.get(pk=settings.SITH_GROUP_COM_ADMIN_ID)]
|
||||||
|
)
|
||||||
|
client.force_login(user)
|
||||||
|
res = client.get(url)
|
||||||
|
assert res.status_code == 200
|
||||||
|
27
com/views.py
27
com/views.py
@ -61,8 +61,7 @@ sith = Sith.objects.first
|
|||||||
|
|
||||||
|
|
||||||
class ComTabsMixin(TabedViewMixin):
|
class ComTabsMixin(TabedViewMixin):
|
||||||
def get_tabs_title(self):
|
tabs_title = _("Communication administration")
|
||||||
return _("Communication administration")
|
|
||||||
|
|
||||||
def get_list_of_tabs(self):
|
def get_list_of_tabs(self):
|
||||||
return [
|
return [
|
||||||
@ -559,7 +558,11 @@ class MailingModerateView(View):
|
|||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
|
|
||||||
class PosterListBaseView(ListView):
|
class PosterAdminViewMixin(IsComAdminMixin, ComTabsMixin):
|
||||||
|
current_tab = "posters"
|
||||||
|
|
||||||
|
|
||||||
|
class PosterListBaseView(PosterAdminViewMixin, ListView):
|
||||||
"""List communication posters."""
|
"""List communication posters."""
|
||||||
|
|
||||||
current_tab = "posters"
|
current_tab = "posters"
|
||||||
@ -586,7 +589,7 @@ class PosterListBaseView(ListView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class PosterCreateBaseView(CreateView):
|
class PosterCreateBaseView(PosterAdminViewMixin, CreateView):
|
||||||
"""Create communication poster."""
|
"""Create communication poster."""
|
||||||
|
|
||||||
current_tab = "posters"
|
current_tab = "posters"
|
||||||
@ -618,7 +621,7 @@ class PosterCreateBaseView(CreateView):
|
|||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class PosterEditBaseView(UpdateView):
|
class PosterEditBaseView(PosterAdminViewMixin, UpdateView):
|
||||||
"""Edit communication poster."""
|
"""Edit communication poster."""
|
||||||
|
|
||||||
pk_url_kwarg = "poster_id"
|
pk_url_kwarg = "poster_id"
|
||||||
@ -664,7 +667,7 @@ class PosterEditBaseView(UpdateView):
|
|||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class PosterDeleteBaseView(DeleteView):
|
class PosterDeleteBaseView(PosterAdminViewMixin, DeleteView):
|
||||||
"""Edit communication poster."""
|
"""Edit communication poster."""
|
||||||
|
|
||||||
pk_url_kwarg = "poster_id"
|
pk_url_kwarg = "poster_id"
|
||||||
@ -681,7 +684,7 @@ class PosterDeleteBaseView(DeleteView):
|
|||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class PosterListView(IsComAdminMixin, ComTabsMixin, PosterListBaseView):
|
class PosterListView(PosterListBaseView):
|
||||||
"""List communication posters."""
|
"""List communication posters."""
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -690,7 +693,7 @@ class PosterListView(IsComAdminMixin, ComTabsMixin, PosterListBaseView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class PosterCreateView(IsComAdminMixin, ComTabsMixin, PosterCreateBaseView):
|
class PosterCreateView(PosterCreateBaseView):
|
||||||
"""Create communication poster."""
|
"""Create communication poster."""
|
||||||
|
|
||||||
success_url = reverse_lazy("com:poster_list")
|
success_url = reverse_lazy("com:poster_list")
|
||||||
@ -701,7 +704,7 @@ class PosterCreateView(IsComAdminMixin, ComTabsMixin, PosterCreateBaseView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class PosterEditView(IsComAdminMixin, ComTabsMixin, PosterEditBaseView):
|
class PosterEditView(PosterEditBaseView):
|
||||||
"""Edit communication poster."""
|
"""Edit communication poster."""
|
||||||
|
|
||||||
success_url = reverse_lazy("com:poster_list")
|
success_url = reverse_lazy("com:poster_list")
|
||||||
@ -712,13 +715,13 @@ class PosterEditView(IsComAdminMixin, ComTabsMixin, PosterEditBaseView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class PosterDeleteView(IsComAdminMixin, ComTabsMixin, PosterDeleteBaseView):
|
class PosterDeleteView(PosterDeleteBaseView):
|
||||||
"""Delete communication poster."""
|
"""Delete communication poster."""
|
||||||
|
|
||||||
success_url = reverse_lazy("com:poster_list")
|
success_url = reverse_lazy("com:poster_list")
|
||||||
|
|
||||||
|
|
||||||
class PosterModerateListView(IsComAdminMixin, ComTabsMixin, ListView):
|
class PosterModerateListView(PosterAdminViewMixin, ListView):
|
||||||
"""Moderate list communication poster."""
|
"""Moderate list communication poster."""
|
||||||
|
|
||||||
current_tab = "posters"
|
current_tab = "posters"
|
||||||
@ -732,7 +735,7 @@ class PosterModerateListView(IsComAdminMixin, ComTabsMixin, ListView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class PosterModerateView(IsComAdminMixin, ComTabsMixin, View):
|
class PosterModerateView(PosterAdminViewMixin, View):
|
||||||
"""Moderate communication poster."""
|
"""Moderate communication poster."""
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user