feat: Add sitemap
This commit is contained in:
		
							
								
								
									
										47
									
								
								src/fellchensammlung/sitemap.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								src/fellchensammlung/sitemap.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
from django.contrib.sitemaps import Sitemap
 | 
			
		||||
from django.urls import reverse
 | 
			
		||||
from .models import AdoptionNotice, RescueOrganization
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StaticViewSitemap(Sitemap):
 | 
			
		||||
    priority = 0.8
 | 
			
		||||
    changefreq = "weekly"
 | 
			
		||||
 | 
			
		||||
    def items(self):
 | 
			
		||||
        return ["index", "search", "map", "about", "rescue-organizations"]
 | 
			
		||||
 | 
			
		||||
    def location(self, item):
 | 
			
		||||
        return reverse(item)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AdoptionNoticeSitemap(Sitemap):
 | 
			
		||||
    priority = 0.5
 | 
			
		||||
    changefreq = "daily"
 | 
			
		||||
 | 
			
		||||
    def items(self):
 | 
			
		||||
        return AdoptionNotice.get_active_ANs()
 | 
			
		||||
 | 
			
		||||
    def lastmod(self, obj):
 | 
			
		||||
        return obj.updated_at
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AnimalSitemap(Sitemap):
 | 
			
		||||
    priority = 0.2
 | 
			
		||||
    changefreq = "daily"
 | 
			
		||||
 | 
			
		||||
    def items(self):
 | 
			
		||||
        return AdoptionNotice.objects.all()
 | 
			
		||||
 | 
			
		||||
    def lastmod(self, obj):
 | 
			
		||||
        return obj.updated_at
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class RescueOrganizationSitemap(Sitemap):
 | 
			
		||||
    priority = 0.3
 | 
			
		||||
    changefreq = "weekly"
 | 
			
		||||
 | 
			
		||||
    def items(self):
 | 
			
		||||
        return RescueOrganization.objects.all()
 | 
			
		||||
 | 
			
		||||
    def lastmod(self, obj):
 | 
			
		||||
        return obj.updated_at
 | 
			
		||||
@@ -7,6 +7,15 @@ from .feeds import LatestAdoptionNoticesFeed
 | 
			
		||||
from . import views
 | 
			
		||||
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
 | 
			
		||||
 | 
			
		||||
from django.contrib.sitemaps.views import sitemap
 | 
			
		||||
from .sitemap import StaticViewSitemap, AdoptionNoticeSitemap, AnimalSitemap
 | 
			
		||||
 | 
			
		||||
sitemaps = {
 | 
			
		||||
    "static": StaticViewSitemap,
 | 
			
		||||
    "vermittlungen": AdoptionNoticeSitemap,
 | 
			
		||||
    "tiere": AnimalSitemap,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
urlpatterns = [
 | 
			
		||||
    path("", views.index, name="index"),
 | 
			
		||||
    path("rss/", LatestAdoptionNoticesFeed(), name="rss"),
 | 
			
		||||
@@ -95,4 +104,9 @@ urlpatterns = [
 | 
			
		||||
    ###################
 | 
			
		||||
    path('external-site/', views.external_site_warning, name="external-site"),
 | 
			
		||||
 | 
			
		||||
    ###############
 | 
			
		||||
    ## TECHNICAL ##
 | 
			
		||||
    ###############
 | 
			
		||||
    path("sitemap.xml", sitemap, {"sitemaps": sitemaps}, name="django.contrib.sitemaps.views.sitemap"),
 | 
			
		||||
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
@@ -168,6 +168,7 @@ INSTALLED_APPS = [
 | 
			
		||||
    'django.contrib.sessions',
 | 
			
		||||
    'django.contrib.messages',
 | 
			
		||||
    'django.contrib.staticfiles',
 | 
			
		||||
    "django.contrib.sitemaps",
 | 
			
		||||
    'fontawesomefree',
 | 
			
		||||
    'crispy_forms',
 | 
			
		||||
    "crispy_bootstrap4",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user