schon/core/sitemaps.py
Egor fureunoir Gorbunov 874fa8a40d Features: 1) Update localized strings for da_DK translations in vibes_auth; 2) Update localized strings for zh_Hans translations in core;
Fixes: 1) Correct `attributes` definition in `da_DK` translations; 2) Add missing localization details in `zh_Hans`;

Extra: Update project version metadata from 2.9.3 to 3.0.0.
2025-09-15 12:54:46 +03:00

138 lines
3.5 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):
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):
# 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):
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):
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):
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}"