2022-08-19 15:06:18 +01:00
|
|
|
from datetime import timedelta
|
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 15:06:18 +01:00
|
|
|
from django.utils import timezone
|
2022-08-19 09:36:03 +01:00
|
|
|
from django.views.defaults import ERROR_404_TEMPLATE_NAME
|
|
|
|
from django.views.generic import TemplateView
|
|
|
|
|
2022-08-19 15:06:18 +01:00
|
|
|
from website.contact.models import ContactPage
|
2022-08-19 09:36:03 +01:00
|
|
|
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:
|
|
|
|
response_kwargs["status"] = 404
|
|
|
|
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
|
2022-08-19 15:06:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SecurityView(TemplateView):
|
|
|
|
template_name = "security.txt"
|
|
|
|
content_type = "text/plain"
|
|
|
|
|
|
|
|
expires = timedelta(days=7)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs: dict) -> dict:
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["security_txt"] = self.request.build_absolute_uri(
|
|
|
|
reverse("securitytxt")
|
|
|
|
)
|
|
|
|
context["contact_page"] = ContactPage.objects.live().first()
|
|
|
|
context["expires"] = (
|
|
|
|
(timezone.now() + self.expires).replace(microsecond=0).isoformat()
|
|
|
|
)
|
|
|
|
return context
|