diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4c665c2..842434f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,12 +16,12 @@ head: before_script: - pip install . - -lts_52: - image: python:3.11 - extends: .python_test - before_script: - - pip install . wagtail~=5.2 django~=4.2 +# Bring back with next LTS (6.3) +# lts_52: +# image: python:3.11 +# extends: .python_test +# before_script: +# - pip install . wagtail~=5.2 django~=4.2 flake8: stage: lint diff --git a/README.rst b/README.rst index 8f4921c..3898ae6 100644 --- a/README.rst +++ b/README.rst @@ -12,7 +12,7 @@ html5 compliant codec using ffmpeg. Requirements ------------ -- Wagtail >= 5.2 (for older wagtail version see the tags) +- Wagtail >= 6.1 (for older wagtail version see the tags) - `ffmpeg `__ (optional, for transcoding) Installing @@ -187,3 +187,4 @@ Future features - Some docs - Richtext embed - Transcoding via external service rather than ffmpeg +- Remove wagtail-modeladmin dependency diff --git a/setup.cfg b/setup.cfg index 5e586ed..44de9e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -description-file = README.rst +description_file = README.rst [bdist_wheel] universal = 1 diff --git a/setup.py b/setup.py index d71647a..46b4618 100755 --- a/setup.py +++ b/setup.py @@ -10,14 +10,14 @@ setup( name="wagtailvideos", - version="6.1.2", + version="7.0.0", description="A wagtail module for uploading and displaying videos in various codecs.", long_description=readme, author="Neon Jungle", author_email="developers@neonjungle.studio", url="https://github.com/neon-jungle/wagtailvideos", install_requires=[ - "wagtail>=5.2", + "wagtail>=6.1", "Django>=3.2", "bcp47==0.0.4", "wagtail-modeladmin>=2.0.0" diff --git a/tests/test_admin_views.py b/tests/test_admin_views.py index 5e12611..84cd52d 100644 --- a/tests/test_admin_views.py +++ b/tests/test_admin_views.py @@ -33,16 +33,12 @@ def test_search(self): self.assertEqual(response.context["query_string"], "Hello") def test_pagination(self): - pages = ["0", "1", "-1", "9999", "Not a page"] - for page in pages: - response = self.get({"p": page}) - self.assertEqual(response.status_code, 200) - - def test_ordering(self): - orderings = ["title", "-created_at"] - for ordering in orderings: - response = self.get({"ordering": ordering}) - self.assertEqual(response.status_code, 200) + # page numbers in range should be accepted + response = self.get({"p": 1}) + self.assertEqual(response.status_code, 200) + # page numbers out of range should return 404 + response = self.get({"p": 9999}) + self.assertEqual(response.status_code, 404) class TestVideoAddView(TestCase, WagtailTestUtils): diff --git a/wagtailvideos/blocks.py b/wagtailvideos/blocks.py index 6b675ea..887d81b 100644 --- a/wagtailvideos/blocks.py +++ b/wagtailvideos/blocks.py @@ -6,11 +6,13 @@ class VideoChooserBlock(ChooserBlock): @cached_property def target_model(self): from wagtailvideos import get_video_model + return get_video_model() @cached_property def widget(self): from wagtailvideos.widgets import AdminVideoChooser + return AdminVideoChooser() def render_basic(self, value, context=None): @@ -20,4 +22,4 @@ def render_basic(self, value, context=None): return "" class Meta: - icon = 'media' + icon = "media" diff --git a/wagtailvideos/templates/wagtailvideos/multiple/add.html b/wagtailvideos/templates/wagtailvideos/multiple/add.html index 755b33d..b321a48 100644 --- a/wagtailvideos/templates/wagtailvideos/multiple/add.html +++ b/wagtailvideos/templates/wagtailvideos/multiple/add.html @@ -17,7 +17,7 @@
- +
{% csrf_token %} diff --git a/wagtailvideos/templates/wagtailvideos/videos/add.html b/wagtailvideos/templates/wagtailvideos/videos/add.html index dbf0a9b..49d6cfc 100644 --- a/wagtailvideos/templates/wagtailvideos/videos/add.html +++ b/wagtailvideos/templates/wagtailvideos/videos/add.html @@ -3,35 +3,34 @@ {% block titletag %}{% trans "Add a video" %}{% endblock %} {% block extra_js %} - {{ block.super }} - - {% url 'wagtailadmin_tag_autocomplete' as autocomplete_url %} - + {{ block.super }} + {% url 'wagtailadmin_tag_autocomplete' as autocomplete_url %} + {% endblock %} {% block content %} - {% trans "Add video" as add_str %} - {% include "wagtailadmin/shared/header.html" with title=add_str icon="media" %} + {% trans "Add video" as add_str %} + {% include "wagtailadmin/shared/header.html" with title=add_str icon="media" %} -
- - {% csrf_token %} -
    - {% for field in form %} - {% if field.is_hidden %} - {{ field }} - {% else %} -
  • {% include "wagtailadmin/shared/field.html" with field=field %}
  • - {% endif %} - {% endfor %} -
  • -
- -
+
+
+ {% csrf_token %} +
    + {% for field in form %} + {% if field.is_hidden %} + {{ field }} + {% else %} +
  • {% include "wagtailadmin/shared/field.html" with field=field %}
  • + {% endif %} + {% endfor %} +
  • +
+
+
{% endblock %} diff --git a/wagtailvideos/templates/wagtailvideos/videos/index.html b/wagtailvideos/templates/wagtailvideos/videos/index.html index 2feaaa8..74963cf 100644 --- a/wagtailvideos/templates/wagtailvideos/videos/index.html +++ b/wagtailvideos/templates/wagtailvideos/videos/index.html @@ -1,43 +1,11 @@ -{% extends "wagtailadmin/base.html" %} +{% extends "wagtailadmin/generic/index.html" %} {% load i18n %} {% block titletag %}{% trans "Videos" %}{% endblock %} -{% block extra_js %} - {{ block.super }} - -{% endblock %} - -{% block content %} - {% trans "Videos" as video_str %} - - {% trans "Add a video" as add_video_str %} - {% url "wagtailvideos:add_multiple" as add_link %} - {% include "wagtailadmin/shared/header.html" with title=video_str add_link="wagtailvideos:add_multiple" action_url=add_link icon="media" add_text=add_video_str action_text=add_video_str search_url="wagtailvideos:index" %} - -
- {% if collections %} - - {% endif %} -
- {% include "wagtailvideos/videos/results.html" %} -
-
+{% block slim_header %} +{% trans "Add a video" as add_video_str %} + {% include "wagtailadmin/shared/headers/slim_header.html" with title=video_str breadcrumbs_items=breadcrumbs_items icon_name="media" search_url=index_results_url search_form=search_form filters=filters buttons=header_buttons only %} {% endblock %} diff --git a/wagtailvideos/templates/wagtailvideos/videos/results.html b/wagtailvideos/templates/wagtailvideos/videos/results.html index 498f028..6c9ebe8 100644 --- a/wagtailvideos/templates/wagtailvideos/videos/results.html +++ b/wagtailvideos/templates/wagtailvideos/videos/results.html @@ -1,20 +1,10 @@ + +{% extends "wagtailadmin/generic/index_results.html" %} {% load wagtailadmin_tags %} {% load i18n %} -{% if videos %} - {% if is_searching %} -

- {% blocktrans count counter=videos.paginator.count %} - There is one match - {% plural %} - There are {{ counter }} matches - {% endblocktrans %} -

- - {% search_other %} - {% else %} -

{% trans "Latest videos" %}

- {% endif %} +{% block results %} +
+
+{% endblock %} + - {% include "wagtailadmin/shared/pagination_nav.html" with items=videos is_searching=is_searching query_string=query_string linkurl="wagtailvideos:index" %} - -{% else %} +{% block no_results_message %} {% if is_searching %}

{% blocktrans %}Sorry, no videos match "{{ query_string }}"{% endblocktrans %}

- {% search_other %} {% else %} {% url 'wagtailvideos:add_multiple' as wagtailvideos_add_video_url %} @@ -47,4 +37,4 @@

{% blocktrans %}Sorry, no videos match "{{ query_string }}"{% endbl

{% blocktrans %}You've not uploaded any videos. Why not add one now?{% endblocktrans %}

{% endif %} {% endif %} -{% endif %} +{% endblock %} diff --git a/wagtailvideos/urls.py b/wagtailvideos/urls.py index ee4d38f..5b88976 100644 --- a/wagtailvideos/urls.py +++ b/wagtailvideos/urls.py @@ -15,5 +15,6 @@ re_path(r'^(\d+)/delete/$', videos.delete, name='delete'), re_path(r'^(\d+)/create_transcode/$', videos.create_transcode, name='create_transcode'), re_path(r'^(\d+)/$', videos.edit, name='edit'), - path('', videos.index, name='index'), + path('', videos.IndexView.as_view(), name='index'), + path("results/", videos.IndexView.as_view(results_only=True), name="index_results"), ] diff --git a/wagtailvideos/views/multiple.py b/wagtailvideos/views/multiple.py index 3781422..90c496f 100644 --- a/wagtailvideos/views/multiple.py +++ b/wagtailvideos/views/multiple.py @@ -30,6 +30,7 @@ class Meta(VideoForm.Meta): @vary_on_headers('X-Requested-With') def add(request): + # TODO replace with wagtail.admin.views.generic.multiple_upload.AddView subclass Video = get_video_model() VideoForm = get_video_form(Video) diff --git a/wagtailvideos/views/videos.py b/wagtailvideos/views/videos.py index 180e8a3..53ad7a9 100644 --- a/wagtailvideos/views/videos.py +++ b/wagtailvideos/views/videos.py @@ -4,12 +4,10 @@ from django.urls import reverse from django.utils.translation import gettext as _ from django.views.decorators.http import require_POST -from django.views.decorators.vary import vary_on_headers from wagtail.admin import messages from wagtail.admin.auth import PermissionPolicyChecker -from wagtail.admin.forms.search import SearchForm -from wagtail.admin.models import popular_tags_for_model -from wagtail.models import Collection +from wagtail.admin.filters import BaseMediaFilterSet +from wagtail.admin.views import generic from wagtail.search.backends import get_search_backends from wagtail_modeladmin.helpers import AdminURLHelper @@ -21,65 +19,44 @@ permission_checker = PermissionPolicyChecker(permission_policy) -@permission_checker.require_any('add', 'change', 'delete', 'choose') -@vary_on_headers('X-Requested-With') -def index(request): - # Get Videos (filtered by user permission) - Video = get_video_model() +Video = get_video_model() - collections = permission_policy.collections_user_has_any_permission_for( - request.user, ['add', 'change', 'delete', 'choose']) - if len(collections) > 1: - collections_to_choose = collections - else: - # no need to show a collections chooser - collections_to_choose = None - videos = Video.objects.filter(collection__in=collections) +class VideoFilterSet(BaseMediaFilterSet): + permission_policy = permission_policy - # Search - query_string = None - if 'q' in request.GET: - form = SearchForm(request.GET, placeholder=_("Search videos")) - if form.is_valid(): - query_string = form.cleaned_data['q'] + class Meta: + model = Video + fields = [] - videos = videos.search(query_string) - else: - form = SearchForm(placeholder=_("Search videos")) - - # Filter by collection - current_collection = None - collection_id = request.GET.get('collection_id') - if collection_id: - try: - current_collection = Collection.objects.get(id=collection_id) - videos = videos.filter(collection=current_collection) - except (ValueError, Collection.DoesNotExist): - pass - - paginator = Paginator(videos, per_page=25) - page = paginator.get_page(request.GET.get('p')) - # Create response - if request.headers.get('x-requested-with') == 'XMLHttpRequest': - response = render(request, 'wagtailvideos/videos/results.html', { - 'videos': page, - 'query_string': query_string, - 'is_searching': bool(query_string), - }) - return response - else: - response = render(request, 'wagtailvideos/videos/index.html', { - 'videos': page, - 'query_string': query_string, - 'is_searching': bool(query_string), - 'search_form': form, - 'popular_tags': popular_tags_for_model(Video), - 'current_collection': current_collection, - 'collections': collections_to_choose, - }) - return response +class IndexView(generic.IndexView): + context_object_name = "videos" + model = Video + filterset_class = VideoFilterSet + permission_policy = permission_policy + any_permission_required = ['add', 'change', 'delete'] + header_icon = 'media' + template_name = 'wagtailvideos/videos/index.html' + results_template_name = 'wagtailvideos/videos/results.html' + _show_breadcrumbs = True + add_url_name = "wagtailvideos:add_multiple" + edit_url_name = "wagtailvideos:edit" + index_results_url_name = 'wagtailvideos:index_results' + add_item_label = "Add a video" + + def get_breadcrumbs_items(self): + return self.breadcrumbs_items + [ + {"url": "", "label": "Videos"}, + ] + + def get_filterset_kwargs(self): + kwargs = super().get_filterset_kwargs() + kwargs["is_searching"] = self.is_searching + return kwargs + + def get_paginate_by(self, queryset): + return 32 # 4 x 8 @permission_checker.require('change') diff --git a/wagtailvideos/wagtail_hooks.py b/wagtailvideos/wagtail_hooks.py index 4878a46..e9b3e6a 100644 --- a/wagtailvideos/wagtail_hooks.py +++ b/wagtailvideos/wagtail_hooks.py @@ -48,23 +48,6 @@ def register_admin_urls(): ] -@hooks.register('insert_editor_js') -def editor_js(): - return format_html( - """ - - """, - reverse('wagtailvideos_chooser:choose') - ) - - @hooks.register('register_group_permission_panel') def register_video_permissions_panel(): return GroupVideoPermissionFormSet