diff --git a/wagtail/wagtailimages/models.py b/wagtail/wagtailimages/models.py index 550be20340..3ff2f97824 100644 --- a/wagtail/wagtailimages/models.py +++ b/wagtail/wagtailimages/models.py @@ -68,8 +68,8 @@ class AbstractImage(models.Model, TagSearchable): except ObjectDoesNotExist: file_field = self.file - # If we have a backend attribute then pass it to process - # image - else pass 'default' + # If we have a backend attribute then pass it to process + # image - else pass 'default' backend_name = getattr(self, 'backend', 'default') generated_image_file = filter.process_image(file_field.file, backend_name=backend_name) diff --git a/wagtail/wagtailimages/templatetags/image_tags.py b/wagtail/wagtailimages/templatetags/image_tags.py index e8a4c2191b..5c72734177 100644 --- a/wagtail/wagtailimages/templatetags/image_tags.py +++ b/wagtail/wagtailimages/templatetags/image_tags.py @@ -15,31 +15,22 @@ def image(parser, token): filter_spec = bits[1] bits = bits[2:] - if len(bits) == 0: - # token is of the form {% image self.photo max-320x200 %} - return ImageNode(image_var, filter_spec) - - elif len(bits) == 2: + if len(bits) == 2 and bits[0] == 'as': # token is of the form {% image self.photo max-320x200 as img %} - - if bits[0] == 'as': - return ImageNode(image_var, filter_spec, output_var_name=bits[1]) - - if len(bits) > 0: - # customized attrs + return ImageNode(image_var, filter_spec, output_var_name=bits[1]) + else: + # token is of the form {% image self.photo max-320x200 %} - all additional tokens + # should be kwargs, which become attributes attrs = {} for bit in bits: try: - name,value = bit.split('=') - except: - raise template.TemplateSyntaxError("'image' tag should be of the form {%% image self.photo max-320x200 [ custom-attr=\"value\" [ ... ] ] %%} or {%% image self.photo max-320x200 as img %%}") + name, value = bit.split('=') + except ValueError: + raise template.TemplateSyntaxError("'image' tag should be of the form {% image self.photo max-320x200 [ custom-attr=\"value\" ... ] %} or {% image self.photo max-320x200 as img %}") attrs[name] = parser.compile_filter(value) # setup to resolve context variables as value return ImageNode(image_var, filter_spec, attrs=attrs) - # something is wrong if we made it this far - raise template.TemplateSyntaxError("'image' tag should be of the form {%% image self.photo max-320x200 [ custom-attr=\"value\" [ ... ] ] %%} or {%% image self.photo max-320x200 as img %%}") - class ImageNode(template.Node): def __init__(self, image_var_name, filter_spec, output_var_name=None, attrs={}):