-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsitemaps.py
54 lines (42 loc) · 1.81 KB
/
sitemaps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from django.contrib.sitemaps import Sitemap
from django.core.urlresolvers import NoReverseMatch
from fluent_faq.models import FaqCategory, FaqQuestion
from fluent_faq.urlresolvers import faq_reverse
def _url_patterns_installed():
# This module can use normal Django urls.py URLs, or mount the "FaqPage" in the page tree.
# Check whether the URLs are installed, so the `sitemap.xml` can be generated nevertheless.
# This issue will pop up elsewhere too, so there is no need to raise an error here.
try:
faq_reverse('faqcategory_detail', kwargs={'slug': 'category'}, ignore_multiple=True)
except NoReverseMatch:
return False
else:
return True
class FaqQuestionSitemap(Sitemap):
"""
Sitemap for FAQ questions
"""
def items(self):
if not _url_patterns_installed():
return []
return FaqQuestion.objects.published().select_related('category').active_translations()
def lastmod(self, question):
"""Return the last modification of the object."""
return question.modification_date
def location(self, question):
"""Return url of an question."""
return faq_reverse('faqquestion_detail', kwargs={'cat_slug': question.category.slug, 'slug': question.slug}, ignore_multiple=True)
class FaqCategorySitemap(Sitemap):
"""
Sitemap for FAQ categories.
"""
def items(self):
if not _url_patterns_installed():
return []
return FaqCategory.objects.published().active_translations()
def lastmod(self, category):
"""Return the last modification of the object."""
return category.modification_date
def location(self, category):
"""Return url of an category."""
return faq_reverse('faqcategory_detail', kwargs={'slug': category.slug}, ignore_multiple=True)