Skip to content

Bugfix: Add WAGTAILADMIN_BASE_URL in the get_media_item_url function #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion grapple/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ def get_media_item_url(cls):
url = cls.file.url

if url[0] == "/":
return settings.BASE_URL + url
if hasattr(settings, "WAGTAILADMIN_BASE_URL"):
return settings.WAGTAILADMIN_BASE_URL + url
elif hasattr(settings, "BASE_URL"):
return settings.BASE_URL + url
return url


Expand Down
6 changes: 3 additions & 3 deletions tests/test_blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_blog_body_imagechooserblock(self):
)
self.assertEqual(
query_blocks[count]["image"]["src"],
settings.BASE_URL + block.value.file.url,
settings.WAGTAILADMIN_BASE_URL + block.value.file.url,
)
# Increment the count
count += 1
Expand Down Expand Up @@ -370,7 +370,7 @@ def test_blog_body_imageblock(self):
)
self.assertEqual(
query_blocks[count]["image"]["src"],
settings.BASE_URL + block.value.file.url,
settings.WAGTAILADMIN_BASE_URL + block.value.file.url,
)
self.assertEqual(
query_blocks[count]["decorative"], block.value.decorative
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_blog_body_imagegalleryblock(self):
)
self.assertEqual(
image["image"]["src"],
settings.BASE_URL
settings.WAGTAILADMIN_BASE_URL
+ str(block.value["images"][key].value["image"].file.url),
)
# Increment the count
Expand Down