From: jordan Date: Tue, 28 Dec 2010 01:34:37 +0000 (+0000) Subject: We created a sitemap index and a separate view forum.sitemap.index, not using the... X-Git-Tag: live~498 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/576bde12866658986362cf4f2e35e6fd1d1a1a73 We created a sitemap index and a separate view forum.sitemap.index, not using the Sitemap framework, but the settings.APP_URL git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@636 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/sitemap.py b/forum/sitemap.py index d898124..b53cb16 100644 --- a/forum/sitemap.py +++ b/forum/sitemap.py @@ -1,6 +1,24 @@ from django.contrib.sitemaps import Sitemap from forum.models import Question from django.conf import settings +from django.http import HttpResponse +from django.template import loader +from django.core import urlresolvers + +def index(request, sitemaps): + sites = [] + 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' % (settings.APP_URL, sitemap_url)) + if pages > 1: + for page in range(2, pages+1): + sites.append('%s%s?p=%s' % (settings.APP_URL, sitemap_url, page)) + xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites}) + return HttpResponse(xml, mimetype='application/xml') class OsqaSitemap(Sitemap): changefreq = 'daily' diff --git a/forum/urls.py b/forum/urls.py index 5c5f622..e964bc4 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -33,8 +33,8 @@ urlpatterns += patterns('', url(r'^$', app.readers.index, name='index'), url(r'^%s(.*)' % _('nimda/'), admin.site.root), - url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}, - name='sitemap'), + url(r'^sitemap.xml$', 'forum.sitemap.index', {'sitemaps': sitemaps}), + url(r'^sitemap-(?P
.+)\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}), (r'^favicon\.ico$', app.meta.favicon), url(r'^cstyle\.css$', app.meta.custom_css, name="custom_css"),