Skip to main content

Dummy thumbnails for most popular Django thumbnail generators.

Project description

Dummy thumbnails for most popular Django thumbnail generators.

There are times when you have a database of a Django site and you need to quickly start it up to fix/develop, but then you realise that images are missing and you need to have images, because either your layout is broken or, in the worst case, entire site is broken (500). This library has been written for developers in order to avoid above mentioned problems in the shortest way possible, with least efforts possible.

Prerequisites

  • Django 1.8, 1.9, 1.10

  • Python 2.7, 3.4, 3.5

Although django-dummy-thumbnails is not being tested against older versions of Django, tests do pass with Django versions 1.5, 1.6 and 1.7.

Installation

  1. Install in your virtual environment

    Latest stable version from PyPI:

    pip install django-dummy-thumbnails

    Latest stable version from GitHub:

    pip install https://github.com/barseghyanartur/django-dummy-thumbnails/archive/stable.tar.gz
  2. Add dummy_thumbnails to your INSTALLED_APPS in the global settings.py.

    INSTALLED_APPS = (
        # ...
        'dummy_thumbnails',
        # ...
    )
  3. Specify a custom path to your images directory:

    DUMMY_THUMBNAILS_IMAGES_PATH = '/home/path/to/images/'

    This should be a directory inside your media directory of your Django project. Otherwise Django would raise a SuspiciousOperation exception. In order not to duplicate tons of files for each project, you are advised to create symlinks to the images directory in the media directory of your Django project.

    ln -s /home/path/to/images /home/repos/your-django-project/media

    If you prefer to use included public domain images, run the following management commands:

    ./manage.py collectstatic --noinput
    ./manage.py dummy_thumbnails_symlink_dummy_images

    And specify the following path:

    DUMMY_THUMBNAILS_IMAGES_PATH = os.path.join(MEDIA_ROOT, 'mixed')

Usage

Common usage examples.

Replace broken images with dummy ones

That’s what it’s all about - replacing the broken images with dummy ones.

Supported thumbnailers

Most popular image thumbnailers for Django (django-imagekit, sorl-thumbnail and easy-thumbnails) are supported. If you can’t find your favourite thumbnailer, open an issue or consider making a pull request.

django-imagekit

Integration with django-imagekit.

Modify your settings in the following way:

  1. Add imagekit, dummy_thumbnails and dummy_thumbnails.contrib.thumbnailers.django_imagekit.generatorlibrary to the INSTALLED_APPS:

    INSTALLED_APPS = [
        # ...
        'imagekit',
        'dummy_thumbnails',
        'dummy_thumbnails.contrib.thumbnailers.django_imagekit.generatorlibrary',
        # ...
    ]
  2. If you are using the included public domain images, don’t forget to collect the static files and create a symlink:

    ./manage.py collectstatic --noinput
    ./manage.py dummy_thumbnails_symlink_dummy_images
  3. Now the following would work:

    {% load imagekit %}
    
    {% thumbnail '640x480' 'None1' %}
    {% thumbnail '480x640' 'None2' %}
    {% thumbnail '200x200' 'None3' %}
sorl-thumbnail

Integration with sorl-thumbnail.

Modify your settings in the following way:

  1. Add sorl.thumbnail and dummy_thumbnails to the INSTALLED_APPS:

    INSTALLED_APPS = [
        # ...
        'sorl.thumbnail',
        'dummy_thumbnails',
        # ...
    ]
  2. Set the dummy thumbnail engine as THUMBNAIL_ENGINE:

    THUMBNAIL_ENGINE = 'dummy_thumbnails.contrib.sorl_thumbnail.engines.DummyThumbnailsEngine'
  3. If you are using the included public domain images, don’t forget to collect the static files and create a symlink:

    ./manage.py collectstatic --noinput
    ./manage.py dummy_thumbnails_symlink_dummy_images
  4. Now the following would work:

    {% load thumbnail %}
    
    {% thumbnail 'None1' "640x480" crop="center" as im %}
        <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" />
    {% endthumbnail %}
    
    {% thumbnail 'None2' "480x640" crop="center" as im %}
        <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" />
    {% endthumbnail %}
    
    {% thumbnail 'None3' "200x200" crop="center" as im %}
        <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" />
    {% endthumbnail %}
easy-thumbnails

Integration with easy-thumbnails.

Modify your settings in the following way:

  1. Add easy_thumbnails and dummy_thumbnails to the INSTALLED_APPS:

    INSTALLED_APPS = [
        # ...
        'easy_thumbnails',
        'dummy_thumbnails',
        # ...
    ]
  2. Add dummy thumbnail generator to THUMBNAIL_SOURCE_GENERATORS:

    THUMBNAIL_SOURCE_GENERATORS = (
        'dummy_thumbnails.contrib.thumbnailers.easy_thumbnails.source_generators.dummy_thumbnail',
    )
  3. If you are using the included public domain images, don’t forget to collect the static files and create a symlink:

    ./manage.py collectstatic --noinput
    ./manage.py dummy_thumbnails_symlink_dummy_images
  4. Now the following would work:

    {% load thumbnail %}
    
    <img src="{% thumbnail 'None1' 640x480 crop %}" alt="" />
    <img src="{% thumbnail 'None2' 480x640 crop %}" alt="" />
    <img src="{% thumbnail 'None3' 200x200 crop %}" alt="" />

Dealing with broken or invalid dummy images

Of course, it’s always better to have a good working set of dummy images. However, it might happen that for some reason one of your dummy images is broken.

The recommended approach is to use a management command dummy_thumbnails_verify_dummy_images, which has been written in order to verify the dummy images and identify possible problems. It also lets you remove broken dummy images.

To remove broken dummy images with confirmation, type:

./manage.py dummy_thumbnails_verify_dummy_images

To remove broken dummy images without confirmation, type:

./manage.py dummy_thumbnails_verify_dummy_images --noinput

Another way to avoid failures is to set the value of DUMMY_THUMBNAILS_VERIFY_IMAGES to True in your project settings. Beware, that this slows down the start up time of your Django project, although does not slow down further rendering of the images.

Demo

Run demo locally

In order to be able to quickly evaluate the django-dummy-thumbnails, a demo app (with a quick installer) has been created (works on Ubuntu/Debian, may work on other Linux systems as well, although not guaranteed). Follow the instructions below to have the demo running within a minute.

Grab the latest dummy_thumbnails_demo_installer.sh:

wget -O - https://raw.github.com/barseghyanartur/django-dummy-thumbnails/stable/examples/dummy_thumbnails_demo_installer.sh | bash

Open your browser and test the app.

If quick installer doesn’t work for you, see the manual steps on running the example project.

Testing

Simply type:

./runtests.py

or use tox:

tox

or use tox to check specific env:

tox -e py35

or run Django tests:

./manage.py test dummy_thumbnails --settings=settings.testing

License

GPL 2.0/LGPL 2.1

Support

For any issues contact me at the e-mail given in the Author section.

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-dummy-thumbnails-0.1.9.tar.gz (9.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_dummy_thumbnails-0.1.9-py2.py3-none-any.whl (9.1 MB view details)

Uploaded Python 2Python 3

File details

Details for the file django-dummy-thumbnails-0.1.9.tar.gz.

File metadata

File hashes

Hashes for django-dummy-thumbnails-0.1.9.tar.gz
Algorithm Hash digest
SHA256 7d03f0fe72e27c9d9e27daaefb3223f2e7c38dd22e2bcdf498c8b5b10c1b6b90
MD5 50e0f603d19c001e693418e2b8ba2404
BLAKE2b-256 45cd431e3fca65f68bd47d1ac980bd4272ac2ad7179ab7edb1a36c66df4b44b1

See more details on using hashes here.

File details

Details for the file django_dummy_thumbnails-0.1.9-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_dummy_thumbnails-0.1.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d2fa952f9447f0d3737774eda5cefe4b8237244ccee3f53132390ff66fef7111
MD5 43c76df9629bc7cbaa437af402ee1705
BLAKE2b-256 79bcb0d149539ec967f75cdd1393a06ff3fdcc3767a904ee6a57c85348fa17e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page