]> git.openstreetmap.org Git - osqa.git/blob - forum/sitemap.py
Applies some of the Justin Grant's patches.
[osqa.git] / forum / sitemap.py
1 from django.contrib.sitemaps import Sitemap
2 from forum.models import Question
3 from django.conf import settings
4
5 class OsqaSitemap(Sitemap):
6     changefreq = 'daily'
7     priority = 0.5
8     def items(self):
9         return Question.objects.filter_state(deleted=False)
10
11     def lastmod(self, obj):
12         return obj.last_activity_at
13
14     def location(self, obj):
15         return obj.get_absolute_url()
16
17     def __get(self, name, obj, default=None):
18         try:
19             attr = getattr(self, name)
20         except AttributeError:
21             return default
22         if callable(attr):
23             return attr(obj)
24         return attr
25
26     def get_urls(self, page=1):
27         urls = []
28         for item in self.paginator.page(page).object_list:
29             loc = "%s%s" % (settings.APP_URL, self.__get('location', item))
30             url_info = {
31                 'location':   loc,
32                 'lastmod':    self.__get('lastmod', item, None),
33                 'changefreq': self.__get('changefreq', item, None),
34                 'priority':   self.__get('priority', item, None)
35             }
36             urls.append(url_info)
37         return urls