You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.3 KiB
63 lines
2.3 KiB
# -*- coding: utf-8 -*-
|
|
from itertools import chain
|
|
|
|
from django.contrib.sitemaps import Sitemap
|
|
from django.contrib.sites.models import Site
|
|
from django.db.models import Q
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from cms.models import Title, Page, CMSPlugin
|
|
|
|
|
|
class CMSSitemap(Sitemap):
|
|
"""
|
|
DjangoCMS Sitemap.
|
|
|
|
Modified version of the original cms.sitemaps.CMSSitemap.
|
|
Everything cached to minimize number of sql queries.
|
|
|
|
Notes:
|
|
- excluded pages that are redirected (items)
|
|
- excluded pages that require login (items)
|
|
- no multi language paths for pages (location)
|
|
|
|
Project specific notes:
|
|
- excluded pages that are not in navigation (items)
|
|
- excluded page with 'guestbook' reverse_id (items)
|
|
"""
|
|
changefreq = 'monthly'
|
|
priority = None
|
|
|
|
exclude_reverse_ids = ['guestbook']
|
|
|
|
def items(self):
|
|
self.all_page_placeholders = Page.placeholders.through.objects.all()
|
|
self.all_plugins = CMSPlugin.objects.all()
|
|
all_titles = (
|
|
Title.objects.public()
|
|
.filter(
|
|
Q(redirect='') | Q(redirect__isnull=True),
|
|
page__login_required=False,
|
|
page__site=Site.objects.get_current(),
|
|
page__in_navigation=True,
|
|
)
|
|
.exclude(page__reverse_id__in=self.exclude_reverse_ids)
|
|
.select_related('page')
|
|
.order_by('path')
|
|
)
|
|
return all_titles
|
|
|
|
def lastmod(self, title):
|
|
modification_dates = [title.page.changed_date, title.page.publication_date]
|
|
plugins_for_placeholder = lambda placeholder: \
|
|
[p for p in self.all_plugins if p.placeholder_id == placeholder.placeholder_id]
|
|
page_placeholders = [pp for pp in self.all_page_placeholders if pp.page_id == title.page_id]
|
|
plugins = chain.from_iterable(map(plugins_for_placeholder, page_placeholders))
|
|
plugin_modification_dates = map(lambda plugin: plugin.changed_date, plugins)
|
|
modification_dates.extend(plugin_modification_dates)
|
|
return max(modification_dates)
|
|
|
|
def location(self, title):
|
|
if title.page.is_home():
|
|
return reverse('pages-root')
|
|
return reverse('pages-details-by-slug', kwargs={'slug': title.path})
|
|
|