svthalia/concrexit

View on GitHub
website/thabloid/sitemaps.py

Summary

Maintainability
A
1 hr
Test Coverage
from django.contrib import sitemaps
from django.urls import reverse

from .models import Thabloid


class StaticViewSitemap(sitemaps.Sitemap):
    """Sitemap of the static thabloid index page."""

    changefreq = "monthly"

    def items(self):
        """Return the index url name."""
        return ["thabloid:index"]

    def location(self, item):
        """Return the index url."""
        return reverse(item)


class ThabloidSitemap(sitemaps.Sitemap):
    """Sitemap of the thabloid pages."""

    changefreq = "never"

    def items(self):
        """Return all Thabloids."""
        return Thabloid.objects.all()

    def location(self, item):
        """Return the url of a Thabloid."""
        return item.get_absolute_url()


sitemap = {
    "thabloid-static": StaticViewSitemap,
    "thabloid-thabloids": ThabloidSitemap,
}