from django.contrib.sitemaps import Sitemap from django.utils import timezone from django.urls import reverse from django.db.models import Q from core.models import (StaticPage, Article, MainLot, KoreaLot, MachineryLot, TransportExperience, MachineryExperience) class StaticViewSitemap(Sitemap): protocol = 'https' limit = 900 def items(self): return StaticPage.objects.all() def location(self, obj): return reverse('core:static_page', args=[obj.slug]) def lastmod(self, item): return timezone.now() class PagesViewSitemap(Sitemap): protocol = 'https' limit = 900 changefreq = 'daily' pages = { 'services': '/services/', 'about': '/about/', 'warning': '/warning/', 'contacts': '/contacts/', 'reviews': '/reviews/', 'video': '/video/', 'articles': '/articles/', 'auction-china': '/services/auction/china/', 'auction-japan': '/services/auction/japan/', 'auction-korea': '/services/auction/korea/', 'auction-machinery': '/services/auction/machinery/', 'auction-vladivostok': '/services/auction/vladivostok/', 'auction-tax': '/services/auction/tax/', 'experience-auto': '/experience/', 'experience-machinery': '/experience/machinery/' } def items(self): return list(self.pages.keys()) def location(self, item): return self.pages[item] class ArticlesViewSitemap(Sitemap): protocol = 'https' limit = 900 changefreq = 'hourly' def items(self): return Article.objects.filter( Q(is_active=True) & Q(date__lte=timezone.now()) ).select_related('cover') def lastmod(self, item): return item.date class CatalogJapanViewSitemap(Sitemap): protocol = 'https' limit = 1000 changefreq = 'hourly' def items(self): return MainLot.objects.all() def location(self, item): return item.get_absolute_url class CatalogKoreaViewSitemap(Sitemap): protocol = 'https' limit = 1000 changefreq = 'hourly' def items(self): return KoreaLot.objects.all() def location(self, item): return item.get_absolute_url class CatalogMachineryViewSitemap(Sitemap): protocol = 'https' limit = 1000 changefreq = 'hourly' def items(self): return MachineryLot.objects.all() def location(self, item): return item.get_absolute_url class TransportExperienceViewSitemap(Sitemap): protocol = 'https' limit = 1000 changefreq = 'hourly' def items(self): return TransportExperience.objects.all().select_related('cover', 'slider') def location(self, item): return item.get_absolute_url class MachineryExperienceViewSitemap(Sitemap): protocol = 'https' limit = 1000 changefreq = 'hourly' def items(self): return MachineryExperience.objects.all().select_related('cover', 'slider') def location(self, item): return item.get_absolute_url sitemaps = { 'static': StaticViewSitemap, 'pages': PagesViewSitemap, 'articles': ArticlesViewSitemap, 'catalog-japan': CatalogJapanViewSitemap, 'catalog-korea': CatalogKoreaViewSitemap, 'catalog-machinery': CatalogMachineryViewSitemap, 'transport-experience': TransportExperienceViewSitemap, 'machinery-experience': MachineryExperienceViewSitemap }