Skip to content

Commit

Permalink
Accept WAGTAILADMIN_BASE_URL in preference to BASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed May 11, 2022
1 parent 37bcb98 commit 6875cd8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion wagtail_transfer/field_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.fields.reverse_related import ManyToOneRel
from django.utils.functional import cached_property
Expand All @@ -31,6 +32,10 @@
DELETED_REVERSE_RELATIONS = {
(model_label.lower(), relation.lower()) for model_label, relation, track_deletions in WAGTAILTRANSFER_FOLLOWED_REVERSE_RELATIONS if track_deletions
}
ADMIN_BASE_URL = getattr(
settings, "WAGTAILADMIN_BASE_URL",
getattr(settings, "BASE_URL", None)
)


class FieldAdapter:
Expand Down Expand Up @@ -283,7 +288,11 @@ def serialize(self, instance):
if url.startswith('/'):
# Using a relative media url. ie. /media/
# Prepend the BASE_URL to turn this into an absolute URL
url = settings.BASE_URL.rstrip('/') + url
if ADMIN_BASE_URL is None:
raise ImproperlyConfigured(
"A WAGTAILADMIN_BASE_URL or BASE_URL setting must be provided when importing files"
)
url = ADMIN_BASE_URL.rstrip('/') + url
return {
'download_url': url,
'size': get_file_size(self.field, instance),
Expand Down

0 comments on commit 6875cd8

Please sign in to comment.