Skip to content

Commit

Permalink
prepare orphan prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Jul 1, 2020
1 parent 5f3031d commit b5e2eac
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 28 deletions.
30 changes: 5 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
dist: xenial # has py35!
sudo: false
language: python
cache: pip

python:
- "2.7"
- "3.5"
- "3.6"

env:
matrix:
- REQ='django>=1.11,<2.0 django-filer==1.4.2'
- REQ='django>=2.0,<2.1 django-filer==1.4.2'
# - REQ='django>=2.1,<2.2 FILER="django-filer==1.4.2'

matrix:
allow-failures:
exclude:
- python: '2.7'
env: REQ='django>=2.0,<2.1 django-filer==1.4.2'
- python: '2.7'
env: REQ='django>=2.1,<2.2 django-filer==1.4.2'

# command to install dependencies
install:
- pip install .
- pip install $REQ
- pip install -r test_requirements.txt

# command to run tests
script: python manage.py test
- "3.7"
install: pip install tox-travis
script: tox
8 changes: 8 additions & 0 deletions filer_addons/filer_signals/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
True
)

# fix orphaned files when replacing a file
# https://github.com/divio/django-filer/pull/958
FILER_ADDONS_REPLACE_FIX = getattr(
settings,
'FILER_ADDONS_REPLACE_FIX',
True
)

# also move already existing, that are modified
FILER_ADDONS_UNFILED_HANDLING = getattr(
settings,
Expand Down
28 changes: 27 additions & 1 deletion filer_addons/filer_signals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from . import conf # noqa need the settings

from django.db.models.signals import post_save
from django.db.models.signals import pre_save, post_save
from django.dispatch import receiver
from django.core.files.base import File as DjangoFile
from filer.models import File, Folder
Expand Down Expand Up @@ -147,3 +147,29 @@ def filer_duplicates_and_rename(sender, instance, **kwargs):
(and original_filename) programmatically.
"""
check_rename(instance)


@receiver(
pre_save,
sender='filer.File',
dispatch_uid="filer_addons_prevent_duplicates_file",
)
@receiver(
pre_save,
sender='filer.Image',
dispatch_uid="filer_addons_prevent_duplicates_image",
)
def filer_prevent_rename_orphans(sender, instance, **kwargs):
"""
https://github.com/divio/django-filer/pull/958
"""
if not conf.FILER_ADDONS_REPLACE_FIX:
return
# Delete old file(s) when updating the file via: admin > advanced > replace file
try:
from_db = File.objects.get(id=instance.id)
if from_db.file != instance.file:
from_db.file.delete(save=False)
except FileNotFoundError:
pass
return
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@


django==1.11.29
djangocms-admin-styles==1.4.0
-e git+https://github.com/rouxcode/django-admin-styles.git@master#egg=django-admin-styles
djangocms-admin-style==1.4.0
-e git+https://github.com/rouxcode/django-admin-styles.git@release#egg=django-admin-styles
File renamed without changes.
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ deps =
django111: django>=1.11,<2.0
django20: django>=2.0,<2.1
django21: django>=2.1,<2.2
django22: django>=2.2,<3.0

[testenv:py27-django20-filer142]
whitelist_externals = echo
Expand All @@ -26,5 +27,10 @@ whitelist_externals = echo
deps =
commands= echo "no django 2.1 on python 2.7!"

[testenv:py27-django22-filer142]
whitelist_externals = echo
deps =
commands= echo "no django 2.2 on python 2.7!"

[testenv:flake8]
commands = flake8

0 comments on commit b5e2eac

Please sign in to comment.