1 from django.contrib.sitemaps import Sitemap
2 from forum.models import Question
3 from django.conf import settings
4 from django.http import HttpResponse
5 from django.template import loader
6 from django.core import urlresolvers
8 def index(request, sitemaps):
10 for section, site in sitemaps.items():
12 pages = site().paginator.num_pages
14 pages = site.paginator.num_pages
15 sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap', kwargs={'section': section})
16 sites.append('%s%s' % (settings.APP_URL, sitemap_url))
18 for page in range(2, pages+1):
19 sites.append('%s%s?p=%s' % (settings.APP_URL, sitemap_url, page))
20 xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
21 return HttpResponse(xml, mimetype='application/xml')
23 class OsqaSitemap(Sitemap):
27 return Question.objects.filter_state(deleted=False)
29 def lastmod(self, obj):
30 return obj.last_activity_at
32 def location(self, obj):
33 return obj.get_absolute_url()
35 def __get(self, name, obj, default=None):
37 attr = getattr(self, name)
38 except AttributeError:
44 def get_urls(self, page=1):
46 for item in self.paginator.page(page).object_list:
47 loc = "%s%s" % (settings.APP_URL, self.__get('location', item))
50 'lastmod': self.__get('lastmod', item, None),
51 'changefreq': self.__get('changefreq', item, None),
52 'priority': self.__get('priority', item, None)