from django.contrib.sitemaps import Sitemap from blog.models import Blog, Cat_Blog from core.models import Page from django.urls import reverse from django.utils import timezone class BlogSitemap(Sitemap): """Sitemap pour les articles de blog""" changefreq = "weekly" priority = 0.8 protocol = 'https' def items(self): return Blog.objects.filter(b_publier=True).order_by('-b_publdate') def lastmod(self, obj): return obj.b_publdate def location(self, obj): return reverse('blog_play', args=[obj.b_titre_slugify]) class CategorySitemap(Sitemap): """Sitemap pour les catégories""" changefreq = "monthly" priority = 0.6 protocol = 'https' def items(self): return Cat_Blog.objects.all() def lastmod(self, obj): # Utilise la date du dernier article publié dans cette catégorie last_article = Blog.objects.filter( b_publier=True, b_cat=obj ).order_by('-b_publdate').first() if last_article and last_article.b_publdate: return last_article.b_publdate # Retourne la date actuelle si aucun article return timezone.now() def location(self, obj): return reverse('blog_tag', args=[obj.cb_titre_slgify]) class PageSitemap(Sitemap): """Sitemap pour les pages statiques""" changefreq = "monthly" priority = 0.5 protocol = 'https' def items(self): return Page.objects.filter(p_publier=True, p_type='page') def lastmod(self, obj): # Si la page a un champ de date de modification, l'utiliser # Sinon retourner la date actuelle return getattr(obj, 'p_date_modification', timezone.now()) def location(self, obj): return obj.p_adresse class StaticViewSitemap(Sitemap): """Sitemap pour les vues statiques""" priority = 0.5 changefreq = 'daily' # Changé à 'daily' car l'index change souvent protocol = 'https' def items(self): return ['blog_index'] def lastmod(self, item): # Date du dernier article publié last_article = Blog.objects.filter(b_publier=True).order_by('-b_publdate').first() if last_article and last_article.b_publdate: return last_article.b_publdate return timezone.now() def location(self, item): return reverse(item)