def create_and_save_new_photo_with_thumb(user, file_content, description=u''): img = images.Image(file_content) anim = get_anim_type_for_photo_size(img.width, img.height) thumb_anim = anim.thumb_anim # img.resize() thumb_img = images.resize(file_content, thumb_anim.photo_width, thumb_anim.photo_height) # thumb_img = img.execute_transforms(output_encoding=images.JPEG) # raise Exception(db.Blob(img)) # raise Exception('%s\n%s' % (dir(img), img.__dict__)) photo_file = PhotoFile( blob=db.Blob(file_content) ) photo_file.put() photo = Photo( file=photo_file, user=user, anim_type=anim, anim_frame_time=0.25, description=description ) photo.set_denormalized_fields() photo.put() thumb_file = ThumbnailFile( blob=thumb_img ) thumb_file.put() thumb = Thumbnail( file=thumb_file, photo=photo ) thumb.set_denormalized_fields() thumb.put() return photo
def post(self): album_key = ndb.Key(urlsafe=self.request.get('key')) if album_key is not None: previous_thumbnails = Thumbnail.query(ancestor=album_key).fetch() for previous_thumbnail in previous_thumbnails: # should be one of these at most. previous_thumbnail_key = ndb.Key(urlsafe=previous_thumbnail.ukey()) previous_thumbnail_key.delete() upload_files = self.get_uploads() # 'file' is file upload field in the form blob_info = upload_files[0] thumbnail = Thumbnail(parent=album_key, image_blob=blob_info.key()) thumbnail.populate(serving_url=images.get_serving_url(blob_info.key())) thumbnail.put() album = album_key.get() album.thumbnail_serving_url = thumbnail.serving_url album.put() album_key = ndb.Key(urlsafe=self.request.get('key')) # No idea why I have to add this line in again self.redirect('/add-album?key=%s' % album_key.urlsafe()) else: #raise some error here. self.redirect('/')