Skip to content
Snippets Groups Projects
Commit 1b325e77 authored by Andy Summers's avatar Andy Summers
Browse files

Merge branch 'fix-thumbs' into 'master'

Fix image handling for thumbnails, use `path()`

See merge request !2
parents e7f2007d d0086437
No related branches found
No related tags found
1 merge request!2Fix image handling for thumbnails, use `path()`
.vscode/
*.py[cod]
*.egg-info/
space_images/
\ No newline at end of file
......@@ -359,7 +359,7 @@ class SpotImage(models.Model):
self.image.file.multiple_chunks()):
img = Image.open(self.image.file.temporary_file_path())
else:
img = Image.open(self.image.name)
img = Image.open(self.image.file)
except:
raise ValidationError('Not a valid image format')
......@@ -560,7 +560,7 @@ class ItemImage(models.Model):
self.image.file.multiple_chunks()):
img = Image.open(self.image.file.temporary_file_path())
else:
img = Image.open(self.image)
img = Image.open(self.image.file)
except:
raise ValidationError('Not a valid image format')
......
from io import BytesIO
from spotseeker_server.test import SpotServerTestCase
......@@ -6,9 +8,11 @@ class ImageTestCase(SpotServerTestCase):
def upload_image(self, image_file_name, url, extra_args=None):
c = self.client
with open(image_file_name, 'rb') as f:
res_args = {'image': f}
img = BytesIO(f.read())
img.name = image_file_name
res_args = {'image': img}
if extra_args:
res_args.update(extra_args)
response = c.post(url, res_args)
response = c.post(url, data=res_args)
return response
......@@ -22,6 +22,7 @@
from django.conf.urls import include, url
from django.views.decorators.csrf import csrf_exempt
from django.urls import path
from spotseeker_server.views.buildings import BuildingListView
from spotseeker_server.views.spot import SpotView
from spotseeker_server.views.search import SearchView
......@@ -41,65 +42,55 @@ from spotseeker_server.views.add_item_image import AddItemImageView
from spotseeker_server.views.item_thumbnail import ItemThumbnailView
urlpatterns = [
url(r'v1/null$', csrf_exempt(NullView().run)),
path('v1/null', csrf_exempt(NullView().run)),
url(r'v1/spot/(?P<spot_id>(\d+|external:[\w-]+))$',
csrf_exempt(SpotView().run), name='spot'),
url(r'v1/spot/?$',
csrf_exempt(SearchView().run),
name='spot-search'),
url(r'v1/spot/all$',
path('v1/spot/all',
csrf_exempt(AllSpotsView().run),
name='spots'),
url(r'v1/buildings/?$',
csrf_exempt(BuildingListView().run),
name='buildings'),
url(r'v1/schema$',
csrf_exempt(SchemaGenView().run),
name='schema'),
url(r'v1/spot/(?P<spot_id>\d+)/image$',
csrf_exempt(AddImageView().run)),
url(r'v1/spot/(?P<spot_id>\d+)/image/'
'(?P<image_id>\d+)$',
csrf_exempt(ImageView().run),
name='spot-image'),
url(r'v1/spot/(?P<spot_id>\d+)/image/'
'(?P<image_id>\d+)/thumb/constrain/'
'(?P<thumb_dimensions>.+)?$',
csrf_exempt(ThumbnailView().run),
{'constrain': True}),
url(r'v1/spot/(?P<spot_id>\d+)/image/'
'(?P<image_id>\d+)/thumb/'
'(?P<thumb_dimensions>.+)?$',
csrf_exempt(ThumbnailView().run),
name='spot-image-thumb'),
url(r'v1/item/(?P<item_id>\d+)/image$',
csrf_exempt(AddItemImageView().run)),
url(r'v1/item/(?P<item_id>\d+)/image/'
'(?P<image_id>\d+)$',
csrf_exempt(ItemImageView().run),
name='item-image'),
url(r'v1/item/(?P<item_id>\d+)/image/'
'(?P<image_id>\d+)/thumb/constrain/'
'(?P<thumb_dimensions>.+)?$',
path('v1/schema',
csrf_exempt(SchemaGenView().run),
name='schema'),
path('v1/spot/<int:spot_id>/image',
csrf_exempt(AddImageView().run)),
path('v1/spot/<int:spot_id>/image/<int:image_id>',
csrf_exempt(ImageView().run),
name='spot-image'),
path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/constrain/<str:thumb_dimensions>',
csrf_exempt(ThumbnailView().run),
{'constrain': True}),
path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/<str:thumb_dimensions>',
csrf_exempt(ThumbnailView().run),
name='spot-image-thumb'),
path('v1/item/<int:item_id>/image',
csrf_exempt(AddItemImageView().run)),
path('v1/item/<int:item_id>/image/<int:image_id>',
csrf_exempt(ItemImageView().run),
name='item-image'),
path('v1/item/<int:item_id>/image/<int:image_id>/thumb/constrain/<str:thumb_dimensions>',
csrf_exempt(ItemThumbnailView().run),
{'constrain': True}),
url(r'v1/item/(?P<item_id>\d+)/image/'
'(?P<image_id>\d+)/thumb/'
'(?P<thumb_dimensions>.+)?$',
path('v1/item/<int:item_id>/image/<int:image_id>/thumb/<str:thumb_dimensions>',
csrf_exempt(ItemThumbnailView().run),
name='item-image-thumb'),
url(r'v1/spot/(?P<spot_id>\d+)/reviews$',
csrf_exempt(ReviewsView().run)),
path('v1/spot/<int:spot_id>/reviews',
csrf_exempt(ReviewsView().run)),
url(r'v1/user/me/favorites/?$',
csrf_exempt(FavoritesView().run)),
url(r'v1/user/me$',
path('v1/user/me',
csrf_exempt(PersonView().run)),
url(r'v1/user/me/favorite/(?P<spot_id>\d+)$',
path('v1/user/me/favorite/<int:spot_id>',
csrf_exempt(FavoritesView().run)),
url(r'v1/spot/(?P<spot_id>\d+)/share$',
path('v1/spot/<int:spot_id>/share',
csrf_exempt(ShareSpaceView().run)),
url(r'v1/spot/(?P<spot_id>\d+)/shared$',
path('v1/spot/<int:spot_id>/shared',
csrf_exempt(SharedSpaceReferenceView().run)),
url(r'v1/reviews/unpublished$',
path('v1/reviews/unpublished',
csrf_exempt(UnpublishedReviewsView().run)),
]
......@@ -25,7 +25,7 @@ from spotseeker_server.models import SpotImage, Spot
from django.http import HttpResponse
from django.utils.http import http_date
from spotseeker_server.require_auth import app_auth_required
from io import StringIO
from io import BytesIO
from PIL import Image
import time
import re
......@@ -90,7 +90,7 @@ class ThumbnailView(RESTDispatch):
else:
thumb = im.resize((thumb_width, thumb_height), Image.ANTIALIAS)
tmp = StringIO()
tmp = BytesIO()
thumb.save(tmp, im.format, quality=95)
tmp.seek(0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment