schon/core/sitemaps.py
Egor fureunoir Gorbunov 3ec0991aa6 Add slug field to Product and update related functionalities
Introduce a unique, auto-generated slug field to the Product model, populated from category, brand, and name. Update core filters, serializers, sitemaps, and GraphQL object types to support the new slug functionality. Also, enforce HTTP-only cookies for session, CSRF, and language for improved security.
2025-04-30 16:31:54 +03:00

59 lines
1.5 KiB
Python

from django.contrib.sitemaps import Sitemap
from django.utils.text import slugify
from core.models import Brand, Category, Product
from evibes.settings import LANGUAGE_CODE
class ProductSitemap(Sitemap):
protocol = "https"
changefreq = "daily"
priority = 0.9
limit = 40000
def items(self):
return Product.objects.filter(
is_active=True,
brand__is_active=True,
category__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.uuid}/{obj.slug}"
class CategorySitemap(Sitemap):
protocol = "https"
changefreq = "weekly"
priority = 0.7
limit = 40000
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):
slug = slugify(obj.name)
return f"/{LANGUAGE_CODE}/catalog/{obj.uuid}/{slug}"
class BrandSitemap(Sitemap):
protocol = "https"
changefreq = "weekly"
priority = 0.6
limit = 40000
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):
slug = slugify(obj.name)
return f"/{LANGUAGE_CODE}/brand/{obj.uuid}/{slug}"