Commit 74b34676 authored by Claude Paroz's avatar Claude Paroz
Browse files

Removed GeoRSSSitemap

Refs #18531.
parent 491419b5
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
# 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']
+0 −55
Original line number Diff line number Diff line
from django.core import urlresolvers
from django.contrib.sitemaps import Sitemap


class GeoRSSSitemap(Sitemap):
    """
    A minimal hook to produce sitemaps for GeoRSS feeds.
    """
    def __init__(self, feed_dict, slug_dict=None):
        """
        This sitemap object initializes on a feed dictionary (as would be passed
        to `django.contrib.gis.views.feed`) and a slug dictionary.
        If the slug dictionary is not defined, then it's assumed the keys provide
        the URL parameter to the feed.  However, if you have a complex feed (e.g.,
        you override `get_object`, then you'll need to provide a slug dictionary.
        The slug dictionary should have the same keys as the feed dictionary, but
        each value in the slug dictionary should be a sequence of slugs that may
        be used for valid feeds.  For example, let's say we have a feed that
        returns objects for a specific ZIP code in our feed dictionary:

            feed_dict = {'zipcode' : ZipFeed}

        Then we would use a slug dictionary with a list of the zip code slugs
        corresponding to feeds you want listed in the sitemap:

            slug_dict = {'zipcode' : ['77002', '77054']}
        """
        # Setting up.
        self.feed_dict = feed_dict
        self.locations = []
        if slug_dict is None:
            slug_dict = {}
        # Getting the feed locations.
        for section in feed_dict.keys():
            if slug_dict.get(section, False):
                for slug in slug_dict[section]:
                    self.locations.append('%s/%s' % (section, slug))
            else:
                self.locations.append(section)

    def get_urls(self, page=1, site=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)
        for url in urls:
            url['geo_format'] = 'georss'
        return urls

    def items(self):
        return self.locations

    def location(self, obj):
        return urlresolvers.reverse('django.contrib.gis.views.feed', args=(obj,))
+2 −2
Original line number Diff line number Diff line
@@ -42,12 +42,12 @@ class KMLSitemap(Sitemap):
                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
+2 −68
Original line number Diff line number Diff line
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):
+0 −17
Original line number Diff line number Diff line
{% autoescape off %}<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:geo="http://www.google.com/geo/schemas/sitemap/1.0">
{% spaceless %}
{% for url in urlset %}
  <url>
    <loc>{{ url.location|escape }}</loc>
    {% if url.lastmod %}<lastmod>{{ url.lastmod|date:"Y-m-d" }}</lastmod>{% endif %}
    {% if url.changefreq %}<changefreq>{{ url.changefreq }}</changefreq>{% endif %}
    {% if url.priority %}<priority>{{ url.priority }}</priority>{% endif %}
    {% if url.geo_format %}<geo:geo>
      <geo:format>{{ url.geo_format }}</geo:format>
    </geo:geo>{% endif %}
   </url>
{% endfor %}
{% endspaceless %}
</urlset>
{% endautoescape %}
Loading