def preview_photo(): item = application.getItemByUUID(request.args(0)) photo = db.plugin_photoset_photo(request.args(1)) return IMG( _src=URL('default', 'download', args=[photo.picture]), _class="img-responsive center-block", _alt=item.slugline, )
def delete_photo(): item = application.getItemByUUID(request.args(0)) content = db.plugin_photoset_content(item_id=item.unique_id) photo = db.plugin_photoset_photo(request.args(1)) content.photoset.remove(photo.id) del db.plugin_photoset_photo[photo.id] content.update_record() application.notifyChanges(item.unique_id) return CAT('')
def upload_photo(): """upload one or more photos""" if not session.plugin_photoset: session.plugin_photoset = Storage() session.plugin_photoset.photos = [] for r in request.vars: if r == "qqfile": filename = request.vars.qqfile photo_id = db.plugin_photoset_photo.insert( picture=db.plugin_photoset_photo.picture.store( request.body, filename ) ) # generate the thumbnail photo = db.plugin_photoset_photo(photo_id) (filename, stream) = db.plugin_photoset_photo.picture.retrieve( photo.picture ) filename = stream.name im = Image.open(filename) # -------------------------------- size = (200, 200) im.thumbnail(size) fl = NamedTemporaryFile(suffix=".jpg", delete=True) fl.close() im.save(fl.name, "JPEG") thumb = db.plugin_photoset_photo.thumbnail.store( open(fl.name, 'rb'), fl.name) photo.update_record(thumbnail=thumb) os.unlink(fl.name) # cleanup # if a photoset is given add this photo to the set if request.args(0): item = application.getItemByUUID(request.args(0)) photoset = db.plugin_photoset_content(item_id=item.unique_id) if photoset.photoset is None: photoset.photoset = [photo_id] else: photoset.photoset.append(photo_id) photoset.update_record() else: # in the create stage, i guess session.plugin_photoset.photos.append(photo_id) return response.json({'success': 'true'})