From c2d5f2903cfaef4f8b17d86f4db706b61073a471 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 17 Jan 2015 14:14:15 -0500 Subject: [PATCH] Removed contrib.flatpages.FlatPageSitemap per deprecation timeline; refs #23884. --- django/contrib/sitemaps/__init__.py | 24 ------- .../contrib/sitemaps/tests/test_flatpages.py | 62 ------------------- django/contrib/sitemaps/tests/urls/http.py | 9 +-- docs/ref/contrib/sitemaps.txt | 16 +---- 4 files changed, 2 insertions(+), 109 deletions(-) delete mode 100644 django/contrib/sitemaps/tests/test_flatpages.py diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py index 3db4ef53a4..930279bf96 100644 --- a/django/contrib/sitemaps/__init__.py +++ b/django/contrib/sitemaps/__init__.py @@ -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 diff --git a/django/contrib/sitemaps/tests/test_flatpages.py b/django/contrib/sitemaps/tests/test_flatpages.py deleted file mode 100644 index ecfe2c094d..0000000000 --- a/django/contrib/sitemaps/tests/test_flatpages.py +++ /dev/null @@ -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, '%s%s' % (self.base_url, public.url)) - # Private flatpage should not be in the sitemap - self.assertNotContains(response, '%s%s' % (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.", - ) diff --git a/django/contrib/sitemaps/tests/urls/http.py b/django/contrib/sitemaps/tests/urls/http.py index 07da79045e..c7bcc0fac0 100644 --- a/django/contrib/sitemaps/tests/urls/http.py +++ b/django/contrib/sitemaps/tests/urls/http.py @@ -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
.+)\.xml', cache_page(1)(views.sitemap), diff --git a/docs/ref/contrib/sitemaps.txt b/docs/ref/contrib/sitemaps.txt index b28b9b463d..cb64685127 100644 --- a/docs/ref/contrib/sitemaps.txt +++ b/docs/ref/contrib/sitemaps.txt @@ -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 ` - defined for the current :setting:`SITE_ID` (see the - :mod:`sites documentation `) 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