From c87459148e21d831e9cb3f1513c8079c47677e11 Mon Sep 17 00:00:00 2001 From: zerolab Date: Sun, 23 Apr 2023 13:02:09 +0100 Subject: [PATCH] Ad deprecation warnings --- src/wagtailmedia/deprecation.py | 4 ++-- src/wagtailmedia/edit_handlers.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/wagtailmedia/deprecation.py b/src/wagtailmedia/deprecation.py index b61831e..51a8588 100644 --- a/src/wagtailmedia/deprecation.py +++ b/src/wagtailmedia/deprecation.py @@ -1,6 +1,6 @@ -class RemovedInWagtailMedia015Warning(PendingDeprecationWarning): +class RemovedInWagtailMedia016Warning(PendingDeprecationWarning): pass -class RemovedInWagtailMedia016Warning(DeprecationWarning): +class RemovedInWagtailMedia017Warning(DeprecationWarning): pass diff --git a/src/wagtailmedia/edit_handlers.py b/src/wagtailmedia/edit_handlers.py index 77c07f4..3aabbfd 100644 --- a/src/wagtailmedia/edit_handlers.py +++ b/src/wagtailmedia/edit_handlers.py @@ -1,10 +1,12 @@ from __future__ import annotations +import warnings from typing import TYPE_CHECKING from django.template.loader import render_to_string from wagtail.admin.compare import ForeignObjectComparison from wagtail.admin.panels import FieldPanel +from .deprecation import RemovedInWagtailMedia017Warning from .models import MediaType from .utils import format_audio_html, format_video_html @@ -23,6 +25,26 @@ def __init__(self, field_name, *args, media_type=None, **kwargs): self.media_type = media_type + if self.media_type is None: + warnings.warn( + ( + "The `MediaChooserPanel` field panel is deprecated. " + "Please use the `FieldPanel()` instead." + ), + RemovedInWagtailMedia017Warning, + stacklevel=2, + ) + else: + warnings.warn( + ( + "The `MediaChooserPanel` field panel is deprecated. Please use the " + "specialised `AudioChooserPanel()` for audio only " + "and `VideoChooserPanel()` for video only." + ), + RemovedInWagtailMedia017Warning, + stacklevel=2, + ) + def clone_kwargs(self): kwargs = super().clone_kwargs() kwargs.update(media_type=self.media_type)