django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.73k stars 574 forks source link

thumbnail is missing... [BUG] #1412

Closed prepstarr closed 10 months ago

prepstarr commented 10 months ago

Description

thumbnail image in the preview section is missing ...

image

Steps to reproduce

Expected behaviour

thumbnail should show image

show image

Actual behaviour

broken link

FILER_STORAGES = {
    'public': {
            'OPTIONS': {
                'location': '/home/sixpiece/python/emploiquebec/media/filer',
                'base_url': '/media/filer/',
            },
            'UPLOAD_TO': 'filer.utils.generate_filename.randomized',
            'UPLOAD_TO_PREFIX': 'filer_public',
        },
        'thumbnails': {
                'location': '/home/sixpiece/python/emploiquebec/media/filer_thumbnails',
                'base_url': '/media/filer_thumbnails/',
            },
        },
    },
    'private': {
        'main': {
            'ENGINE': 'filer.storage.PrivateFileSystemStorage',
            'OPTIONS': {
                'location': '/usr/home/sixpiece/python/emploiquebec/smedia/filer',
                'base_url': '/smedia/filer/',
            },
            'UPLOAD_TO': 'filer.utils.generate_filename.randomized',
            'UPLOAD_TO_PREFIX': 'filer_public',
        },
        'thumbnails': {
            'ENGINE': 'filer.storage.PrivateFileSystemStorage',
            'OPTIONS': {
                'location': '/usr/home/sixpiece/python/emploiquebec/smedia/filer_thumbnails',
                'base_url': '/smedia/filer_thumbnails/',
            },
        },
    },
} 
```in settings.py

this directory exists : ```
/home/sixpiece/python/emploiquebec/media/filer_thumbnails/filer_public_thumbnails/filer_public/fb/5b/fb5bdd6d-9a78-4a7c-ab42-39c41d3b510b this directory exists and the following files exist: sheldon-lub.png__160x160_q85_crop_subsampling-2.jpg
sheldon-lub.png__180x180_q85_crop_subsampling-2_upscale.jpg
sheldon-lub.png__40x40_q85_crop_subsampling-2.jpg
sheldon-lub.png__70x70_q85_crop_subsampling-2.jpg
sheldon-lub.png__70x70_q85_subsampling-2.jpg
sheldon-lub.png__80x80_q85_crop_subsampling-2.jpg

it looks like it's close but for some reason thumbnail is not generated...

Screenshots

Additional information (CMS/Python/Django versions)

Do you want to help fix this issue?

fsbraun commented 10 months ago

Can you share your MEDIA settings?

prepstarr commented 10 months ago

Yes my apologies for the late return if this is not the right answer, I will be back at it on Saturday night... I was up late that night and did an hour sieste now but I want to finish making my soup , etc..

adding MEDIA root

MEDIA_ROOT = '/usr/home/sixpiece/python/emploiquebec/media'

MEDIA_URL = '/media/'e__).resolve().parent.parent

fsbraun commented 10 months ago

The MEDIA_URL line seems garbeled ... at least by the balance of opening and closing brackets?

prepstarr commented 10 months ago

sorry about that there was probably something wrong with how it posted...

adding MEDIA root

MEDIA_ROOT = '/usr/home/sixpiece/python/emploiquebec/media'

MEDIA_URL = '/media/'

I just looked at it now and was wondering how I came up with such a thing...

going to share the whole settings.py ...

prepstarr commented 10 months ago
from pathlib import Path

import os.path

USE_TZ = False

FILER_CANONICAL_URL = 'canonical/'

BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = 'd87%15x3pBU7*k&@L11PkBtn38oQiNhJ2IX9iqA8d0p%sfikc2m@5p'

DEBUG = True
ALLOWED_HOSTS = [
   'emploisquebec.net'
]

# Application definition

INSTALLED_APPS = [
    'debug_toolbar',
    'filemanager',
    'filer',
    'easy_thumbnails',
    'emplois.apps.EmploisConfig',
    'splashpage',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bootstrap5',
]

MIDDLEWARE = [
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'emploiquebec.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / "templates"],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

FILER_SERVERS = {
    'private': {
        'main': {
            'ENGINE': 'filer.server.backends.xsendfile.ApacheXSendfileServer',
            },
        'thumbnails': {
            'ENGINE': 'filer.server.backends.xsendfile.ApacheXSendfileServer',
            },
        },
    }

WSGI_APPLICATION = 'emploiquebec.wsgi.application'

MEDIA_ROOT = '/usr/home/sixpiece/python/emploiquebec/media'

MEDIA_URL = '/media/'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

THUMBNAIL_HIGH_RESOLUTION = True

THUMBNAIL_PROCESSORS = (
    'easy_thumbnails.processors.colorspace',
    'easy_thumbnails.processors.autocrop',
    'filer.thumbnail_processors.scale_and_crop_with_subject_location',
    'easy_thumbnails.processors.filters',
)

FILER_ENABLE_PERMISSIONS = True

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',

    },
]

LANGUAGE_CODE = 'de-de'

TIME_ZONE = 'Berlin/Europe'

USE_I18N = True

USE_TZ = True

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles/'

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

FILER_STORAGES = {
    'public': {
        'main': {
            'ENGINE': 'filer.storage.PublicFileSystemStorage',
            'OPTIONS': {
                'location': '/home/sixpiece/python/emploiquebec/media/filer',
                'base_url': '/media/filer/',
            },
            'UPLOAD_TO': 'filer.utils.generate_filename.randomized',
            'UPLOAD_TO_PREFIX': 'filer_public',
        },
        'thumbnails': {
            'ENGINE': 'filer.storage.PublicFileSystemStorage',
            'OPTIONS': {
                'location': '/home/sixpiece/python/emploiquebec/media/filer_thumbnails',
                'base_url': '/media/filer_thumbnails/',
            },
        },
    },
    'private': {
        'main': {
            'ENGINE': 'filer.storage.PrivateFileSystemStorage',
            'OPTIONS': {
                'location': '/usr/home/sixpiece/python/emploiquebec/smedia/filer',
                'base_url': '/smedia/filer/',
            },
            'UPLOAD_TO': 'filer.utils.generate_filename.randomized',
            'UPLOAD_TO_PREFIX': 'filer_public',
        },
        'thumbnails': {
            'ENGINE': 'filer.storage.PrivateFileSystemStorage',
            'OPTIONS': {
                'location': '/usr/home/sixpiece/python/emploiquebec/smedia/filer_thumbnails',
                'base_url': '/smedia/filer_thumbnails/',
            },
        },
    },
}
prepstarr commented 10 months ago

here's the issue as far as I see... is the thumbnail

'filer.thumbnail_processors.scale_and_crop_with_subject_location', will not work but if I use

'easy_thumbnails.processors.scale_and_crop', then it works.... cause it gives a different location

prepstarr commented 10 months ago

for example it looks for this thumbnail : https://tld-withheld.net/media/filer_public_thumbnails/filer_public/fb/5b/fb5bdd6d-9a78-4a7c-ab42-39c41d3b510b/sheldon-lub.png__40x40_q85_crop_subsampling-2.jpg

sheldon-lub.png__40x40_q85_crop_subsampling-2.jpg a little bit odd...

prepstarr commented 10 months ago

I set it back to 'filer.thumbnail_processors.scale_and_crop_with_subject_location' what I notice is that the minute it uploads the picture it's there but if I refresh it's gone...

prepstarr commented 10 months ago
(env) $ python manage.py filer_check --orphans
Traceback (most recent call last):
  File "/usr/home/sixpiece/python/emploiquebec/manage.py", line 22, in <module>
    main()
  File "/usr/home/sixpiece/python/emploiquebec/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/home/sixpiece/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/home/sixpiece/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/home/sixpiece/env/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/home/sixpiece/env/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/usr/home/sixpiece/env/lib/python3.9/site-packages/filer/management/commands/filer_check.py", line 66, in handle
    self.verify_storages(options)
  File "/usr/home/sixpiece/env/lib/python3.9/site-packages/filer/management/commands/filer_check.py", line 114, in verify_storages
    walk(filer_public['UPLOAD_TO_PREFIX'])
  File "/usr/home/sixpiece/env/lib/python3.9/site-packages/filer/management/commands/filer_check.py", line 95, in walk
    child_dirs, files = storage.listdir(prefix)
  File "/usr/home/sixpiece/env/lib/python3.9/site-packages/django/core/files/storage/filesystem.py", line 170, in listdir
    with os.scandir(path) as entries:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/home/sixpiece/python/emploiquebec/media/filer_public'
prepstarr commented 10 months ago

apologize for the fatigure of the other I was up late doing the system upgrades, etc..

prepstarr commented 10 months ago

it's missing filer_thumbnails in the path... between /media/"missing here"/filer_public_thumbnails ...

fsbraun commented 10 months ago

Your settings look good to me.

Just to nail this down: I assume the issue disappears if you remove your custom thumbnail filer storage? If so, I assume there is a bug using the wrong storage (default storage as opposed to thumbnail storage). Can you confirm?

prepstarr commented 10 months ago

yes that is correct, on new pictures if I comment out the thumbnail storage it will work properly...

prepstarr commented 10 months ago

it seems to fix the issue... in fact because by selecting the image it will recreate the thumbnail and it will work... should I close this issue?

prepstarr commented 10 months ago

thank you...

prepstarr commented 10 months ago

image

fsbraun commented 10 months ago

I think you found a real bug: If you have a custom file storage for thumbnails, it needs to be reflected in the directory listing. Leave this issue open.

fsbraun commented 10 months ago

I would like to come up with a fix. Once I've done that, could you test it with your original settings?

fsbraun commented 10 months ago

Here's a fix: #1413

Can you test if it works with your original settings? You can install the fix using pip install git+https://github.com/fsbraun/django-filer@fix/respect_storage_settings.

prepstarr commented 10 months ago

no it's not working...

prepstarr commented 10 months ago
(env) $ pip install git+https://github.com/fsbraun/django-filer@fix/respect_storage_settings
Collecting git+https://github.com/fsbraun/django-filer@fix/respect_storage_settings
  Cloning https://github.com/fsbraun/django-filer (to revision fix/respect_storage_settings) to /tmp/pip-req-build-_9wz1bv2
  Running command git clone --filter=blob:none --quiet https://github.com/fsbraun/django-filer /tmp/pip-req-build-_9wz1bv2
  Running command git checkout -b fix/respect_storage_settings --track origin/fix/respect_storage_settings
  Switched to a new branch 'fix/respect_storage_settings'
  branch 'fix/respect_storage_settings' set up to track 'origin/fix/respect_storage_settings'.
  Resolved https://github.com/fsbraun/django-filer to commit efbd71e7d454ccb1463db6631f9415b3ab6dcada
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: django<5,>=3.2 in /usr/home/sixpiece/env/lib/python3.9/site-packages (from django-filer==3.0.4) (4.2.4)
Requirement already satisfied: django-polymorphic in /usr/home/sixpiece/env/lib/python3.9/site-packages (from django-filer==3.0.4) (3.1.0)
Requirement already satisfied: easy-thumbnails[svg] in /usr/home/sixpiece/env/lib/python3.9/site-packages (from django-filer==3.0.4) (2.8.5)
Requirement already satisfied: asgiref<4,>=3.6.0 in /usr/home/sixpiece/env/lib/python3.9/site-packages (from django<5,>=3.2->django-filer==3.0.4) (3.7.2)
Requirement already satisfied: sqlparse>=0.3.1 in /usr/home/sixpiece/env/lib/python3.9/site-packages (from django<5,>=3.2->django-filer==3.0.4) (0.4.4)
Requirement already satisfied: pillow in /usr/home/sixpiece/env/lib/python3.9/site-packages (from easy-thumbnails[svg]->django-filer==3.0.4) (10.0.0)
Requirement already satisfied: svglib in /usr/home/sixpiece/env/lib/python3.9/site-packages (from easy-thumbnails[svg]->django-filer==3.0.4) (1.5.1)
Requirement already satisfied: reportlab in /usr/home/sixpiece/env/lib/python3.9/site-packages (from easy-thumbnails[svg]->django-filer==3.0.4) (4.0.4)
Requirement already satisfied: typing-extensions>=4 in /usr/home/sixpiece/env/lib/python3.9/site-packages (from asgiref<4,>=3.6.0->django<5,>=3.2->django-filer==3.0.4) (4.7.1)
Requirement already satisfied: lxml in /usr/home/sixpiece/env/lib/python3.9/site-packages (from svglib->easy-thumbnails[svg]->django-filer==3.0.4) (4.9.3)
Requirement already satisfied: tinycss2>=0.6.0 in /usr/home/sixpiece/env/lib/python3.9/site-packages (from svglib->easy-thumbnails[svg]->django-filer==3.0.4) (1.2.1)
Requirement already satisfied: cssselect2>=0.2.0 in /usr/home/sixpiece/env/lib/python3.9/site-packages (from svglib->easy-thumbnails[svg]->django-filer==3.0.4) (0.7.0)
Requirement already satisfied: webencodings in /usr/home/sixpiece/env/lib/python3.9/site-packages (from cssselect2>=0.2.0->svglib->easy-thumbnails[svg]->django-filer==3.0.4) (0.5.1)
fsbraun commented 10 months ago

This install looks all right. To be on the safe side, you might try uninstalling filer beforehand (pip uninstall django-filer) and then reinstall from the repo. I think it should now respect your custom filer storage settings (and add the missing filer_thumbnails to the thumbnail URL.

I guess we should also have a test for that.

prepstarr commented 10 months ago

image thank you it seems to be working now... should I close the issue now?

fsbraun commented 10 months ago

Let's leave this open until the fix is merged :-) Thank you for your help! Great work!

prepstarr commented 10 months ago

you're welcome, thank you for the help as well..