Skip to content

Commit

Permalink
added /uri and /entity urls
Browse files Browse the repository at this point in the history
ToDo: add a param to return html/xml-tei/json
  • Loading branch information
csae8092 committed Jan 3, 2024
1 parent 851f851 commit 7aacf7b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 14 additions & 0 deletions apis_core/apis_entities/resolver_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
from django.shortcuts import redirect
from django.urls.exceptions import NoReverseMatch

from apis_core.apis_metainfo.models import TempEntityClass, Uri

Expand All @@ -19,3 +20,16 @@ def uri_resolver(request):
entity = TempEntityClass.objects_inheritance.get_subclass(pk=uri.entity_id)
url = entity.get_absolute_url()
return redirect(url)


def entity_resolver(request, pk):
try:
TempEntityClass.objects.get(id=pk)
except ObjectDoesNotExist:
raise Http404
entity = TempEntityClass.objects_inheritance.get_subclass(pk=pk)
try:
url = entity.get_absolute_url()
except NoReverseMatch:
raise Http404
return redirect(url)
12 changes: 11 additions & 1 deletion apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ class EntitiesTestCase(TestCase):
]

def setUp(self):
# Create two users
User.objects.create_user(**USER)

def test_001a_entity_resolver(self):
url = reverse("entity-resolver", kwargs={"pk": 4})
r = client.get(url)
self.assertEqual(r.status_code, 404)
url = reverse("entity-resolver", kwargs={"pk": 44442344})
r = client.get(url)
self.assertEqual(r.status_code, 404)
url = reverse("entity-resolver", kwargs={"pk": 1})
r = client.get(url)
self.assertEqual(r.status_code, 302)

def test_001_list_view(self):
for x in MODELS:
try:
Expand Down
1 change: 1 addition & 0 deletions pmb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
path("admin/", admin.site.urls),
path("arche/", include("archemd.urls", namespace="archemd")),
path("uri/", resolver_views.uri_resolver, name="uri-resolver"),
path("entity/<int:pk>/", resolver_views.entity_resolver, name="entity-resolver"),
path("", include("dumper.urls", namespace="dumper")),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

0 comments on commit 7aacf7b

Please sign in to comment.