Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional generate param to generate_all_aliases #349

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
13 changes: 9 additions & 4 deletions easy_thumbnails/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,22 @@ def get_thumbnailer(obj, relative_name=None):
remote_source=obj is not None)


def generate_all_aliases(fieldfile, include_global):
def generate_all_aliases(fieldfile, include_global, force=False):
"""
Generate all of a file's aliases.

:param fieldfile: A ``FieldFile`` instance.
:param include_global: A boolean which determines whether to generate
thumbnails for project-wide aliases in addition to field, model, and
app specific aliases.
:param force: Force the generation behaviour by setting the generate param
to either True or False as required.
"""
all_options = aliases.all(fieldfile, include_global=include_global)
if all_options:
thumbnailer = get_thumbnailer(fieldfile)
for options in all_options.values():
thumbnailer.get_thumbnail(options)
thumbnailer.get_thumbnail(options, force=force)


def database_get_image_dimensions(file, close=False, dimensions=None):
Expand Down Expand Up @@ -484,7 +486,7 @@ def get_existing_thumbnail(self, thumbnail_options, high_resolution=False):
thumbnail_file.set_image_dimensions(exists)
return thumbnail_file

def get_thumbnail(self, thumbnail_options, save=True, generate=None,
def get_thumbnail(self, thumbnail_options, save=True, generate=None, force=False,
silent_template_exception=False):
"""
Return a ``ThumbnailFile`` containing a thumbnail.
Expand All @@ -498,6 +500,9 @@ def get_thumbnail(self, thumbnail_options, save=True, generate=None,
Force the generation behaviour by setting the ``generate`` param to
either ``True`` or ``False`` as required.

Force re-generation behaviour (even if thumbnail already exists) by setting
the force param to either True or False as required.

The new thumbnail image is generated using the ``thumbnail_options``
dictionary. If the ``save`` argument is ``True`` (default), the
generated thumbnail will be saved too.
Expand All @@ -507,7 +512,7 @@ def get_thumbnail(self, thumbnail_options, save=True, generate=None,
generate = self.generate

thumbnail = self.get_existing_thumbnail(thumbnail_options)
if not thumbnail:
if force or not thumbnail:
if generate:
thumbnail = self.generate_thumbnail(
thumbnail_options,
Expand Down