Skip to content
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

Prepare test for widgets and split tests for admin #62

Merged
merged 2 commits into from
Nov 5, 2024
Merged
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
9 changes: 5 additions & 4 deletions import_export_extensions/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.core.files import File
from django.core.files.storage import default_storage
from django.db.models import Model, Q, QuerySet
from django.db.models.fields.files import FieldFile
from django.forms import ValidationError
from django.utils.encoding import smart_str

Expand Down Expand Up @@ -294,7 +295,7 @@ def __init__(self, filename: str):

def render(
self,
value: Model | None,
value: FieldFile | None,
obj=None,
**kwargs,
) -> str | None:
Expand All @@ -320,12 +321,12 @@ def clean(
internal_url = utils.url_to_internal_value(urlparse(value).path)

if not internal_url:
raise ValidationError("Invalid image path")
raise ValidationError("Invalid file path")

try:
if default_storage.exists(internal_url):
return internal_url
except SuspiciousFileOperation:
except SuspiciousFileOperation: # pragma: no cover
pass

return self._get_file(value)
Expand All @@ -350,4 +351,4 @@ def _get_default_storage(self) -> str:
"""
if hasattr(settings, "STORAGES"):
return settings.STORAGES["default"]["BACKEND"]
return settings.DEFAULT_FILE_STORAGE
return settings.DEFAULT_FILE_STORAGE # pragma: no cover
Loading