mirror of
https://github.com/ae-utbm/sith.git
synced 2025-09-13 03:25:49 +00:00
@@ -99,9 +99,10 @@ INSTALLED_APPS = (
|
|||||||
"django.contrib.auth",
|
"django.contrib.auth",
|
||||||
"django.contrib.contenttypes",
|
"django.contrib.contenttypes",
|
||||||
"django.contrib.sessions",
|
"django.contrib.sessions",
|
||||||
|
"django.contrib.sitemaps",
|
||||||
|
"django.contrib.sites",
|
||||||
"django.contrib.messages",
|
"django.contrib.messages",
|
||||||
"staticfiles",
|
"staticfiles",
|
||||||
"django.contrib.sites",
|
|
||||||
"honeypot",
|
"honeypot",
|
||||||
"django_jinja",
|
"django_jinja",
|
||||||
"ninja_extra",
|
"ninja_extra",
|
||||||
|
46
sith/sitemap.py
Normal file
46
sith/sitemap.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.sitemaps import Sitemap
|
||||||
|
from django.db.models import OuterRef, Subquery
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from club.models import Club
|
||||||
|
from core.models import Page, PageRev
|
||||||
|
|
||||||
|
|
||||||
|
class SithSitemap(Sitemap):
|
||||||
|
def items(self):
|
||||||
|
return [
|
||||||
|
"core:index",
|
||||||
|
"eboutic:main",
|
||||||
|
"sas:main",
|
||||||
|
"forum:main",
|
||||||
|
"club:club_list",
|
||||||
|
"election:list",
|
||||||
|
]
|
||||||
|
|
||||||
|
def location(self, item):
|
||||||
|
return reverse(item)
|
||||||
|
|
||||||
|
|
||||||
|
class PagesSitemap(Sitemap):
|
||||||
|
def items(self):
|
||||||
|
return (
|
||||||
|
Page.objects.filter(view_groups=settings.SITH_GROUP_PUBLIC_ID)
|
||||||
|
.exclude(revisions=None, _full_name__startswith="club")
|
||||||
|
.annotate(
|
||||||
|
lastmod=Subquery(
|
||||||
|
PageRev.objects.filter(page=OuterRef("pk"))
|
||||||
|
.values("date")
|
||||||
|
.order_by("-date")[:1]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
|
||||||
|
def lastmod(self, item: Page):
|
||||||
|
return item.lastmod
|
||||||
|
|
||||||
|
|
||||||
|
class ClubSitemap(Sitemap):
|
||||||
|
def items(self):
|
||||||
|
return Club.objects.filter(is_active=True)
|
@@ -15,20 +15,24 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.contrib.sitemaps.views import sitemap
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
from django.views.decorators.cache import cache_page
|
||||||
from django.views.i18n import JavaScriptCatalog
|
from django.views.i18n import JavaScriptCatalog
|
||||||
|
|
||||||
from api.urls import api
|
from api.urls import api
|
||||||
|
from sith.sitemap import ClubSitemap, PagesSitemap, SithSitemap
|
||||||
|
|
||||||
js_info_dict = {"packages": ("sith",)}
|
js_info_dict = {"packages": ("sith",)}
|
||||||
|
|
||||||
handler403 = "core.views.forbidden"
|
handler403 = "core.views.forbidden"
|
||||||
handler404 = "core.views.not_found"
|
handler404 = "core.views.not_found"
|
||||||
handler500 = "core.views.internal_servor_error"
|
handler500 = "core.views.internal_servor_error"
|
||||||
|
sitemaps = {"sith": SithSitemap, "pages": PagesSitemap, "clubs": ClubSitemap}
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", include(("core.urls", "core"), namespace="core")),
|
path("", include(("core.urls", "core"), namespace="core")),
|
||||||
|
path("sitemap.xml", cache_page(86400)(sitemap), {"sitemaps": sitemaps}),
|
||||||
path("api/", api.urls),
|
path("api/", api.urls),
|
||||||
path("rootplace/", include(("rootplace.urls", "rootplace"), namespace="rootplace")),
|
path("rootplace/", include(("rootplace.urls", "rootplace"), namespace="rootplace")),
|
||||||
path(
|
path(
|
||||||
|
Reference in New Issue
Block a user