def save_cropped_photo(request, username=None): identifier = request.POST['id'] photo = Photo.objects.get(id=int(identifier)) left = request.POST['left'] top = request.POST['top'] width = request.POST['width'] height = request.POST['height'] fake_original = "%s/unsafe/%s/%s" % (THUMBOR_SERVER, 'fit-in/600x400', format_url(photo.url)) url = '/unsafe/%dx%d:%dx%d/smart/%s' % ( int(left), int(top), int(left) + int(width), int(top) + int(height), fake_original ) cropped, created = CroppedPhoto.objects.get_or_create( original_photo=photo, url=url, hash=CroppedPhoto.get_hash(url) ) return HttpResponse(dumps({"url": request.build_absolute_uri('../' + cropped.get_absolute_url()), "crop_id": cropped.id }), mimetype="application/json")
def albums(request, username=None, extension="json"): data = [] for album in AlbumProxy.objects.load(username): album_data = { 'identifier': album.identifier, 'url': album.url, 'title': album.title, 'photos': [] } for photo in PhotoProxy.objects.load(album): album_data['photos'].append({ 'id': photo.id, 'url': photo.url, 'title': photo.title, 'thumbnail': photo.thumbnail, 'crop_url': "%s/unsafe/%s/%s" % (THUMBOR_SERVER, 'fit-in/600x400', format_url(photo.url)), 'width': photo.width, 'height': photo.height }) data.append(album_data) data = dumps(data) providers = Provider.objects.filter(username=request.user.username) for provider in providers: provider.mark_as_updated() provider.save() if extension == "json": return HttpResponse(data, mimetype="application/json") elif extension == "jsonp": return HttpResponse('albums_loaded(%s)' % data, mimetype="application/json") else: raise Http404