Removed contrib.flatpages.FlatPageSitemap per deprecation timeline; refs #23884.

This commit is contained in:
Tim Graham 2015-01-17 14:14:15 -05:00
parent 65d55c4093
commit c2d5f2903c
4 changed files with 2 additions and 109 deletions

View File

@ -1,11 +1,8 @@
import warnings
from django.apps import apps as django_apps
from django.conf import settings
from django.core import urlresolvers, paginator
from django.core.exceptions import ImproperlyConfigured
from django.utils import translation
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.six.moves.urllib.parse import urlencode
from django.utils.six.moves.urllib.request import urlopen
@ -135,27 +132,6 @@ class Sitemap(object):
return urls
class FlatPageSitemap(Sitemap):
# This class is not a subclass of
# django.contrib.flatpages.sitemaps.FlatPageSitemap to avoid a
# circular import problem.
def __init__(self):
warnings.warn(
"'django.contrib.sitemaps.FlatPageSitemap' is deprecated. "
"Use 'django.contrib.flatpages.sitemaps.FlatPageSitemap' instead.",
RemovedInDjango19Warning,
stacklevel=2
)
def items(self):
if not django_apps.is_installed('django.contrib.sites'):
raise ImproperlyConfigured("FlatPageSitemap requires django.contrib.sites, which isn't installed.")
Site = django_apps.get_model('sites.Site')
current_site = Site.objects.get_current()
return current_site.flatpage_set.filter(registration_required=False)
class GenericSitemap(Sitemap):
priority = None
changefreq = None

View File

@ -1,62 +0,0 @@
from __future__ import unicode_literals
from unittest import skipUnless
import warnings
from django.apps import apps
from django.conf import settings
from django.contrib.sitemaps import FlatPageSitemap
from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango19Warning
from .base import SitemapTestsBase
class FlatpagesSitemapTests(SitemapTestsBase):
@ignore_warnings(category=RemovedInDjango19Warning)
@skipUnless(apps.is_installed('django.contrib.flatpages'),
"django.contrib.flatpages app not installed.")
def test_flatpage_sitemap(self):
"Basic FlatPage sitemap test"
# Import FlatPage inside the test so that when django.contrib.flatpages
# is not installed we don't get problems trying to delete Site
# objects (FlatPage has an M2M to Site, Site.delete() tries to
# delete related objects, but the M2M table doesn't exist.
from django.contrib.flatpages.models import FlatPage
public = FlatPage.objects.create(
url='/public/',
title='Public Page',
enable_comments=True,
registration_required=False,
)
public.sites.add(settings.SITE_ID)
private = FlatPage.objects.create(
url='/private/',
title='Private Page',
enable_comments=True,
registration_required=True
)
private.sites.add(settings.SITE_ID)
response = self.client.get('/flatpages/sitemap.xml')
# Public flatpage should be in the sitemap
self.assertContains(response, '<loc>%s%s</loc>' % (self.base_url, public.url))
# Private flatpage should not be in the sitemap
self.assertNotContains(response, '<loc>%s%s</loc>' % (self.base_url, private.url))
class FlatpagesSitemapDeprecationTests(SimpleTestCase):
def test_deprecation(self):
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always')
FlatPageSitemap()
self.assertEqual(len(warns), 1)
self.assertEqual(
str(warns[0].message),
"'django.contrib.sitemaps.FlatPageSitemap' is deprecated. "
"Use 'django.contrib.flatpages.sitemaps.FlatPageSitemap' instead.",
)

View File

@ -1,7 +1,7 @@
from datetime import date, datetime
from django.conf.urls import url
from django.conf.urls.i18n import i18n_patterns
from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap, views
from django.contrib.sitemaps import Sitemap, GenericSitemap, views
from django.http import HttpResponse
from django.utils import timezone
from django.views.decorators.cache import cache_page
@ -90,10 +90,6 @@ generic_sitemaps = {
'generic': GenericSitemap({'queryset': TestModel.objects.all()}),
}
flatpage_sitemaps = {
'flatpages': FlatPageSitemap,
}
urlpatterns = [
url(r'^simple/index\.xml$', views.index, {'sitemaps': simple_sitemaps}),
@ -129,9 +125,6 @@ urlpatterns = [
url(r'^generic/sitemap\.xml$', views.sitemap,
{'sitemaps': generic_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^flatpages/sitemap\.xml$', views.sitemap,
{'sitemaps': flatpage_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^cached/index\.xml$', cache_page(1)(views.index),
{'sitemaps': simple_sitemaps, 'sitemap_url_name': 'cached_sitemap'}),
url(r'^cached/sitemap-(?P<section>.+)\.xml', cache_page(1)(views.sitemap),

View File

@ -247,21 +247,7 @@ Sitemap class reference
Shortcuts
=========
The sitemap framework provides a couple convenience classes for common cases:
.. class:: FlatPageSitemap
.. deprecated:: 1.8
Use :class:`django.contrib.flatpages.sitemaps.FlatPageSitemap` instead.
The :class:`django.contrib.sitemaps.FlatPageSitemap` class looks at all
publicly visible :mod:`flatpages <django.contrib.flatpages>`
defined for the current :setting:`SITE_ID` (see the
:mod:`sites documentation <django.contrib.sites>`) and
creates an entry in the sitemap. These entries include only the
:attr:`~Sitemap.location` attribute -- not :attr:`~Sitemap.lastmod`,
:attr:`~Sitemap.changefreq` or :attr:`~Sitemap.priority`.
The sitemap framework provides a convenience class for a common case:
.. class:: GenericSitemap