Remove features deprecated in 2.7

This commit is contained in:
Matt Westcott 2019-07-09 17:05:03 +01:00 committed by Matt Westcott
parent 6d7a82cfb2
commit 13a7d403ad
6 changed files with 30 additions and 136 deletions

View file

@ -1,6 +1,5 @@
import functools
import re
from warnings import warn
from django import forms
from django.core.exceptions import ImproperlyConfigured
@ -18,7 +17,6 @@ from wagtail.core.fields import RichTextField
from wagtail.core.models import Page
from wagtail.core.utils import camelcase_to_underscore, resolve_model_string
from wagtail.utils.decorators import cached_classmethod
from wagtail.utils.deprecation import RemovedInWagtail27Warning
# DIRECT_FORM_FIELD_OVERRIDES, FORM_FIELD_OVERRIDES are imported for backwards
# compatibility, as people are likely importing them from here and then
@ -158,18 +156,6 @@ class EditHandler:
return new
def bind_to_model(self, model):
warn('EditHandler.bind_to_model(model) is deprecated. '
'Use EditHandler.bind_to(model=model) instead',
category=RemovedInWagtail27Warning)
return self.bind_to(model=model)
def bind_to_instance(self, instance, form, request):
warn('EditHandler.bind_to_instance(instance, request, form) is deprecated. '
'Use EditHandler.bind_to(instance=instance, request=request, form=form) instead',
category=RemovedInWagtail27Warning)
return self.bind_to(instance=instance, request=request, form=form)
def on_model_bound(self):
pass

View file

@ -1,35 +1,30 @@
{% load i18n %}
{% load wagtailadmin_tags %}
{% if is_ajax %}
{% ajax_pagination_nav_deprecation_warning %}
{% include "wagtailadmin/shared/ajax_pagination_nav.html" %}
{% else %}
{% comment %}
HACK: This template expects to be passed a 'linkurl' parameter, containing a URL name
that can be reverse-resolved by the {% url %} tag with no further parameters.
Views that have parameters in their URL can work around this by omitting linkurl,
which will produce a final URL of the form "?q=123", implicitly preserving the current URL path.
Using the {% url ... as ... %} form of the tag ensures that this fails silently,
rather than throwing a NoReverseMatch exception.
{% endcomment %}
{% if linkurl %}
{% url linkurl as url_to_use %}
{% endif %}
<nav class="pagination" aria-label="{% trans 'Pagination' %}">
<p>{% blocktrans with page_num=items.number total_pages=items.paginator.num_pages %}Page {{ page_num }} of {{ total_pages }}.{% endblocktrans %}</p>
<ul>
<li class="prev">
{% if items.has_previous %}
<a href="{{ url_to_use }}{% querystring p=items.previous_page_number %}" class="icon icon-arrow-left">{% trans 'Previous' %}</a>
{% endif %}
</li>
<li class="next">
{% if items.has_next %}
<a href="{{ url_to_use }}{% querystring p=items.next_page_number %}" class="icon icon-arrow-right-after">{% trans 'Next' %}</a>
{% endif %}
</li>
</ul>
</nav>
{% comment %}
HACK: This template expects to be passed a 'linkurl' parameter, containing a URL name
that can be reverse-resolved by the {% url %} tag with no further parameters.
Views that have parameters in their URL can work around this by omitting linkurl,
which will produce a final URL of the form "?q=123", implicitly preserving the current URL path.
Using the {% url ... as ... %} form of the tag ensures that this fails silently,
rather than throwing a NoReverseMatch exception.
{% endcomment %}
{% if linkurl %}
{% url linkurl as url_to_use %}
{% endif %}
<nav class="pagination" aria-label="{% trans 'Pagination' %}">
<p>{% blocktrans with page_num=items.number total_pages=items.paginator.num_pages %}Page {{ page_num }} of {{ total_pages }}.{% endblocktrans %}</p>
<ul>
<li class="prev">
{% if items.has_previous %}
<a href="{{ url_to_use }}{% querystring p=items.previous_page_number %}" class="icon icon-arrow-left">{% trans 'Previous' %}</a>
{% endif %}
</li>
<li class="next">
{% if items.has_next %}
<a href="{{ url_to_use }}{% querystring p=items.next_page_number %}" class="icon icon-arrow-right-after">{% trans 'Next' %}</a>
{% endif %}
</li>
</ul>
</nav>

View file

@ -1,5 +1,4 @@
import itertools
from warnings import warn
from django import template
from django.conf import settings
@ -22,7 +21,6 @@ from wagtail.core.models import (
from wagtail.core.utils import cautious_slugify as _cautious_slugify
from wagtail.core.utils import camelcase_to_underscore, escape_script
from wagtail.users.utils import get_gravatar_url
from wagtail.utils.deprecation import RemovedInWagtail27Warning
register = template.Library()
@ -471,11 +469,3 @@ def avatar_url(user, size=50):
return gravatar_url
return static('wagtailadmin/images/default-user-avatar.png')
@register.simple_tag
def ajax_pagination_nav_deprecation_warning():
warn('Passing is_ajax=1 to wagtailadmin/shared/pagination_nav.html is deprecated. '
'Use wagtailadmin/shared/ajax_pagination_nav.html instead',
category=RemovedInWagtail27Warning)
return ''

View file

@ -1,7 +1,4 @@
from warnings import warn
from wagtail.core import hooks
from wagtail.utils.deprecation import RemovedInWagtail27Warning
class FeatureRegistry:
@ -71,40 +68,16 @@ class FeatureRegistry:
except KeyError:
return None
def register_link_type(self, identifier_or_handler_obj, handler_fn=None):
if handler_fn is not None:
# invoked as register_link_type(identifier, handler_function) - deprecated
identifier = identifier_or_handler_obj
warn(
'FeatureRegistry.register_link_type(link_type, handler_function) is deprecated. '
'Use FeatureRegistry.register_link_type(handler_object) instead',
category=RemovedInWagtail27Warning
)
self.link_types[identifier] = self.function_as_entity_handler(identifier, handler_fn)
else:
# invoked as register_link_type(handler_object)
handler = identifier_or_handler_obj
self.link_types[handler.identifier] = handler
def register_link_type(self, handler):
self.link_types[handler.identifier] = handler
def get_link_types(self):
if not self.has_scanned_for_features:
self._scan_for_features()
return self.link_types
def register_embed_type(self, identifier_or_handler_obj, handler_fn=None):
if handler_fn is not None:
# invoked as register_embed_type(identifier, handler_function) - deprecated
identifier = identifier_or_handler_obj
warn(
'FeatureRegistry.register_embed_type(link_type, handler_function) is deprecated. '
'Use FeatureRegistry.register_embed_type(handler_object) instead',
category=RemovedInWagtail27Warning
)
self.embed_types[identifier] = self.function_as_entity_handler(identifier, handler_fn)
else:
# invoked as register_embed_type(handler_object)
handler = identifier_or_handler_obj
self.embed_types[handler.identifier] = handler
def register_embed_type(self, handler):
self.embed_types[handler.identifier] = handler
def get_embed_types(self):
if not self.has_scanned_for_features:

View file

@ -1,6 +1,5 @@
from unittest.mock import patch
from django.contrib.auth import get_user_model
from django.test import TestCase
from wagtail.core.rich_text import RichText, expand_db_html
@ -96,36 +95,6 @@ class TestFeatureRegistry(TestCase):
features.get_editor_plugin('hallo', 'made_up_feature')
)
def test_legacy_register_link_type(self):
User = get_user_model()
User.objects.create(username='wagtail', email='hello@wagtail.io')
def user_expand_db_attributes(attrs):
user = User.objects.get(username=attrs['username'])
return '<a href="mailto:%s">' % user.email
features = FeatureRegistry()
features.register_link_type('user', user_expand_db_attributes)
handler = features.get_link_types()['user']
self.assertEqual(
handler.expand_db_attributes({'username': 'wagtail'}),
'<a href="mailto:hello@wagtail.io">'
)
def test_legacy_register_embed_type(self):
def embed_expand_db_attributes(attrs):
return '<div>embedded content: %s</div>' % attrs['content']
features = FeatureRegistry()
features.register_embed_type('mock_embed', embed_expand_db_attributes)
handler = features.get_embed_types()['mock_embed']
self.assertEqual(
handler.expand_db_attributes({'content': 'foo'}),
'<div>embedded content: foo</div>'
)
class TestLinkRewriterTagReplacing(TestCase):
def test_should_follow_default_behaviour(self):

View file

@ -1,19 +0,0 @@
from warnings import warn
from django.core.paginator import Paginator
from wagtail.utils.deprecation import RemovedInWagtail27Warning
warn('wagtail.utils.pagination is deprecated. '
'Use django.core.paginator.Paginator directly with get_page instead',
category=RemovedInWagtail27Warning)
DEFAULT_PAGE_KEY = 'p'
def paginate(request, items, page_key=DEFAULT_PAGE_KEY, per_page=20):
paginator = Paginator(items, per_page)
page = paginator.get_page(request.GET.get(page_key))
return paginator, page