1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Added tests for contrib.sitemaps.ping_google().

This commit is contained in:
Adam Chainz
2016-11-22 11:56:22 +00:00
committed by Tim Graham
parent b1a9041535
commit 10d49b96e6
5 changed files with 76 additions and 5 deletions

View File

@@ -21,6 +21,15 @@ def ping_google(sitemap_url=None, ping_url=PING_URL):
for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
function will attempt to deduce it by using urls.reverse().
"""
sitemap_full_url = _get_sitemap_full_url(sitemap_url)
params = urlencode({'sitemap': sitemap_full_url})
urlopen('%s?%s' % (ping_url, params))
def _get_sitemap_full_url(sitemap_url):
if not django_apps.is_installed('django.contrib.sites'):
raise ImproperlyConfigured("ping_google requires django.contrib.sites, which isn't installed.")
if sitemap_url is None:
try:
# First, try to get the "index" sitemap URL.
@@ -35,13 +44,9 @@ def ping_google(sitemap_url=None, ping_url=PING_URL):
if sitemap_url is None:
raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.")
if not django_apps.is_installed('django.contrib.sites'):
raise ImproperlyConfigured("ping_google requires django.contrib.sites, which isn't installed.")
Site = django_apps.get_model('sites.Site')
current_site = Site.objects.get_current()
url = "http://%s%s" % (current_site.domain, sitemap_url)
params = urlencode({'sitemap': url})
urlopen("%s?%s" % (ping_url, params))
return 'http://%s%s' % (current_site.domain, sitemap_url)
class Sitemap(object):