Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
0d912738
Commit
0d912738
authored
10 months ago
by
ml bonhomme
Committed by
Bastien Abadie
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Do not use urljoin to generate IIIF url and thumbnail URL when the image URL has query parameters
parent
6688e756
No related branches found
No related tags found
1 merge request
!2309
Do not use urljoin to generate IIIF url and thumbnail URL when the image URL has query parameters
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/models.py
+12
-1
12 additions, 1 deletion
arkindex/documents/models.py
arkindex/documents/tests/test_element.py
+38
-10
38 additions, 10 deletions
arkindex/documents/tests/test_element.py
with
50 additions
and
11 deletions
arkindex/documents/models.py
+
12
−
1
View file @
0d912738
import
re
import
uuid
from
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
,
urlparse
from
django.conf
import
settings
from
django.contrib.contenttypes.fields
import
GenericRelation
...
...
@@ -649,6 +649,11 @@ class Element(IndexableModel):
from
arkindex.project.tools
import
bounding_box
x
,
y
,
width
,
height
=
bounding_box
(
self
.
polygon
)
# Handle IIIF URLs with query parameters (cannot use urljoin as it will remove the query parameters)
parsed_url
=
urlparse
(
self
.
image
.
url
)
if
parsed_url
.
query
:
return
f
"
{
self
.
image
.
url
}
/
{
x
}
,
{
y
}
,
{
width
}
,
{
height
}
/full/0/default.jpg
"
return
urljoin
(
self
.
image
.
url
+
"
/
"
,
f
"
{
x
}
,
{
y
}
,
{
width
}
,
{
height
}
/full/0/default.jpg
"
...
...
@@ -671,6 +676,12 @@ class Element(IndexableModel):
# Do no attempt to upsize small images for thumbnails
thumbnail_height
=
min
(
400
,
height
)
# Handle IIIF URLs with query parameters (cannot use urljoin as it will remove the query parameters)
parsed_url
=
urlparse
(
self
.
image
.
url
)
if
parsed_url
.
query
:
return
f
"
{
self
.
image
.
url
}
/
{
x
}
,
{
y
}
,
{
width
}
,
{
height
}
/,
{
thumbnail_height
}
/
{
rotation_param
}
/default.jpg
"
return
urljoin
(
self
.
image
.
url
+
"
/
"
,
f
"
{
x
}
,
{
y
}
,
{
width
}
,
{
height
}
/,
{
thumbnail_height
}
/
{
rotation_param
}
/default.jpg
"
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_element.py
+
38
−
10
View file @
0d912738
...
...
@@ -36,23 +36,51 @@ class TestElement(FixtureTestCase):
)
self
.
assertEqual
(
element
.
iiif_url
,
"
http://server/img1/10,20,30,40/full/0/default.jpg
"
)
def
test_iiif_url_query_params
(
self
):
# Element.iiif_url can handles URLs with query parameters
test_image
=
self
.
imgsrv
.
images
.
create
(
path
=
"
blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif
"
,
width
=
1000
,
height
=
1000
,)
element
=
Element
(
name
=
"
Something
"
,
type
=
self
.
element_type
,
image
=
test_image
,
polygon
=
[
[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
],
],
)
self
.
assertEqual
(
element
.
iiif_url
,
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/10,20,30,40/full/0/default.jpg
"
)
def
test_iiif_thumbnail_url
(
self
):
test_image
=
self
.
imgsrv
.
images
.
create
(
path
=
"
blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif
"
,
width
=
1000
,
height
=
1000
,)
cases
=
[
(
0
,
False
,
[[
500
,
100
],
[
650
,
100
],
[
650
,
800
],
[
500
,
800
],
[
500
,
100
]],
"
http://server/img1/500,100,150,700/,400/0/default.jpg
"
),
(
0
,
True
,
[[
500
,
100
],
[
650
,
100
],
[
650
,
800
],
[
500
,
800
],
[
500
,
100
]],
"
http://server/img1/500,100,150,700/,400/!0/default.jpg
"
),
(
180
,
False
,
[[
500
,
580
],
[
650
,
580
],
[
650
,
700
],
[
500
,
700
],
[
500
,
580
]],
"
http://server/img1/500,580,150,120/,120/180/default.jpg
"
),
(
180
,
True
,
[[
500
,
580
],
[
650
,
580
],
[
650
,
700
],
[
500
,
700
],
[
500
,
580
]],
"
http://server/img1/500,580,150,120/,120/!180/default.jpg
"
),
(
0
,
False
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/img1/10,20,30,40/,40/0/default.jpg
"
),
(
0
,
True
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/img1/10,20,30,40/,40/!0/default.jpg
"
),
(
180
,
False
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/img1/10,20,30,40/,40/180/default.jpg
"
),
(
180
,
True
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/img1/10,20,30,40/,40/!180/default.jpg
"
),
(
self
.
image
,
0
,
False
,
[[
500
,
100
],
[
650
,
100
],
[
650
,
800
],
[
500
,
800
],
[
500
,
100
]],
"
http://server/img1/500,100,150,700/,400/0/default.jpg
"
),
(
self
.
image
,
0
,
True
,
[[
500
,
100
],
[
650
,
100
],
[
650
,
800
],
[
500
,
800
],
[
500
,
100
]],
"
http://server/img1/500,100,150,700/,400/!0/default.jpg
"
),
(
self
.
image
,
180
,
False
,
[[
500
,
580
],
[
650
,
580
],
[
650
,
700
],
[
500
,
700
],
[
500
,
580
]],
"
http://server/img1/500,580,150,120/,120/180/default.jpg
"
),
(
self
.
image
,
180
,
True
,
[[
500
,
580
],
[
650
,
580
],
[
650
,
700
],
[
500
,
700
],
[
500
,
580
]],
"
http://server/img1/500,580,150,120/,120/!180/default.jpg
"
),
(
self
.
image
,
0
,
False
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/img1/10,20,30,40/,40/0/default.jpg
"
),
(
self
.
image
,
0
,
True
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/img1/10,20,30,40/,40/!0/default.jpg
"
),
(
self
.
image
,
180
,
False
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/img1/10,20,30,40/,40/180/default.jpg
"
),
(
self
.
image
,
180
,
True
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/img1/10,20,30,40/,40/!180/default.jpg
"
),
# Image with query parameters in the IIIF URL
(
test_image
,
0
,
False
,
[[
500
,
100
],
[
650
,
100
],
[
650
,
800
],
[
500
,
800
],
[
500
,
100
]],
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/500,100,150,700/,400/0/default.jpg
"
),
(
test_image
,
0
,
True
,
[[
500
,
100
],
[
650
,
100
],
[
650
,
800
],
[
500
,
800
],
[
500
,
100
]],
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/500,100,150,700/,400/!0/default.jpg
"
),
(
test_image
,
180
,
False
,
[[
500
,
580
],
[
650
,
580
],
[
650
,
700
],
[
500
,
700
],
[
500
,
580
]],
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/500,580,150,120/,120/180/default.jpg
"
),
(
test_image
,
180
,
True
,
[[
500
,
580
],
[
650
,
580
],
[
650
,
700
],
[
500
,
700
],
[
500
,
580
]],
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/500,580,150,120/,120/!180/default.jpg
"
),
(
test_image
,
0
,
False
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/10,20,30,40/,40/0/default.jpg
"
),
(
test_image
,
0
,
True
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/10,20,30,40/,40/!0/default.jpg
"
),
(
test_image
,
180
,
False
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/10,20,30,40/,40/180/default.jpg
"
),
(
test_image
,
180
,
True
,
[[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
]],
"
http://server/blahblah-bin/something.something?IIIF=01/02/2020601/https___moon_prism__power/makeup.original.tif/10,20,30,40/,40/!180/default.jpg
"
),
]
for
rotation_angle
,
mirrored
,
polygon
,
expected_url
in
cases
:
for
image
,
rotation_angle
,
mirrored
,
polygon
,
expected_url
in
cases
:
with
self
.
subTest
(
rotation_angle
=
rotation_angle
,
mirrored
=
mirrored
):
element
=
Element
(
name
=
"
Something
"
,
type
=
self
.
element_type
,
image
=
self
.
image
,
image
=
image
,
polygon
=
polygon
,
rotation_angle
=
rotation_angle
,
mirrored
=
mirrored
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment