Add P_photos to batchify some api operations.
This commit is contained in:
		
							parent
							
								
									6d349aa235
								
							
						
					
					
						commit
						8c356df6fd
					
				
					 3 changed files with 12 additions and 12 deletions
				
			
		|  | @ -85,6 +85,10 @@ def P_bookmark(bookmarkid): | ||||||
| def P_photo(photo_id): | def P_photo(photo_id): | ||||||
|     return P.get_photo(photo_id) |     return P.get_photo(photo_id) | ||||||
| 
 | 
 | ||||||
|  | @P_wrapper | ||||||
|  | def P_photos(photo_ids): | ||||||
|  |     return P.get_photos_by_id(photo_ids) | ||||||
|  | 
 | ||||||
| @P_wrapper | @P_wrapper | ||||||
| def P_tag(tagname): | def P_tag(tagname): | ||||||
|     return P.get_tag(name=tagname) |     return P.get_tag(name=tagname) | ||||||
|  |  | ||||||
|  | @ -95,10 +95,8 @@ def post_album_add_photo(album_id): | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id) | ||||||
| 
 | 
 | ||||||
|     photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) |     photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) | ||||||
|     photos = [common.P_photo(photo_id) for photo_id in photo_ids] |     photos = list(common.P_photos(photo_ids)) | ||||||
|     for photo in photos: |     album.add_photos(photos) | ||||||
|         album.add_photo(photo, commit=False) |  | ||||||
|     common.P.commit() |  | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>/remove_photo', methods=['POST']) | @site.route('/album/<album_id>/remove_photo', methods=['POST']) | ||||||
|  | @ -113,10 +111,8 @@ def post_album_remove_photo(album_id): | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id) | ||||||
| 
 | 
 | ||||||
|     photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) |     photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) | ||||||
|     photos = [common.P_photo(photo_id) for photo_id in photo_ids] |     photos = list(common.P_photos(photo_ids)) | ||||||
|     for photo in photos: |     album.remove_photos(photos) | ||||||
|         album.remove_photo(photo, commit=False) |  | ||||||
|     common.P.commit() |  | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| # Album tag operations ############################################################################# | # Album tag operations ############################################################################# | ||||||
|  |  | ||||||
|  | @ -73,7 +73,7 @@ def post_photo_add_remove_tag_core(photo_ids, tagname, add_or_remove): | ||||||
|     if isinstance(photo_ids, str): |     if isinstance(photo_ids, str): | ||||||
|         photo_ids = etiquette.helpers.comma_space_split(photo_ids) |         photo_ids = etiquette.helpers.comma_space_split(photo_ids) | ||||||
| 
 | 
 | ||||||
|     photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids] |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
|     tag = common.P_tag(tagname, response_type='json') |     tag = common.P_tag(tagname, response_type='json') | ||||||
| 
 | 
 | ||||||
|     for photo in photos: |     for photo in photos: | ||||||
|  | @ -139,7 +139,7 @@ def post_photo_refresh_metadata_core(photo_ids): | ||||||
|     if isinstance(photo_ids, str): |     if isinstance(photo_ids, str): | ||||||
|         photo_ids = etiquette.helpers.comma_space_split(photo_ids) |         photo_ids = etiquette.helpers.comma_space_split(photo_ids) | ||||||
| 
 | 
 | ||||||
|     photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids] |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
| 
 | 
 | ||||||
|     for photo in photos: |     for photo in photos: | ||||||
|         common.P.caches['photo'].remove(photo.id) |         common.P.caches['photo'].remove(photo.id) | ||||||
|  | @ -171,7 +171,7 @@ def post_photo_searchhidden_core(photo_ids, searchhidden): | ||||||
|     if isinstance(photo_ids, str): |     if isinstance(photo_ids, str): | ||||||
|         photo_ids = etiquette.helpers.comma_space_split(photo_ids) |         photo_ids = etiquette.helpers.comma_space_split(photo_ids) | ||||||
| 
 | 
 | ||||||
|     photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids] |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
| 
 | 
 | ||||||
|     for photo in photos: |     for photo in photos: | ||||||
|         photo.set_searchhidden(searchhidden, commit=False) |         photo.set_searchhidden(searchhidden, commit=False) | ||||||
|  | @ -206,7 +206,7 @@ def post_batch_photos_photo_cards(): | ||||||
|     photo_ids = request.form['photo_ids'] |     photo_ids = request.form['photo_ids'] | ||||||
| 
 | 
 | ||||||
|     photo_ids = etiquette.helpers.comma_space_split(photo_ids) |     photo_ids = etiquette.helpers.comma_space_split(photo_ids) | ||||||
|     photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids] |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
| 
 | 
 | ||||||
|     # Photo filenames are prevented from having colons, so using it as a split |     # Photo filenames are prevented from having colons, so using it as a split | ||||||
|     # delimiter should be safe. |     # delimiter should be safe. | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue