schon/core/sitemaps.py

139 lines
3.6 KiB
Python

from django.conf import settings
from django.contrib.sitemaps import Sitemap
from django.utils.translation import gettext_lazy as _
from core.models import Brand, Category, Product
from core.utils.seo_builders import any_non_digital
from evibes.settings import LANGUAGE_CODE
class StaticPagesSitemap(Sitemap): # type: ignore [type-arg]
protocol = "https"
changefreq = "monthly"
priority = 0.8
limit = 1000
PAGES = [
{
"name": _("Home"),
"path": f"/{LANGUAGE_CODE}",
"lastmod": settings.RELEASE_DATE,
},
{
"name": _("Contact Us"),
"path": f"/{LANGUAGE_CODE}/contact-us",
"lastmod": settings.RELEASE_DATE,
},
{
"name": _("About Us"),
"path": f"/{LANGUAGE_CODE}/about-us",
"lastmod": settings.RELEASE_DATE,
},
{
"name": _("Payment Information"),
"path": f"/{LANGUAGE_CODE}/help/payments",
"lastmod": settings.RELEASE_DATE,
},
]
if any_non_digital():
PAGES.append(
{
"name": _("Delivery"),
"path": f"/{LANGUAGE_CODE}/help/delivery",
"lastmod": settings.RELEASE_DATE,
}
)
def items(self):
return self.PAGES
def location(self, obj):
return obj["path"]
def lastmod(self, obj):
return obj.get("lastmod")
# class FeaturedProductsSitemap(Sitemap): # type: ignore [type-arg]
# protocol = "https"
# changefreq = "daily"
# priority = 0.9
# limit = 25000
#
# def items(self):
# return (
# Product.objects.filter(
# is_active=True,
# brand__is_active=True,
# category__is_active=True,
# stocks__isnull=False,
# stocks__vendor__is_active=True,
# )
# .only("uuid", "name", "modified", "slug")
# .order_by("-modified")
# )
#
# def lastmod(self, obj):
# return obj.modified
#
# def location(self, obj):
# return f"/{LANGUAGE_CODE}/product/{obj.slug}"
class ProductSitemap(Sitemap): # type: ignore [type-arg]
protocol = "https"
changefreq = "daily"
priority = 0.9
limit = 25000
def items(self):
return (
Product.objects.filter(
is_active=True,
brand__is_active=True,
category__is_active=True,
stocks__isnull=False,
stocks__vendor__is_active=True,
)
.only("uuid", "name", "modified", "slug")
.order_by("-modified")
)
def lastmod(self, obj):
return obj.modified
def location(self, obj):
return f"/{LANGUAGE_CODE}/product/{obj.slug}"
class CategorySitemap(Sitemap): # type: ignore [type-arg]
protocol = "https"
changefreq = "weekly"
priority = 0.7
limit = 10000
def items(self):
return Category.objects.filter(is_active=True).only("uuid", "name", "modified").order_by("-modified")
def lastmod(self, obj):
return obj.modified
def location(self, obj):
return f"/{LANGUAGE_CODE}/catalog/{obj.slug}"
class BrandSitemap(Sitemap): # type: ignore [type-arg]
protocol = "https"
changefreq = "weekly"
priority = 0.6
limit = 10000
def items(self):
return Brand.objects.filter(is_active=True).only("uuid", "name", "modified").order_by("-modified")
def lastmod(self, obj):
return obj.modified
def location(self, obj):
return f"/{LANGUAGE_CODE}/brand/{obj.slug}"