Coverage for archeutils/views.py: 24%
37 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-27 11:19 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-27 11:19 +0000
1from django.http import HttpResponse, JsonResponse, Http404
2from django.core.exceptions import ObjectDoesNotExist
3from django.urls import reverse
5from .utils import (
6 as_arche_graph,
7 serialize_project,
8 ARCHE_BASE_URL,
9 title_img,
10 ARCHE_DEFAULT_EXTENSION,
11 ARCHE_PAYLOAD_MIMETYPE,
12)
14from shps.models import TempSpatial
17def res_as_arche_graph(request, pk):
18 format = request.GET.get("format", "xml")
19 try:
20 res = TempSpatial.objects.get(id=pk)
21 except ObjectDoesNotExist:
22 raise Http404(f"No object with id: {pk} found")
23 g = as_arche_graph(res)
24 if format == "turtle":
25 return HttpResponse(
26 g.serialize(encoding="utf-8", format="turtle"), content_type="text/turtle"
27 )
28 else:
29 return HttpResponse(
30 g.serialize(encoding="utf-8"), content_type="application/xml"
31 )
34def project_as_arche_graph(request):
35 g = serialize_project()
36 if format == "turtle":
37 return HttpResponse(
38 g.serialize(encoding="utf-8", format="turtle"), content_type="text/turtle"
39 )
40 else:
41 return HttpResponse(
42 g.serialize(encoding="utf-8"), content_type="application/xml"
43 )
46def get_ids(request):
47 limit = request.GET.get("limit", False)
48 base_uri = request.build_absolute_uri().split("/shapes")[0]
49 if limit:
50 try:
51 final_limit = int(limit)
52 except ValueError:
53 final_limit = 10
54 else:
55 final_limit = TempSpatial.objects.all().count()
56 data = {
57 "arche_constants": f"{base_uri}{reverse('shapes:project_as_arche')}",
58 "id_prefix": f"{ARCHE_BASE_URL}",
59 "ids": [
60 {
61 "id": f"{ARCHE_BASE_URL}/{x.source.slug_name()}/{x.slug_name()}",
62 "filename": f"{x.slug_name()}.{ARCHE_DEFAULT_EXTENSION}",
63 "md": f"{base_uri}{x.get_arche_url()}",
64 "html": f"{base_uri}{x.get_absolute_url()}",
65 "payload": f"{base_uri}{x.get_json_url()}?format=json",
66 "mimetype": f"{ARCHE_PAYLOAD_MIMETYPE}",
67 }
68 for x in TempSpatial.objects.all()[0:final_limit]
69 ],
70 }
71 data["ids"].append(
72 {
73 "id": f"{ARCHE_BASE_URL}/histogis_projektlogo_black.png",
74 "filename": "histogis_projektlogo_black.png",
75 "md": f"{base_uri}{reverse('shps:arche_title_img')}",
76 "payload": "https://histogis.acdh.oeaw.ac.at/static/webpage/img/histogis_projektlogo_black.png",
77 "mimetype": "image/png",
78 }
79 )
80 return JsonResponse(data)
83def get_title_img(request):
84 g = title_img()
85 if format == "turtle":
86 return HttpResponse(
87 g.serialize(encoding="utf-8", format="turtle"), content_type="text/turtle"
88 )
89 else:
90 return HttpResponse(
91 g.serialize(encoding="utf-8"), content_type="application/xml"
92 )