+ locations = []
+
+ for page in paginator.page_range:
+ location = urlresolvers.reverse('sitemap_section_page', prefix='/', kwargs={ 'page' : page, 'section' : section })
+ location = '%s%s' % (settings.APP_URL, location)
+ location = re.sub("/+", "/", location)
+ location = location.replace('http:/', 'http://')
+ location = location.replace('https:/', 'https://')
+ locations.append(location)
+
+ xml = loader.render_to_string('sitemap_section_index.xml', { 'locations' : locations, })
+ return HttpResponse(xml, mimetype='application/xml')
+
+def sitemap(request, sitemaps, section=None, page=1):
+ 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 = sitemaps.values()
+
+ for site in maps:
+ try:
+ if callable(site):
+ urls.extend(site().get_urls(page=page))
+ else:
+ urls.extend(site.get_urls(page=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')
+
+class OsqaSitemap(Sitemap):
+ limit = QUESTIONS_SITEMAP_LIMIT
+ changefreq = QUESTIONS_SITEMAP_CHANGEFREQ