Coverage for apis_core / entities / views.py: 56%
16 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 11:37 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 11:37 +0000
1from django.http import HttpResponse
2from django.shortcuts import redirect
3from django.views.generic.base import View
4from django.views.generic.detail import SingleObjectMixin
6from apis_core.entities.models import EntityID
9class CanonicalEntity(View, SingleObjectMixin):
10 model = EntityID
11 accepted_media_types = ["text/html", "application/json"]
13 def get(self, request, *args, **kwargs):
14 match request.get_preferred_type(self.accepted_media_types):
15 case "text/html":
16 return redirect(self.get_object().content_object.get_absolute_url())
17 case "application/json":
18 return redirect(
19 self.get_object().content_object.get_api_detail_endpoint()
20 )
21 case _:
22 return HttpResponse(
23 status_code=406,
24 headers={"Accept": ",".join(self.accepted_media_types)},
25 )