eximagination package

Submodules

eximagination.apps module

Apps.

class eximagination.apps.Config(app_name, app_module)[source]

Bases: django.apps.config.AppConfig

Config.

label = 'eximagination'
name = 'eximagination'

eximagination.conf module

eximagination.conf.get_setting(setting, override=None)[source]

Get setting.

Get a setting from eximagination conf module, falling back to the default.

If override is not None, it will be used instead of the setting.

Parameters:
  • setting – String with setting name
  • override – Value to use when no setting is available. Defaults to None.
Returns:

Setting value.

eximagination.defaults module

eximagination.helpers module

eximagination.helpers.project_dir(base)[source]

Get path to directory/file from current path.

eximagination.helpers.PROJECT_DIR(base)

Get path to directory/file from current path.

eximagination.settings module

eximagination.tests module

class eximagination.tests.EximaginationUtilsTest(methodName='runTest')[source]

Bases: unittest.case.TestCase

Tests of eximagination.utils.obtain_image function.

setUp()[source]

Set up.

test_01_obtain_image(*args, **kwargs)[source]
eximagination.tests.log_info(func)[source]

Log some useful info.

eximagination.utils module

eximagination.utils.obtain_image(image_source='', save_to='', media_url='', force_update=False, expiration_interval=None, debug=False)[source]

Get an image from absolute url and saves it locally.

Check whether image already exists in local directory and only if not - try to download it and save it. Validate validity of the image (rely on PIL Image class validation).

Parameters:
  • image_source (str) –
  • save_to (str) –
  • media_url (str) –
  • force_update (bool) –
  • expiration_interval (int) – Expiration interval in seconds.
  • debug (bool) –
Return list:

(relative_url_of_the_image, original_image_width, original_image_height)

Module contents

A Django template tag library which allows to download external images, store them locally and return the local path to locally stored image to a desired context variable, along with width and height of the image fetched. Caches the fetched images locally for the given time (set in settings). You could, for example, use this app to solve the problems with displaying of a mixed content (assets loaded from HTTP and HTTPS sources).

  • default_app_config: Default Django app config.
eximagination.obtain_image(image_source='', save_to='', media_url='', force_update=False, expiration_interval=None, debug=False)[source]

Get an image from absolute url and saves it locally.

Check whether image already exists in local directory and only if not - try to download it and save it. Validate validity of the image (rely on PIL Image class validation).

Parameters:
  • image_source (str) –
  • save_to (str) –
  • media_url (str) –
  • force_update (bool) –
  • expiration_interval (int) – Expiration interval in seconds.
  • debug (bool) –
Return list:

(relative_url_of_the_image, original_image_width, original_image_height)