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:
Krzysztof Klimonda
2013-02-25 04:08:35 +01:00
parent 4f2b94616c
commit d0a71244b5
10 changed files with 76 additions and 179 deletions

View File

@@ -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: