mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
Another major Pinry model rewrite
Generate thumbnail and standard image on request, and use http://github.com/mirumee/django-images for generating them. Also, remove the CreatePin page as pin creation is going to be done in JavaScript. Create UploadImage view for uploading images from computer.
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
from django_images.models import Thumbnail
|
||||
from tastypie.resources import ModelResource
|
||||
from tastypie import fields
|
||||
from tastypie.authorization import DjangoAuthorization
|
||||
@@ -27,10 +31,15 @@ class PinResource(ModelResource):
|
||||
submitter = fields.ForeignKey(UserResource, 'submitter', full=True)
|
||||
|
||||
def dehydrate_images(self, bundle):
|
||||
images = {}
|
||||
for type in ['standard', 'thumbnail', 'original']:
|
||||
image_obj = getattr(bundle.obj, type, None)
|
||||
images[type] = {'url': image_obj.image.url, 'width': image_obj.width, 'height': image_obj.height}
|
||||
original = bundle.obj.image
|
||||
images = {'original': {
|
||||
'url': original.get_absolute_url(), 'width': original.width, 'height': original.height}
|
||||
}
|
||||
for image in ['standard', 'thumbnail']:
|
||||
obj = Thumbnail.objects.get_or_create_at_size(original.pk, image)
|
||||
images[image] = {
|
||||
'url': obj.get_absolute_url(), 'width': obj.width, 'height': obj.height
|
||||
}
|
||||
return images
|
||||
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user