Make response_type required, explicit in all calls.
This commit is contained in:
		
							parent
							
								
									9d620b4b97
								
							
						
					
					
						commit
						02db1f3971
					
				
					 4 changed files with 28 additions and 25 deletions
				
			
		|  | @ -50,7 +50,10 @@ file_cache_manager = caching.FileCacheManager( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| def P_wrapper(function): | def P_wrapper(function): | ||||||
|     def P_wrapped(thingid, response_type='html'): |     def P_wrapped(thingid, response_type): | ||||||
|  |         if response_type not in {'html', 'json'}: | ||||||
|  |             raise TypeError(f'response_type should be html or json, not {response_type}.') | ||||||
|  | 
 | ||||||
|         try: |         try: | ||||||
|             return function(thingid) |             return function(thingid) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ session_manager = common.session_manager | ||||||
| @site.route('/album/<album_id>') | @site.route('/album/<album_id>') | ||||||
| @session_manager.give_token | @session_manager.give_token | ||||||
| def get_album_html(album_id): | def get_album_html(album_id): | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='html') | ||||||
|     response = common.render_template( |     response = common.render_template( | ||||||
|         request, |         request, | ||||||
|         'album.html', |         'album.html', | ||||||
|  | @ -28,13 +28,13 @@ def get_album_html(album_id): | ||||||
| @site.route('/album/<album_id>.json') | @site.route('/album/<album_id>.json') | ||||||
| @session_manager.give_token | @session_manager.give_token | ||||||
| def get_album_json(album_id): | def get_album_json(album_id): | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='json') | ||||||
|     album = etiquette.jsonify.album(album) |     album = etiquette.jsonify.album(album) | ||||||
|     return jsonify.make_json_response(album) |     return jsonify.make_json_response(album) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>.zip') | @site.route('/album/<album_id>.zip') | ||||||
| def get_album_zip(album_id): | def get_album_zip(album_id): | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='html') | ||||||
| 
 | 
 | ||||||
|     recursive = request.args.get('recursive', True) |     recursive = request.args.get('recursive', True) | ||||||
|     recursive = etiquette.helpers.truthystring(recursive) |     recursive = etiquette.helpers.truthystring(recursive) | ||||||
|  | @ -59,8 +59,8 @@ def get_album_zip(album_id): | ||||||
| @decorators.catch_etiquette_exception | @decorators.catch_etiquette_exception | ||||||
| @decorators.required_fields(['child_id'], forbid_whitespace=True) | @decorators.required_fields(['child_id'], forbid_whitespace=True) | ||||||
| def post_album_add_child(album_id): | def post_album_add_child(album_id): | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='json') | ||||||
|     child = common.P_album(request.form['child_id']) |     child = common.P_album(request.form['child_id'], response_type='json') | ||||||
|     album.add_child(child, commit=True) |     album.add_child(child, commit=True) | ||||||
|     response = etiquette.jsonify.album(child) |     response = etiquette.jsonify.album(child) | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
|  | @ -69,8 +69,8 @@ def post_album_add_child(album_id): | ||||||
| @decorators.catch_etiquette_exception | @decorators.catch_etiquette_exception | ||||||
| @decorators.required_fields(['child_id'], forbid_whitespace=True) | @decorators.required_fields(['child_id'], forbid_whitespace=True) | ||||||
| def post_album_remove_child(album_id): | def post_album_remove_child(album_id): | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='json') | ||||||
|     child = common.P_album(request.form['child_id']) |     child = common.P_album(request.form['child_id'], response_type='json') | ||||||
|     album.remove_child(child, commit=True) |     album.remove_child(child, commit=True) | ||||||
|     response = etiquette.jsonify.album(child) |     response = etiquette.jsonify.album(child) | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
|  | @ -78,7 +78,7 @@ def post_album_remove_child(album_id): | ||||||
| @site.route('/album/<album_id>/refresh_directories', methods=['POST']) | @site.route('/album/<album_id>/refresh_directories', methods=['POST']) | ||||||
| @decorators.catch_etiquette_exception | @decorators.catch_etiquette_exception | ||||||
| def post_album_refresh_directories(album_id): | def post_album_refresh_directories(album_id): | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='json') | ||||||
|     for directory in album.get_associated_directories(): |     for directory in album.get_associated_directories(): | ||||||
|         common.P.digest_directory(directory, new_photo_ratelimit=0.1) |         common.P.digest_directory(directory, new_photo_ratelimit=0.1) | ||||||
|     common.P.commit(message='refresh album directories endpoint') |     common.P.commit(message='refresh album directories endpoint') | ||||||
|  | @ -95,10 +95,10 @@ def post_album_add_photo(album_id): | ||||||
|     Add a photo or photos to this album. |     Add a photo or photos to this album. | ||||||
|     ''' |     ''' | ||||||
|     response = {} |     response = {} | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='json') | ||||||
| 
 | 
 | ||||||
|     photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) |     photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) | ||||||
|     photos = list(common.P_photos(photo_ids)) |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
|     album.add_photos(photos, commit=True) |     album.add_photos(photos, commit=True) | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
| 
 | 
 | ||||||
|  | @ -111,10 +111,10 @@ def post_album_remove_photo(album_id): | ||||||
|     Remove a photo or photos from this album. |     Remove a photo or photos from this album. | ||||||
|     ''' |     ''' | ||||||
|     response = {} |     response = {} | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='json') | ||||||
| 
 | 
 | ||||||
|     photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) |     photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) | ||||||
|     photos = list(common.P_photos(photo_ids)) |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
|     album.remove_photos(photos, commit=True) |     album.remove_photos(photos, commit=True) | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
| 
 | 
 | ||||||
|  | @ -128,11 +128,11 @@ def post_album_add_tag(album_id): | ||||||
|     Apply a tag to every photo in the album. |     Apply a tag to every photo in the album. | ||||||
|     ''' |     ''' | ||||||
|     response = {} |     response = {} | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='json') | ||||||
| 
 | 
 | ||||||
|     tag = request.form['tagname'].strip() |     tag = request.form['tagname'].strip() | ||||||
|     try: |     try: | ||||||
|         tag = common.P_tag(tag) |         tag = common.P_tag(tag, response_type='json') | ||||||
|     except etiquette.exceptions.NoSuchTag as exc: |     except etiquette.exceptions.NoSuchTag as exc: | ||||||
|         response = etiquette.jsonify.exception(exc) |         response = etiquette.jsonify.exception(exc) | ||||||
|         return jsonify.make_json_response(response, status=404) |         return jsonify.make_json_response(response, status=404) | ||||||
|  | @ -152,7 +152,7 @@ def post_album_edit(album_id): | ||||||
|     ''' |     ''' | ||||||
|     Edit the title / description. |     Edit the title / description. | ||||||
|     ''' |     ''' | ||||||
|     album = common.P_album(album_id) |     album = common.P_album(album_id, response_type='json') | ||||||
| 
 | 
 | ||||||
|     title = request.form.get('title', None) |     title = request.form.get('title', None) | ||||||
|     description = request.form.get('description', None) |     description = request.form.get('description', None) | ||||||
|  | @ -196,7 +196,7 @@ def post_albums_create(): | ||||||
|     description = request.form.get('description', None) |     description = request.form.get('description', None) | ||||||
|     parent_id = request.form.get('parent_id', None) |     parent_id = request.form.get('parent_id', None) | ||||||
|     if parent_id is not None: |     if parent_id is not None: | ||||||
|         parent = common.P_album(parent_id) |         parent = common.P_album(parent_id, response_type='json') | ||||||
| 
 | 
 | ||||||
|     user = session_manager.get(request).user |     user = session_manager.get(request).user | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -61,7 +61,7 @@ def get_file(photo_id, basename=None): | ||||||
| @site.route('/thumbnail/<photo_id>') | @site.route('/thumbnail/<photo_id>') | ||||||
| def get_thumbnail(photo_id): | def get_thumbnail(photo_id): | ||||||
|     photo_id = photo_id.split('.')[0] |     photo_id = photo_id.split('.')[0] | ||||||
|     photo = common.P_photo(photo_id) |     photo = common.P_photo(photo_id, response_type='html') | ||||||
|     if photo.thumbnail: |     if photo.thumbnail: | ||||||
|         path = photo.thumbnail |         path = photo.thumbnail | ||||||
|     else: |     else: | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ def get_tag_id_redirect(tag_id): | ||||||
| @site.route('/tag/<specific_tag>/edit', methods=['POST']) | @site.route('/tag/<specific_tag>/edit', methods=['POST']) | ||||||
| @decorators.catch_etiquette_exception | @decorators.catch_etiquette_exception | ||||||
| def post_tag_edit(specific_tag): | def post_tag_edit(specific_tag): | ||||||
|     tag = common.P_tag(specific_tag) |     tag = common.P_tag(specific_tag, response_type='json') | ||||||
|     name = request.form.get('name', '').strip() |     name = request.form.get('name', '').strip() | ||||||
|     if name: |     if name: | ||||||
|         tag.rename(name) |         tag.rename(name) | ||||||
|  | @ -50,8 +50,8 @@ def post_tag_edit(specific_tag): | ||||||
| @session_manager.give_token | @session_manager.give_token | ||||||
| @decorators.required_fields(['child_name'], forbid_whitespace=True) | @decorators.required_fields(['child_name'], forbid_whitespace=True) | ||||||
| def post_tag_add_child(tagname): | def post_tag_add_child(tagname): | ||||||
|     parent = common.P_tag(tagname) |     parent = common.P_tag(tagname, response_type='json') | ||||||
|     child = common.P_tag(request.form['child_name']) |     child = common.P_tag(request.form['child_name'], response_type='json') | ||||||
|     parent.add_child(child, commit=True) |     parent.add_child(child, commit=True) | ||||||
|     response = {'action': 'add_child', 'tagname': f'{parent.name}.{child.name}'} |     response = {'action': 'add_child', 'tagname': f'{parent.name}.{child.name}'} | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
|  | @ -61,8 +61,8 @@ def post_tag_add_child(tagname): | ||||||
| @session_manager.give_token | @session_manager.give_token | ||||||
| @decorators.required_fields(['child_name'], forbid_whitespace=True) | @decorators.required_fields(['child_name'], forbid_whitespace=True) | ||||||
| def post_tag_remove_child(tagname): | def post_tag_remove_child(tagname): | ||||||
|     parent = common.P_tag(tagname) |     parent = common.P_tag(tagname, response_type='json') | ||||||
|     child = common.P_tag(request.form['child_name']) |     child = common.P_tag(request.form['child_name'], response_type='json') | ||||||
|     parent.remove_child(child, commit=True) |     parent.remove_child(child, commit=True) | ||||||
|     response = {'action': 'remove_child', 'tagname': f'{parent.name}.{child.name}'} |     response = {'action': 'remove_child', 'tagname': f'{parent.name}.{child.name}'} | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
|  | @ -159,7 +159,7 @@ def post_tag_easybake(): | ||||||
| @decorators.catch_etiquette_exception | @decorators.catch_etiquette_exception | ||||||
| @session_manager.give_token | @session_manager.give_token | ||||||
| def post_tag_delete(tagname): | def post_tag_delete(tagname): | ||||||
|     tag = common.P_tag(tagname) |     tag = common.P_tag(tagname, response_type='json') | ||||||
|     tag.delete(commit=True) |     tag.delete(commit=True) | ||||||
|     response = {'action': 'delete_tag', 'tagname': tag.name} |     response = {'action': 'delete_tag', 'tagname': tag.name} | ||||||
|     return jsonify.make_json_response(response) |     return jsonify.make_json_response(response) | ||||||
|  | @ -171,7 +171,7 @@ def post_tag_delete(tagname): | ||||||
| def post_tag_remove_synonym(tagname): | def post_tag_remove_synonym(tagname): | ||||||
|     syn_name = request.form['syn_name'] |     syn_name = request.form['syn_name'] | ||||||
| 
 | 
 | ||||||
|     master_tag = common.P_tag(tagname) |     master_tag = common.P_tag(tagname, response_type='json') | ||||||
|     master_tag.remove_synonym(syn_name, commit=True) |     master_tag.remove_synonym(syn_name, commit=True) | ||||||
| 
 | 
 | ||||||
|     response = {'action': 'delete_synonym', 'synonym': syn_name} |     response = {'action': 'delete_synonym', 'synonym': syn_name} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue