Skip to content

Commit

Permalink
fix: File expand url incorrect and worked not with custom image models (
Browse files Browse the repository at this point in the history
#1471)

* Fix #1377

* Fix issue #1470

* Update tests

* Update `tox.ini`

* Update tox.ini

Co-authored-by: Mark Walker <theshow@gmail.com>

---------

Co-authored-by: Mark Walker <theshow@gmail.com>
  • Loading branch information
fsbraun and marksweb authored May 21, 2024
1 parent db416e6 commit c8af44a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11', '3.12']
requirements-file: [
django-3.2.txt,
django-4.0.txt,
django-4.1.txt,
django-4.2.txt,
django-5.0.txt,
django-main.txt,
]
custom-image-model: [false, true]
exclude:
- requirements-file: django-5.0.txt
python-version: 3.8
- requirements-file: django-5.0.txt
python-version: 3.9
os: [
ubuntu-20.04,
]
Expand Down
15 changes: 10 additions & 5 deletions filer/models/filemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,24 @@ def has_generic_permission(self, request, permission_type):
else:
return False

def get_admin_change_url(self):
def get_admin_url(self, action):
return reverse(
'admin:{}_{}_change'.format(
'admin:{}_{}_{}'.format(
self._meta.app_label,
self._meta.model_name,
action
),
args=(self.pk,)
)

def get_admin_change_url(self):
return self.get_admin_url("change")

def get_admin_expand_view_url(self):
return self.get_admin_url("expand")

def get_admin_delete_url(self):
return reverse(
f'admin:{self._meta.app_label}_{self._meta.model_name}_delete',
args=(self.pk,))
return self.get_admin_url("delete")

@property
def url(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
</td>
<td class="column-action">
{% if file.canonical_url %}
<a href="{% if 'svg' in file.mime_type %}{% url 'admin:filer_image_expand_view' file.pk %}{% else %}{{ file.canonical_url }}{% endif %}"
<a href="{% if 'svg' in file.mime_type %}{{ file.get_admin_expand_view_url }}{% else %}{{ file.canonical_url }}{% endif %}"
data-url="{{ file.canonical_url }}"
data-msg="{% trans 'URL copied to clipboard' %}"
rel="noopener noreferrer"
Expand Down
4 changes: 4 additions & 0 deletions tests/requirements/django-main.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r base.txt

git+https://github.com/django/django@main#egg=Django
django_polymorphic>=3.1
1 change: 1 addition & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ def test_image_expand_view(self):

response = self.client.get(url)

self.assertEqual(url, self.file_object.get_admin_expand_view_url())
self.assertContains(
response,
f"""<img id="img" src="{original_url}" onclick="this.classList.toggle('zoom')"/>"""
Expand Down
14 changes: 6 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ envlist =
isort
docs
frontend
py{38,39,310}-dj32-{swap,noswap}
py{38,39,310,311}-{dj40,dj41,dj42}-{swap,noswap}
py{310,311}-{dj50}-{swap,noswap}
py{310,311,312}-{dj42,dj50,djmain}-{swap,noswap}

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312

skip_missing_interpreters=True

[testenv]
allowlist_externals =
{env:COMMAND:coverage}
{envpython}
deps =
dj32: -r tests/requirements/django-3.2.txt
dj40: -r tests/requirements/django-4.0.txt
dj41: -r tests/requirements/django-4.1.txt
dj42: -r tests/requirements/django-4.2.txt
dj50: -r tests/requirements/django-5.0.txt
djmain: -r tests/requirements/django-main.txt
commands =
{envpython} --version
{env:COMMAND:coverage} erase
Expand Down

0 comments on commit c8af44a

Please sign in to comment.