75 lines
1.7 KiB
Python
75 lines
1.7 KiB
Python
from django.contrib.sitemaps import Sitemap
|
|
from django.urls import reverse
|
|
|
|
from blog.models import Article
|
|
from .models import Solution, Competence, Recall
|
|
|
|
|
|
class HttpsSitemap(Sitemap):
|
|
"""Base class that forces https on all sitemap URLs."""
|
|
protocol = 'https'
|
|
|
|
|
|
class StaticViewSitemap(HttpsSitemap):
|
|
priority = 1.0
|
|
changefreq = 'monthly'
|
|
|
|
def items(self):
|
|
return ['home', 'about', 'solution', 'blog:article_list', 'recall']
|
|
|
|
def location(self, item):
|
|
return reverse(item)
|
|
|
|
|
|
class SolutionSitemap(HttpsSitemap):
|
|
changefreq = 'weekly'
|
|
priority = 0.9
|
|
|
|
def items(self):
|
|
return Solution.objects.filter(is_published=True)
|
|
|
|
def lastmod(self, obj):
|
|
return obj.time_update
|
|
|
|
|
|
class CompetenceSitemap(HttpsSitemap):
|
|
changefreq = 'monthly'
|
|
priority = 0.8
|
|
|
|
def items(self):
|
|
return Competence.objects.filter(is_published=True)
|
|
|
|
def lastmod(self, obj):
|
|
return obj.time_update
|
|
|
|
|
|
class RecallSitemap(HttpsSitemap):
|
|
changefreq = 'monthly'
|
|
priority = 0.7
|
|
|
|
def items(self):
|
|
return Recall.objects.filter(is_published=True)
|
|
|
|
def lastmod(self, obj):
|
|
return obj.time_update
|
|
|
|
|
|
class BlogSitemap(HttpsSitemap):
|
|
changefreq = 'weekly'
|
|
priority = 0.9
|
|
|
|
def items(self):
|
|
return Article.objects.filter(is_published=True).select_related('category')
|
|
|
|
def lastmod(self, obj):
|
|
return obj.time_update
|
|
|
|
|
|
# Упрощаем sitemaps - убираем HomeSitemap если он дублирует главную
|
|
sitemaps = {
|
|
'static': StaticViewSitemap,
|
|
'solutions': SolutionSitemap,
|
|
'blog': BlogSitemap,
|
|
# 'competence': CompetenceSitemap,
|
|
'recall': RecallSitemap,
|
|
} |