mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-10 16:24:49 +00:00
Added error for bad filter specs
This commit is contained in:
parent
c632e03a04
commit
9545550281
2 changed files with 11 additions and 1 deletions
|
|
@ -29,6 +29,10 @@ def validate_image_format(f):
|
|||
raise ValidationError(_("Not a valid %s image. Please use a gif, jpeg or png file with the correct file extension.") % (extension.upper()))
|
||||
|
||||
|
||||
class InvalidFilterSpecError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
# TODO: Cache results from this method in something like Python 3.2s LRU cache (available in Django 1.7 as django.utils.lru_cache)
|
||||
def parse_filter_spec(filter_spec):
|
||||
# parse the spec string and save the results to
|
||||
|
|
@ -62,3 +66,5 @@ def parse_filter_spec(filter_spec):
|
|||
width = int(match.group(2))
|
||||
height = int(match.group(3))
|
||||
return OPERATION_NAMES[match.group(1)], (width, height)
|
||||
|
||||
raise InvalidFilterSpecError(filter_spec)
|
||||
|
|
|
|||
|
|
@ -2,10 +2,14 @@ from django.shortcuts import get_object_or_404
|
|||
from django.http import HttpResponse
|
||||
|
||||
from wagtail.wagtailimages.models import get_image_model
|
||||
from wagtail.wagtailimages.utils import InvalidFilterSpecError
|
||||
from wagtail.wagtailimages import image_processor
|
||||
|
||||
|
||||
def serve(request, image_id, filter_spec):
|
||||
image = get_object_or_404(get_image_model(), id=image_id)
|
||||
|
||||
return image_processor.process_image(image.file.file, HttpResponse(content_type='image/jpeg'), filter_spec)
|
||||
try:
|
||||
return image_processor.process_image(image.file.file, HttpResponse(content_type='image/jpeg'), filter_spec)
|
||||
except InvalidFilterSpecError:
|
||||
return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400)
|
||||
|
|
|
|||
Loading…
Reference in a new issue