Skip to content

Commit

Permalink
Removed GeoRSSSitemap
Browse files Browse the repository at this point in the history
Refs #18531.
  • Loading branch information
claudep committed Mar 22, 2014
1 parent 491419b commit 74b3467
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 203 deletions.
3 changes: 1 addition & 2 deletions django/contrib/gis/sitemaps/__init__.py
@@ -1,5 +1,4 @@
# Geo-enabled Sitemap classes.
from django.contrib.gis.sitemaps.georss import GeoRSSSitemap
from django.contrib.gis.sitemaps.kml import KMLSitemap, KMZSitemap

__all__ = ['GeoRSSSitemap', 'KMLSitemap', 'KMZSitemap']
__all__ = ['KMLSitemap', 'KMZSitemap']
55 changes: 0 additions & 55 deletions django/contrib/gis/sitemaps/georss.py

This file was deleted.

4 changes: 2 additions & 2 deletions django/contrib/gis/sitemaps/kml.py
Expand Up @@ -42,12 +42,12 @@ def _build_kml_sources(self, sources):
raise TypeError('KML Sources must be a model or a 3-tuple.')
return kml_sources

def get_urls(self, page=1, site=None):
def get_urls(self, page=1, site=None, protocol=None):
"""
This method is overrridden so the appropriate `geo_format` attribute
is placed on each URL element.
"""
urls = Sitemap.get_urls(self, page=page, site=site)
urls = Sitemap.get_urls(self, page=page, site=site, protocol=protocol)
for url in urls:
url['geo_format'] = self.geo_format
return urls
Expand Down
70 changes: 2 additions & 68 deletions django/contrib/gis/sitemaps/views.py
@@ -1,77 +1,11 @@
from __future__ import unicode_literals

import warnings

from django.apps import apps
from django.http import HttpResponse, Http404
from django.template import loader
from django.contrib.sites.shortcuts import get_current_site
from django.core import urlresolvers
from django.core.paginator import EmptyPage, PageNotAnInteger
from django.http import Http404
from django.contrib.gis.db.models.fields import GeometryField
from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
from django.db import connections, DEFAULT_DB_ALIAS
from django.db.models.fields import FieldDoesNotExist
from django.utils import six
from django.utils.deprecation import RemovedInDjango18Warning
from django.utils.translation import ugettext as _

from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz


def index(request, sitemaps):
"""
This view generates a sitemap index that uses the proper view
for resolving geographic section sitemap URLs.
"""
warnings.warn("Geo Sitemaps are deprecated. Use plain sitemaps from "
"django.contrib.sitemaps instead", RemovedInDjango18Warning, stacklevel=2)
current_site = get_current_site(request)
sites = []
protocol = request.scheme
for section, site in sitemaps.items():
if callable(site):
pages = site().paginator.num_pages
else:
pages = site.paginator.num_pages
sitemap_url = urlresolvers.reverse('django.contrib.gis.sitemaps.views.sitemap', kwargs={'section': section})
sites.append('%s://%s%s' % (protocol, current_site.domain, sitemap_url))

if pages > 1:
for page in range(2, pages + 1):
sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
return HttpResponse(xml, content_type='application/xml')


def sitemap(request, sitemaps, section=None):
"""
This view generates a sitemap with additional geographic
elements defined by Google.
"""
warnings.warn("Geo Sitemaps are deprecated. Use plain sitemaps from "
"django.contrib.sitemaps instead", RemovedInDjango18Warning, stacklevel=2)
maps, urls = [], []
if section is not None:
if section not in sitemaps:
raise Http404(_("No sitemap available for section: %r") % section)
maps.append(sitemaps[section])
else:
maps = list(six.itervalues(sitemaps))

page = request.GET.get("p", 1)
current_site = get_current_site(request)
for site in maps:
try:
if callable(site):
urls.extend(site().get_urls(page=page, site=current_site))
else:
urls.extend(site.get_urls(page=page, site=current_site))
except EmptyPage:
raise Http404(_("Page %s empty") % page)
except PageNotAnInteger:
raise Http404(_("No page '%s'") % page)
xml = loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls})
return HttpResponse(xml, content_type='application/xml')


def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
Expand Down
17 changes: 0 additions & 17 deletions django/contrib/gis/templates/gis/sitemaps/geo_sitemap.xml

This file was deleted.

4 changes: 1 addition & 3 deletions django/contrib/gis/tests/geoapp/sitemaps.py
@@ -1,10 +1,8 @@
from django.contrib.gis.sitemaps import GeoRSSSitemap, KMLSitemap, KMZSitemap
from django.contrib.gis.sitemaps import KMLSitemap, KMZSitemap

from .feeds import feed_dict
from .models import City, Country


sitemaps = {'kml': KMLSitemap([City, Country]),
'kmz': KMZSitemap([City, Country]),
'georss': GeoRSSSitemap(feed_dict),
}
50 changes: 4 additions & 46 deletions django/contrib/gis/tests/geoapp/test_sitemaps.py
Expand Up @@ -3,24 +3,21 @@
from io import BytesIO
from unittest import skipUnless
from xml.dom import minidom
import os
import zipfile

from django.conf import settings
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
from django.contrib.sites.models import Site
from django.test import TestCase, modify_settings
from django.test.utils import IgnoreDeprecationWarningsMixin
from django.utils._os import upath

if HAS_GEOS:
from .models import City, Country


@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sites'})
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.sites', 'django.contrib.sitemaps']})
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
class GeoSitemapTest(IgnoreDeprecationWarningsMixin, TestCase):
class GeoSitemapTest(TestCase):

urls = 'django.contrib.gis.tests.geoapp.urls'

Expand All @@ -34,36 +31,19 @@ def assertChildNodes(self, elem, expected):
expected = set(expected)
self.assertEqual(actual, expected)

def test_geositemap_index(self):
"Tests geographic sitemap index."
# Getting the geo index.
from django.contrib import sitemaps
template_dirs = settings.TEMPLATE_DIRS + (
os.path.join(os.path.dirname(upath(sitemaps.__file__)), 'templates'),)
with self.settings(TEMPLATE_DIRS=template_dirs):
doc = minidom.parseString(self.client.get('/sitemap.xml').content)
index = doc.firstChild
self.assertEqual(index.getAttribute('xmlns'), 'http://www.sitemaps.org/schemas/sitemap/0.9')
self.assertEqual(3, len(index.getElementsByTagName('sitemap')))

def test_geositemap_kml(self):
"Tests KML/KMZ geographic sitemaps."
for kml_type in ('kml', 'kmz'):
doc = minidom.parseString(self.client.get('/sitemaps/%s.xml' % kml_type).content)

# Ensuring the right sitemaps namespaces are present.
# Ensuring the right sitemaps namespace is present.
urlset = doc.firstChild
self.assertEqual(urlset.getAttribute('xmlns'), 'http://www.sitemaps.org/schemas/sitemap/0.9')
self.assertEqual(urlset.getAttribute('xmlns:geo'), 'http://www.google.com/geo/schemas/sitemap/1.0')

urls = urlset.getElementsByTagName('url')
self.assertEqual(2, len(urls)) # Should only be 2 sitemaps.
for url in urls:
self.assertChildNodes(url, ['loc', 'geo:geo'])
# Making sure the 'geo:format' element was properly set.
geo_elem = url.getElementsByTagName('geo:geo')[0]
geo_format = geo_elem.getElementsByTagName('geo:format')[0]
self.assertEqual(kml_type, geo_format.childNodes[0].data)
self.assertChildNodes(url, ['loc'])

# Getting the relative URL since we don't have a real site.
kml_url = url.getElementsByTagName('loc')[0].childNodes[0].data.split('http://example.com')[1]
Expand All @@ -84,25 +64,3 @@ def test_geositemap_kml(self):
elif 'country' in kml_url:
model = Country
self.assertEqual(model.objects.count(), len(kml_doc.getElementsByTagName('Placemark')))

def test_geositemap_georss(self):
"Tests GeoRSS geographic sitemaps."
from .feeds import feed_dict

doc = minidom.parseString(self.client.get('/sitemaps/georss.xml').content)

# Ensuring the right sitemaps namespaces are present.
urlset = doc.firstChild
self.assertEqual(urlset.getAttribute('xmlns'), 'http://www.sitemaps.org/schemas/sitemap/0.9')
self.assertEqual(urlset.getAttribute('xmlns:geo'), 'http://www.google.com/geo/schemas/sitemap/1.0')

# Making sure the correct number of feed URLs were included.
urls = urlset.getElementsByTagName('url')
self.assertEqual(len(feed_dict), len(urls))

for url in urls:
self.assertChildNodes(url, ['loc', 'geo:geo'])
# Making sure the 'geo:format' element was properly set to 'georss'.
geo_elem = url.getElementsByTagName('geo:geo')[0]
geo_format = geo_elem.getElementsByTagName('geo:format')[0]
self.assertEqual('georss', geo_format.childNodes[0].data)
6 changes: 4 additions & 2 deletions django/contrib/gis/tests/geoapp/urls.py
Expand Up @@ -10,9 +10,11 @@
(r'^feeds/(?P<url>.*)/$', 'django.contrib.gis.views.feed', {'feed_dict': feed_dict}),
)

urlpatterns += patterns('django.contrib.gis.sitemaps.views',
(r'^sitemap.xml$', 'index', {'sitemaps': sitemaps}),
urlpatterns += patterns('django.contrib.sitemaps.views',
(r'^sitemaps/(?P<section>\w+)\.xml$', 'sitemap', {'sitemaps': sitemaps}),
)

urlpatterns += patterns('django.contrib.gis.sitemaps.views',
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kml$', 'kml'),
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', 'kmz'),
)
12 changes: 4 additions & 8 deletions docs/ref/contrib/gis/sitemaps.txt
Expand Up @@ -2,10 +2,9 @@
Geographic Sitemaps
===================

Google's sitemap protocol used to include geospatial content support. [#]_
This included the addition of the ``<url>`` child element
``<geo:geo>``, which tells Google that the content located at the URL is
geographic in nature. This is now obsolete.
KML is an XML language focused on geographic visualization [#]_.``KMLSitemap``
and its compressed counterpart ``KMZSitemap`` allow you to present geolocated
data in a machine-readable format.

Example
=======
Expand All @@ -19,8 +18,5 @@ Reference
``KMZSitemap``
--------------

``GeoRSSSitemap``
-----------------

.. rubric:: Footnotes
.. [#] Google, Inc., `What is a Geo Sitemap? <https://support.google.com/webmasters/answer/94555>`_.
.. [#] http://www.opengeospatial.org/standards/kml

0 comments on commit 74b3467

Please sign in to comment.