]> git.openstreetmap.org Git - osqa.git/commitdiff
We created a sitemap index and a separate view forum.sitemap.index, not using the...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 28 Dec 2010 01:34:37 +0000 (01:34 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 28 Dec 2010 01:34:37 +0000 (01:34 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@636 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/sitemap.py
forum/urls.py

index d898124834f795926a0f52cd3119958cadc943da..b53cb160728351124d3f9e7af4425396e2b2d9ee 100644 (file)
@@ -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'
index 5c5f622c477663c0f36214b6f3bff54208395d82..e964bc48960b329c3ba0afd29d21c410c5036424 100644 (file)
@@ -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<section>.+)\.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"),