-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from scaife-viewer/core/urn-redirects
Improve library / reader URN heuristics
- Loading branch information
Showing
12 changed files
with
193 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
# Scaife Viewer :: Core functionality | ||
|
||
This package was extracted from [https://github.com/scaife-viewer/scaife-viewer](https://github.com/scaife-viewer/scaife-viewer) | ||
This package was extracted from | ||
[https://github.com/scaife-viewer/scaife-viewer](https://github.com/scaife-viewer/scaife-viewer) | ||
|
||
## Settings | ||
|
||
### ALLOW_TRAILING_COLON | ||
Default: `False` | ||
|
||
When `False`, to maintain compatability with the MyCapitain resolver, | ||
the trailing colon will be stripped from URNs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.conf import settings # noqa | ||
|
||
from appconf import AppConf | ||
|
||
|
||
class CoreAppConf(AppConf): | ||
ALLOW_TRAILING_COLON = False | ||
|
||
class Meta: | ||
prefix = "scaife_viewer_core" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
core/scaife_viewer/core/tests/fixtures/templates/site_base.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% comment %} left intentinoally blank {% endcomment %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<GetCapabilities xmlns="http://chs.harvard.edu/xmlns/cts"> | ||
<request> | ||
<requestName>GetInventory</requestName> | ||
<requestFilters>urn=None</requestFilters> | ||
</request> | ||
<reply> | ||
<TextInventory tiid="defaultTic" | ||
xmlns:ns1="http://purl.org/dc/elements/1.1/" | ||
xmlns:skos="http://www.w3.org/2004/02/skos/core#" | ||
xmlns:dts="http://w3id.org/dts-ontology/" | ||
xmlns="http://chs.harvard.edu/xmlns/cts" | ||
xmlns:ns2="http://purl.org/dc/terms/" | ||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> | ||
<textgroup urn="urn:cts:greekLit:tlg0096"> | ||
<groupname xml:lang="eng">Aesop</groupname> | ||
<work urn="urn:cts:greekLit:tlg0096.tlg002" xml:lang="grc" groupUrn="urn:cts:greekLit:tlg0096"> | ||
<title xml:lang="lat">Fabulae</title> | ||
<edition urn="urn:cts:greekLit:tlg0096.tlg002.First1K-grc1" xml:lang="grc" workUrn="urn:cts:greekLit:tlg0096.tlg002"> | ||
<label xml:lang="lat">Fabulae Aesopicae Collectae</label> | ||
<label xml:lang="grc">ΑΙΣΩΠΕΙΩΝ ΜΥΘΩΝ ΣΥΝΑΓΩΓΗ</label> | ||
<description xml:lang="lat">Fabulae Aesopicae Collectae, Halm, Teubner, 1872</description> | ||
<online> | ||
<citationMapping> | ||
<citation xpath="/tei:div[@n='?']" scope="/tei:TEI/tei:text/tei:body/tei:div" label="fabula"></citation> | ||
</citationMapping> | ||
</online> | ||
</edition> | ||
</work> | ||
</textgroup> | ||
<textgroup urn="urn:cts:greekLit:tlg4031"> | ||
<groupname xml:lang="lat">Eustratius</groupname> | ||
<work urn="urn:cts:greekLit:tlg4031.tlg002" xml:lang="grc" groupUrn="urn:cts:greekLit:tlg4031"> | ||
<title xml:lang="lat">In Aristotelis Ethica Nicomachea I Commentaria</title> | ||
<edition urn="urn:cts:greekLit:tlg4031.tlg002.opp-grc1" xml:lang="grc" workUrn="urn:cts:greekLit:tlg4031.tlg002"> | ||
<label xml:lang="lat">In Aristotelis Ethica Nicomachea I Commentaria</label> | ||
<description xml:lang="mul">Eustratius, In Aristotelis Ethica Nicomachea I Commentaria, Commentaria in Aristotelem Graeca 20, | ||
Reimer, Heylbut, 1892</description> | ||
<online> | ||
<citationMapping> | ||
<citation xpath="/tei:div[@n='?']" scope="/tei:TEI/tei:text/tei:body/tei:div" label="chapter"></citation> | ||
</citationMapping> | ||
</online> | ||
</edition> | ||
</work> | ||
</textgroup> | ||
</TextInventory> | ||
</reply> | ||
</GetCapabilities> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,42 @@ | ||
from django.test import TestCase | ||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
|
||
from ..utils import normalize_urn | ||
|
||
class Tests(TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
class URNTests(TestCase): | ||
def test_urn_normalized(self): | ||
provided_urn = "urn:cts:greekLit:tlg0096.tlg002.First1K-grc1:" | ||
acceptable_urn = "urn:cts:greekLit:tlg0096.tlg002.First1K-grc1" | ||
result = normalize_urn(provided_urn) | ||
assert result == acceptable_urn | ||
|
||
@override_settings(SCAIFE_VIEWER_CORE_ALLOW_TRAILING_COLON=True) | ||
def test_urn_trailing_colon_not_normalized(self): | ||
provided_urn = "urn:cts:greekLit:tlg0096.tlg002.First1K-grc1:" | ||
result = normalize_urn(provided_urn) | ||
assert result == provided_urn | ||
|
||
def test_urn_unmodified(self): | ||
provided_urn = "urn:cts:greekLit:tlg0096.tlg002.First1K-grc1" | ||
result = normalize_urn(provided_urn) | ||
assert result == provided_urn | ||
|
||
|
||
class ViewTests(TestCase): | ||
def test_reader_version_urn_redirects_to_first_passage(self): | ||
urn = "urn:cts:greekLit:tlg0096.tlg002.First1K-grc1" | ||
reader_url = reverse("reader", kwargs={"urn": urn}) | ||
response = self.client.get(reader_url, follow=True) | ||
assert len(response.redirect_chain) == 2 | ||
assert ( | ||
response.wsgi_request.path | ||
== "/reader/urn:cts:greekLit:tlg0096.tlg002.First1K-grc1:1-4b/" | ||
) | ||
|
||
def test_reader_work_urn_redirects_to_library(self): | ||
urn = "urn:cts:greekLit:tlg0096.tlg002" | ||
reader_url = reverse("reader", kwargs={"urn": urn}) | ||
response = self.client.get(reader_url, follow=True) | ||
assert len(response.redirect_chain) == 2 | ||
assert response.wsgi_request.path == "/library/urn:cts:greekLit:tlg0096.tlg002/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
urlpatterns = [] | ||
from django.urls import path | ||
|
||
from .views import LibraryCollectionView, Reader, library_text_redirect | ||
|
||
|
||
urlpatterns = [ | ||
path( | ||
"library/<str:urn>/", | ||
LibraryCollectionView.as_view(format="html"), | ||
name="library_collection", | ||
), | ||
path( | ||
"library/<str:urn>/redirect/", | ||
library_text_redirect, | ||
name="library_text_redirect", | ||
), | ||
path("reader/<str:urn>/", Reader.as_view(), name="reader"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters