1 """Sitemaps for Zinnia"""
2 from django.contrib.sitemaps import Sitemap
3 from django.core.urlresolvers import reverse
4
5 from tagging.models import TaggedItem
6
7 from zinnia.models import Entry
8 from zinnia.models import Author
9 from zinnia.models import Category
10 from zinnia.managers import tags_published
11 from zinnia.managers import entries_published
12
13
14 -class EntrySitemap(Sitemap):
15 """Sitemap for entries"""
16 priority = 0.5
17 changefreq = 'never'
18
20 """Return published entries"""
21 return Entry.published.all()
22
23 - def lastmod(self, obj):
24 """Return last modification of an entry"""
25 return obj.last_update
26
27
29 """Sitemap for categories"""
30 changefreq = 'monthly'
31
32 - def cache(self, categories):
33 """Cache categorie's entries percent on total entries"""
34 len_entries = float(Entry.published.count())
35 self.cache_categories = {}
36 for cat in categories:
37 self.cache_categories[cat.pk] = cat.entries_published_set(
38 ).count() / len_entries
39
45
52
54 """Compute priority with cached coeffs"""
55 priority = 0.5 + self.cache_categories[obj.pk]
56 if priority > 1.0:
57 priority = 1.0
58 return '%.1f' % priority
59
60
62 """Sitemap for authors"""
63 priority = 0.5
64 changefreq = 'monthly'
65
69
76
78 """Return url of an author"""
79 return reverse('zinnia_author_detail', args=[obj.username])
80
81
116