2022-08-19 09:36:03 +01:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from django.http.response import HttpResponse
|
2022-08-19 14:35:38 +01:00
|
|
|
from django.urls import reverse
|
2022-08-19 09:36:03 +01:00
|
|
|
from django.views.defaults import ERROR_404_TEMPLATE_NAME
|
|
|
|
from django.views.generic import TemplateView
|
|
|
|
|
|
|
|
from website.home.models import HomePage
|
|
|
|
|
|
|
|
|
|
|
|
class Error404View(TemplateView):
|
|
|
|
template_name = ERROR_404_TEMPLATE_NAME
|
|
|
|
|
|
|
|
def render_to_response(self, context: dict, **response_kwargs: Any) -> HttpResponse:
|
2022-08-19 15:07:59 +01:00
|
|
|
if self.request.resolver_match.url_name != "404":
|
|
|
|
response_kwargs["status"] = 404
|
2022-08-19 09:36:03 +01:00
|
|
|
return super().render_to_response(context, **response_kwargs)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs: dict) -> dict:
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["homepage"] = HomePage.objects.live().get()
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
page_not_found = Error404View.as_view()
|
2022-08-19 14:35:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RobotsView(TemplateView):
|
|
|
|
template_name = "robots.txt"
|
|
|
|
content_type = "text/plain"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs: dict) -> dict:
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["sitemap"] = self.request.build_absolute_uri(reverse("sitemap"))
|
|
|
|
return context
|