def add_post_photo(post_id): info = extract(request) uid = token_to_uid(info) if uid is None: return invalid_token() if not info.get('photo', ''): return missing() post = Post.query.filter_by(id=post_id).first() if not post: return nopost() if not post.uid == uid: return wrong_token() if len(post.photos) > 3: return json.dumps({ 'success': False, 'error': "Post already has four photos. Please delete one before adding another." }), 400 photo = Photo.query.filter_by(val=info.get('photo')).first() if photo is not None: return json.dumps({'success': True, 'data': photo.serialize()}), 200 photo = Photo(post_id=post_id, val=info.get('photo')) db.session.add(photo) db.session.commit() return json.dumps({'success': True, 'data': photo.serialize()}), 201
def fetch_photos(library): photosdb = osxphotos.PhotosDB(library.path) images = photosdb.photos(images=True, movies=False) videos = [] # photosdb.photos(images=False, movies=True) albums = {} # photosdb.albums_as_dict photos = [Photo(p, library) for p in filter(is_image_supported, images)] logging.info( f"Found {len(photos)} photos, {len(videos)} videos, {len(albums)} albums" ) return (photos, videos, albums)