summaryrefslogtreecommitdiff
path: root/django/contrib/sitemaps/views.py
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-08-05 17:15:33 +0000
committerJustin Bronn <jbronn@gmail.com>2008-08-05 17:15:33 +0000
commitaa239e3e5405933af6a29dac3cf587b59a099927 (patch)
treeea2cbd139c9a8cf84c09e0b2008bff70e05927ef /django/contrib/sitemaps/views.py
parent45b73c9a4685809236f84046cc7ffd32a50db958 (diff)
downloaddjango-attic/gis.tar.gz
gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.archive/attic/gisattic/gis
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@8215 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/sitemaps/views.py')
-rw-r--r--django/contrib/sitemaps/views.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
index 86ef1e3526..7a5fe38a08 100644
--- a/django/contrib/sitemaps/views.py
+++ b/django/contrib/sitemaps/views.py
@@ -3,14 +3,22 @@ from django.template import loader
from django.contrib.sites.models import Site
from django.core import urlresolvers
from django.utils.encoding import smart_str
+from django.core.paginator import EmptyPage, PageNotAnInteger
def index(request, sitemaps):
current_site = Site.objects.get_current()
sites = []
protocol = request.is_secure() and 'https' or 'http'
- for section in sitemaps.keys():
+ 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.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, mimetype='application/xml')
@@ -22,10 +30,16 @@ def sitemap(request, sitemaps, section=None):
maps.append(sitemaps[section])
else:
maps = sitemaps.values()
+ page = request.GET.get("p", 1)
for site in maps:
- if callable(site):
- urls.extend(site().get_urls())
- else:
- urls.extend(site.get_urls())
+ try:
+ if callable(site):
+ urls.extend(site().get_urls(page))
+ else:
+ urls.extend(site.get_urls(page))
+ except EmptyPage:
+ raise Http404("Page %s empty" % page)
+ except PageNotAnInteger:
+ raise Http404("No page '%s'" % page)
xml = smart_str(loader.render_to_string('sitemap.xml', {'urlset': urls}))
return HttpResponse(xml, mimetype='application/xml')