Move make_json_response to voussoirkit.flasktools.
This commit is contained in:
		
							parent
							
								
									adb691405c
								
							
						
					
					
						commit
						f003f55fca
					
				
					 8 changed files with 70 additions and 70 deletions
				
			
		|  | @ -107,7 +107,7 @@ def P_wrapper(function): | ||||||
|                 flask.abort(status, exc.error_message) |                 flask.abort(status, exc.error_message) | ||||||
|             else: |             else: | ||||||
|                 response = exc.jsonify() |                 response = exc.jsonify() | ||||||
|                 response = jsonify.make_json_response(response, status=status) |                 response = flasktools.make_json_response(response, status=status) | ||||||
|                 flask.abort(response) |                 flask.abort(response) | ||||||
| 
 | 
 | ||||||
|         except Exception as exc: |         except Exception as exc: | ||||||
|  | @ -115,7 +115,7 @@ def P_wrapper(function): | ||||||
|             if response_type == 'html': |             if response_type == 'html': | ||||||
|                 flask.abort(500) |                 flask.abort(500) | ||||||
|             else: |             else: | ||||||
|                 flask.abort(jsonify.make_json_response({}, status=500)) |                 flask.abort(flasktools.make_json_response({}, status=500)) | ||||||
| 
 | 
 | ||||||
|     return P_wrapped |     return P_wrapped | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -105,7 +105,7 @@ def catch_etiquette_exception(function): | ||||||
|             else: |             else: | ||||||
|                 status = 400 |                 status = 400 | ||||||
|             response = exc.jsonify() |             response = exc.jsonify() | ||||||
|             response = jsonify.make_json_response(response, status=status) |             response = flasktools.make_json_response(response, status=status) | ||||||
|             flask.abort(response) |             flask.abort(response) | ||||||
|     return wrapped |     return wrapped | ||||||
| 
 | 
 | ||||||
|  | @ -153,7 +153,7 @@ def required_fields(fields, forbid_whitespace=False): | ||||||
|                         'error_type': 'MISSING_FIELDS', |                         'error_type': 'MISSING_FIELDS', | ||||||
|                         'error_message': 'Required fields: %s' % ', '.join(fields), |                         'error_message': 'Required fields: %s' % ', '.join(fields), | ||||||
|                     } |                     } | ||||||
|                     response = jsonify.make_json_response(response, status=400) |                     response = flasktools.make_json_response(response, status=400) | ||||||
|                     return response |                     return response | ||||||
| 
 | 
 | ||||||
|             return function(*args, **kwargs) |             return function(*args, **kwargs) | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ import os | ||||||
| import time | import time | ||||||
| import urllib.parse | import urllib.parse | ||||||
| 
 | 
 | ||||||
|  | from voussoirkit import flasktools | ||||||
| from voussoirkit import stringtools | from voussoirkit import stringtools | ||||||
| 
 | 
 | ||||||
| import etiquette | import etiquette | ||||||
|  | @ -31,7 +32,7 @@ def get_album_html(album_id): | ||||||
| def get_album_json(album_id): | def get_album_json(album_id): | ||||||
|     album = common.P_album(album_id, response_type='json') |     album = common.P_album(album_id, response_type='json') | ||||||
|     album = album.jsonify() |     album = album.jsonify() | ||||||
|     return jsonify.make_json_response(album) |     return flasktools.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): | ||||||
|  | @ -66,7 +67,7 @@ def post_album_add_child(album_id): | ||||||
|     print(children) |     print(children) | ||||||
|     album.add_children(children, commit=True) |     album.add_children(children, commit=True) | ||||||
|     response = album.jsonify() |     response = album.jsonify() | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>/remove_child', methods=['POST']) | @site.route('/album/<album_id>/remove_child', methods=['POST']) | ||||||
| @decorators.required_fields(['child_id'], forbid_whitespace=True) | @decorators.required_fields(['child_id'], forbid_whitespace=True) | ||||||
|  | @ -77,14 +78,14 @@ def post_album_remove_child(album_id): | ||||||
|     children = list(common.P_albums(child_ids, response_type='json')) |     children = list(common.P_albums(child_ids, response_type='json')) | ||||||
|     album.remove_children(children, commit=True) |     album.remove_children(children, commit=True) | ||||||
|     response = album.jsonify() |     response = album.jsonify() | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>/remove_thumbnail_photo', methods=['POST']) | @site.route('/album/<album_id>/remove_thumbnail_photo', methods=['POST']) | ||||||
| def post_album_remove_thumbnail_photo(album_id): | def post_album_remove_thumbnail_photo(album_id): | ||||||
|     album = common.P_album(album_id, response_type='json') |     album = common.P_album(album_id, response_type='json') | ||||||
|     album.set_thumbnail_photo(None) |     album.set_thumbnail_photo(None) | ||||||
|     common.P.commit(message='album remove thumbnail photo endpoint') |     common.P.commit(message='album remove thumbnail photo endpoint') | ||||||
|     return jsonify.make_json_response(album.jsonify()) |     return flasktools.make_json_response(album.jsonify()) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>/refresh_directories', methods=['POST']) | @site.route('/album/<album_id>/refresh_directories', methods=['POST']) | ||||||
| def post_album_refresh_directories(album_id): | def post_album_refresh_directories(album_id): | ||||||
|  | @ -95,7 +96,7 @@ def post_album_refresh_directories(album_id): | ||||||
|         digest = common.P.digest_directory(directory, new_photo_ratelimit=0.1) |         digest = common.P.digest_directory(directory, new_photo_ratelimit=0.1) | ||||||
|         etiquette.helpers.run_generator(digest) |         etiquette.helpers.run_generator(digest) | ||||||
|     common.P.commit(message='refresh album directories endpoint') |     common.P.commit(message='refresh album directories endpoint') | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>/set_thumbnail_photo', methods=['POST']) | @site.route('/album/<album_id>/set_thumbnail_photo', methods=['POST']) | ||||||
| @decorators.required_fields(['photo_id'], forbid_whitespace=True) | @decorators.required_fields(['photo_id'], forbid_whitespace=True) | ||||||
|  | @ -104,7 +105,7 @@ def post_album_set_thumbnail_photo(album_id): | ||||||
|     photo = common.P_photo(request.form['photo_id'], response_type='json') |     photo = common.P_photo(request.form['photo_id'], response_type='json') | ||||||
|     album.set_thumbnail_photo(photo) |     album.set_thumbnail_photo(photo) | ||||||
|     common.P.commit(message='album set thumbnail photo endpoint') |     common.P.commit(message='album set thumbnail photo endpoint') | ||||||
|     return jsonify.make_json_response(album.jsonify()) |     return flasktools.make_json_response(album.jsonify()) | ||||||
| 
 | 
 | ||||||
| # Album photo operations ########################################################################### | # Album photo operations ########################################################################### | ||||||
| 
 | 
 | ||||||
|  | @ -120,7 +121,7 @@ def post_album_add_photo(album_id): | ||||||
|     photos = list(common.P_photos(photo_ids, response_type='json')) |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
|     album.add_photos(photos, commit=True) |     album.add_photos(photos, commit=True) | ||||||
|     response = album.jsonify() |     response = album.jsonify() | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>/remove_photo', methods=['POST']) | @site.route('/album/<album_id>/remove_photo', methods=['POST']) | ||||||
| @decorators.required_fields(['photo_id'], forbid_whitespace=True) | @decorators.required_fields(['photo_id'], forbid_whitespace=True) | ||||||
|  | @ -134,7 +135,7 @@ def post_album_remove_photo(album_id): | ||||||
|     photos = list(common.P_photos(photo_ids, response_type='json')) |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
|     album.remove_photos(photos, commit=True) |     album.remove_photos(photos, commit=True) | ||||||
|     response = album.jsonify() |     response = album.jsonify() | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| # Album tag operations ############################################################################# | # Album tag operations ############################################################################# | ||||||
| 
 | 
 | ||||||
|  | @ -151,13 +152,13 @@ def post_album_add_tag(album_id): | ||||||
|         tag = common.P_tag(tag, response_type='json') |         tag = common.P_tag(tag, response_type='json') | ||||||
|     except etiquette.exceptions.NoSuchTag as exc: |     except etiquette.exceptions.NoSuchTag as exc: | ||||||
|         response = exc.jsonify() |         response = exc.jsonify() | ||||||
|         return jsonify.make_json_response(response, status=404) |         return flasktools.make_json_response(response, status=404) | ||||||
|     recursive = request.form.get('recursive', False) |     recursive = request.form.get('recursive', False) | ||||||
|     recursive = etiquette.helpers.truthystring(recursive) |     recursive = etiquette.helpers.truthystring(recursive) | ||||||
|     album.add_tag_to_all(tag, nested_children=recursive, commit=True) |     album.add_tag_to_all(tag, nested_children=recursive, commit=True) | ||||||
|     response['action'] = 'add_tag' |     response['action'] = 'add_tag' | ||||||
|     response['tagname'] = tag.name |     response['tagname'] = tag.name | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| # Album metadata operations ######################################################################## | # Album metadata operations ######################################################################## | ||||||
| 
 | 
 | ||||||
|  | @ -172,7 +173,7 @@ def post_album_edit(album_id): | ||||||
|     description = request.form.get('description', None) |     description = request.form.get('description', None) | ||||||
|     album.edit(title=title, description=description, commit=True) |     album.edit(title=title, description=description, commit=True) | ||||||
|     response = album.jsonify(minimal=True) |     response = album.jsonify(minimal=True) | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>/show_in_folder', methods=['POST']) | @site.route('/album/<album_id>/show_in_folder', methods=['POST']) | ||||||
| def post_album_show_in_folder(album_id): | def post_album_show_in_folder(album_id): | ||||||
|  | @ -188,7 +189,7 @@ def post_album_show_in_folder(album_id): | ||||||
|     if os.name == 'nt': |     if os.name == 'nt': | ||||||
|         command = f'start explorer.exe "{directory.absolute_path}"' |         command = f'start explorer.exe "{directory.absolute_path}"' | ||||||
|         os.system(command) |         os.system(command) | ||||||
|         return jsonify.make_json_response({}) |         return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
|     flask.abort(501) |     flask.abort(501) | ||||||
| 
 | 
 | ||||||
|  | @ -199,7 +200,7 @@ def post_album_show_in_folder(album_id): | ||||||
| def get_all_album_names(): | def get_all_album_names(): | ||||||
|     all_albums = {album.id: album.display_name for album in common.P.get_albums()} |     all_albums = {album.id: album.display_name for album in common.P.get_albums()} | ||||||
|     response = {'albums': all_albums} |     response = {'albums': all_albums} | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| def get_albums_core(): | def get_albums_core(): | ||||||
|     albums = list(common.P.get_root_albums()) |     albums = list(common.P.get_root_albums()) | ||||||
|  | @ -221,7 +222,7 @@ def get_albums_html(): | ||||||
| def get_albums_json(): | def get_albums_json(): | ||||||
|     albums = get_albums_core() |     albums = get_albums_core() | ||||||
|     albums = [album.jsonify(minimal=True) for album in albums] |     albums = [album.jsonify(minimal=True) for album in albums] | ||||||
|     return jsonify.make_json_response(albums) |     return flasktools.make_json_response(albums) | ||||||
| 
 | 
 | ||||||
| # Album create and delete ########################################################################## | # Album create and delete ########################################################################## | ||||||
| 
 | 
 | ||||||
|  | @ -241,10 +242,10 @@ def post_albums_create(): | ||||||
|     common.P.commit('create album endpoint') |     common.P.commit('create album endpoint') | ||||||
| 
 | 
 | ||||||
|     response = album.jsonify(minimal=False) |     response = album.jsonify(minimal=False) | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/album/<album_id>/delete', methods=['POST']) | @site.route('/album/<album_id>/delete', methods=['POST']) | ||||||
| def post_album_delete(album_id): | def post_album_delete(album_id): | ||||||
|     album = common.P_album(album_id, response_type='json') |     album = common.P_album(album_id, response_type='json') | ||||||
|     album.delete(commit=True) |     album.delete(commit=True) | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
|  |  | ||||||
|  | @ -1,5 +1,7 @@ | ||||||
| import flask; from flask import request | import flask; from flask import request | ||||||
| 
 | 
 | ||||||
|  | from voussoirkit import flasktools | ||||||
|  | 
 | ||||||
| import etiquette | import etiquette | ||||||
| 
 | 
 | ||||||
| from .. import common | from .. import common | ||||||
|  | @ -15,7 +17,7 @@ session_manager = common.session_manager | ||||||
| def get_bookmark_json(bookmark_id): | def get_bookmark_json(bookmark_id): | ||||||
|     bookmark = common.P_bookmark(bookmark_id, response_type='json') |     bookmark = common.P_bookmark(bookmark_id, response_type='json') | ||||||
|     response = bookmark.jsonify() |     response = bookmark.jsonify() | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/bookmark/<bookmark_id>/edit', methods=['POST']) | @site.route('/bookmark/<bookmark_id>/edit', methods=['POST']) | ||||||
| def post_bookmark_edit(bookmark_id): | def post_bookmark_edit(bookmark_id): | ||||||
|  | @ -26,7 +28,7 @@ def post_bookmark_edit(bookmark_id): | ||||||
|     bookmark.edit(title=title, url=url, commit=True) |     bookmark.edit(title=title, url=url, commit=True) | ||||||
| 
 | 
 | ||||||
|     response = bookmark.jsonify() |     response = bookmark.jsonify() | ||||||
|     response = jsonify.make_json_response(response) |     response = flasktools.make_json_response(response) | ||||||
|     return response |     return response | ||||||
| 
 | 
 | ||||||
| # Bookmark listings ################################################################################ | # Bookmark listings ################################################################################ | ||||||
|  | @ -39,7 +41,7 @@ def get_bookmarks_html(): | ||||||
| @site.route('/bookmarks.json') | @site.route('/bookmarks.json') | ||||||
| def get_bookmarks_json(): | def get_bookmarks_json(): | ||||||
|     bookmarks = [b.jsonify() for b in common.P.get_bookmarks()] |     bookmarks = [b.jsonify() for b in common.P.get_bookmarks()] | ||||||
|     return jsonify.make_json_response(bookmarks) |     return flasktools.make_json_response(bookmarks) | ||||||
| 
 | 
 | ||||||
| # Bookmark create and delete ####################################################################### | # Bookmark create and delete ####################################################################### | ||||||
| 
 | 
 | ||||||
|  | @ -51,11 +53,11 @@ def post_bookmark_create(): | ||||||
|     user = session_manager.get(request).user |     user = session_manager.get(request).user | ||||||
|     bookmark = common.P.new_bookmark(url=url, title=title, author=user, commit=True) |     bookmark = common.P.new_bookmark(url=url, title=title, author=user, commit=True) | ||||||
|     response = bookmark.jsonify() |     response = bookmark.jsonify() | ||||||
|     response = jsonify.make_json_response(response) |     response = flasktools.make_json_response(response) | ||||||
|     return response |     return response | ||||||
| 
 | 
 | ||||||
| @site.route('/bookmark/<bookmark_id>/delete', methods=['POST']) | @site.route('/bookmark/<bookmark_id>/delete', methods=['POST']) | ||||||
| def post_bookmark_delete(bookmark_id): | def post_bookmark_delete(bookmark_id): | ||||||
|     bookmark = common.P_bookmark(bookmark_id, response_type='json') |     bookmark = common.P_bookmark(bookmark_id, response_type='json') | ||||||
|     bookmark.delete(commit=True) |     bookmark.delete(commit=True) | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ import traceback | ||||||
| import urllib.parse | import urllib.parse | ||||||
| 
 | 
 | ||||||
| from voussoirkit import cacheclass | from voussoirkit import cacheclass | ||||||
|  | from voussoirkit import flasktools | ||||||
| from voussoirkit import stringtools | from voussoirkit import stringtools | ||||||
| 
 | 
 | ||||||
| import etiquette | import etiquette | ||||||
|  | @ -28,7 +29,7 @@ def get_photo_html(photo_id): | ||||||
| def get_photo_json(photo_id): | def get_photo_json(photo_id): | ||||||
|     photo = common.P_photo(photo_id, response_type='json') |     photo = common.P_photo(photo_id, response_type='json') | ||||||
|     photo = photo.jsonify() |     photo = photo.jsonify() | ||||||
|     photo = jsonify.make_json_response(photo) |     photo = flasktools.make_json_response(photo) | ||||||
|     return photo |     return photo | ||||||
| 
 | 
 | ||||||
| @site.route('/file/<photo_id>') | @site.route('/file/<photo_id>') | ||||||
|  | @ -76,7 +77,7 @@ def post_photo_delete(photo_id): | ||||||
|     delete_file = request.form.get('delete_file', False) |     delete_file = request.form.get('delete_file', False) | ||||||
|     delete_file = etiquette.helpers.truthystring(delete_file) |     delete_file = etiquette.helpers.truthystring(delete_file) | ||||||
|     photo.delete(delete_file=delete_file, commit=True) |     photo.delete(delete_file=delete_file, commit=True) | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
| # Photo tag operations ############################################################################# | # Photo tag operations ############################################################################# | ||||||
| 
 | 
 | ||||||
|  | @ -95,7 +96,7 @@ def post_photo_add_remove_tag_core(photo_ids, tagname, add_or_remove): | ||||||
|     common.P.commit('photo add remove tag core') |     common.P.commit('photo add remove tag core') | ||||||
| 
 | 
 | ||||||
|     response = {'action': add_or_remove, 'tagname': tag.name} |     response = {'action': add_or_remove, 'tagname': tag.name} | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/photo/<photo_id>/add_tag', methods=['POST']) | @site.route('/photo/<photo_id>/add_tag', methods=['POST']) | ||||||
| @decorators.required_fields(['tagname'], forbid_whitespace=True) | @decorators.required_fields(['tagname'], forbid_whitespace=True) | ||||||
|  | @ -120,7 +121,7 @@ def post_photo_copy_tags(photo_id): | ||||||
|     other = common.P_photo(request.form['other_photo'], response_type='json') |     other = common.P_photo(request.form['other_photo'], response_type='json') | ||||||
|     photo.copy_tags(other) |     photo.copy_tags(other) | ||||||
|     common.P.commit('photo copy tags') |     common.P.commit('photo copy tags') | ||||||
|     return jsonify.make_json_response([tag.jsonify(minimal=True) for tag in photo.get_tags()]) |     return flasktools.make_json_response([tag.jsonify(minimal=True) for tag in photo.get_tags()]) | ||||||
| 
 | 
 | ||||||
| @site.route('/photo/<photo_id>/remove_tag', methods=['POST']) | @site.route('/photo/<photo_id>/remove_tag', methods=['POST']) | ||||||
| @decorators.required_fields(['tagname'], forbid_whitespace=True) | @decorators.required_fields(['tagname'], forbid_whitespace=True) | ||||||
|  | @ -165,7 +166,7 @@ def post_photo_generate_thumbnail(photo_id): | ||||||
|     photo = common.P_photo(photo_id, response_type='json') |     photo = common.P_photo(photo_id, response_type='json') | ||||||
|     photo.generate_thumbnail(commit=True, **special) |     photo.generate_thumbnail(commit=True, **special) | ||||||
| 
 | 
 | ||||||
|     response = jsonify.make_json_response({}) |     response = flasktools.make_json_response({}) | ||||||
|     return response |     return response | ||||||
| 
 | 
 | ||||||
| def post_photo_refresh_metadata_core(photo_ids): | def post_photo_refresh_metadata_core(photo_ids): | ||||||
|  | @ -186,7 +187,7 @@ def post_photo_refresh_metadata_core(photo_ids): | ||||||
| 
 | 
 | ||||||
|     common.P.commit('photo refresh metadata core') |     common.P.commit('photo refresh metadata core') | ||||||
| 
 | 
 | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
| @site.route('/photo/<photo_id>/refresh_metadata', methods=['POST']) | @site.route('/photo/<photo_id>/refresh_metadata', methods=['POST']) | ||||||
| def post_photo_refresh_metadata(photo_id): | def post_photo_refresh_metadata(photo_id): | ||||||
|  | @ -203,13 +204,13 @@ def post_batch_photos_refresh_metadata(): | ||||||
| def post_photo_set_searchhidden(photo_id): | def post_photo_set_searchhidden(photo_id): | ||||||
|     photo = common.P_photo(photo_id, response_type='json') |     photo = common.P_photo(photo_id, response_type='json') | ||||||
|     photo.set_searchhidden(True) |     photo.set_searchhidden(True) | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
| @site.route('/photo/<photo_id>/unset_searchhidden', methods=['POST']) | @site.route('/photo/<photo_id>/unset_searchhidden', methods=['POST']) | ||||||
| def post_photo_unset_searchhidden(photo_id): | def post_photo_unset_searchhidden(photo_id): | ||||||
|     photo = common.P_photo(photo_id, response_type='json') |     photo = common.P_photo(photo_id, response_type='json') | ||||||
|     photo.set_searchhidden(False) |     photo.set_searchhidden(False) | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
| def post_batch_photos_searchhidden_core(photo_ids, searchhidden): | def post_batch_photos_searchhidden_core(photo_ids, searchhidden): | ||||||
|     if isinstance(photo_ids, str): |     if isinstance(photo_ids, str): | ||||||
|  | @ -222,7 +223,7 @@ def post_batch_photos_searchhidden_core(photo_ids, searchhidden): | ||||||
| 
 | 
 | ||||||
|     common.P.commit('photo set searchhidden core') |     common.P.commit('photo set searchhidden core') | ||||||
| 
 | 
 | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
| @site.route('/photo/<photo_id>/show_in_folder', methods=['POST']) | @site.route('/photo/<photo_id>/show_in_folder', methods=['POST']) | ||||||
| def post_photo_show_in_folder(photo_id): | def post_photo_show_in_folder(photo_id): | ||||||
|  | @ -233,7 +234,7 @@ def post_photo_show_in_folder(photo_id): | ||||||
|     if os.name == 'nt': |     if os.name == 'nt': | ||||||
|         command = f'start explorer.exe /select,"{photo.real_path.absolute_path}"' |         command = f'start explorer.exe /select,"{photo.real_path.absolute_path}"' | ||||||
|         os.system(command) |         os.system(command) | ||||||
|         return jsonify.make_json_response({}) |         return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
|     flask.abort(501) |     flask.abort(501) | ||||||
| 
 | 
 | ||||||
|  | @ -269,7 +270,7 @@ def post_batch_photos(): | ||||||
|     photos = list(common.P_photos(photo_ids, response_type='json')) |     photos = list(common.P_photos(photo_ids, response_type='json')) | ||||||
| 
 | 
 | ||||||
|     photos = [photo.jsonify() for photo in photos] |     photos = [photo.jsonify() for photo in photos] | ||||||
|     response = jsonify.make_json_response(photos) |     response = flasktools.make_json_response(photos) | ||||||
|     return response |     return response | ||||||
| 
 | 
 | ||||||
| @site.route('/batch/photos/photo_card', methods=['POST']) | @site.route('/batch/photos/photo_card', methods=['POST']) | ||||||
|  | @ -295,7 +296,7 @@ def post_batch_photos_photo_cards(): | ||||||
|     divs = [div for div in divs if div] |     divs = [div for div in divs if div] | ||||||
|     divs = [div.split(':', 1) for div in divs] |     divs = [div.split(':', 1) for div in divs] | ||||||
|     divs = {photo_id.strip(): photo_card.strip() for (photo_id, photo_card) in divs} |     divs = {photo_id.strip(): photo_card.strip() for (photo_id, photo_card) in divs} | ||||||
|     response = jsonify.make_json_response(divs) |     response = flasktools.make_json_response(divs) | ||||||
|     return response |     return response | ||||||
| 
 | 
 | ||||||
| # Zipping ########################################################################################## | # Zipping ########################################################################################## | ||||||
|  | @ -348,7 +349,7 @@ def post_batch_photos_download_zip(): | ||||||
|     photo_download_zip_tokens[zip_token] = photo_ids |     photo_download_zip_tokens[zip_token] = photo_ids | ||||||
| 
 | 
 | ||||||
|     response = {'zip_token': zip_token} |     response = {'zip_token': zip_token} | ||||||
|     response = jsonify.make_json_response(response) |     response = flasktools.make_json_response(response) | ||||||
|     return response |     return response | ||||||
| 
 | 
 | ||||||
| # Search ########################################################################################### | # Search ########################################################################################### | ||||||
|  | @ -548,7 +549,7 @@ def get_search_json(): | ||||||
|     search_results['total_tags'] = [ |     search_results['total_tags'] = [ | ||||||
|         tag.jsonify(minimal=True) for tag in search_results['total_tags'] |         tag.jsonify(minimal=True) for tag in search_results['total_tags'] | ||||||
|     ] |     ] | ||||||
|     return jsonify.make_json_response(search_results) |     return flasktools.make_json_response(search_results) | ||||||
| 
 | 
 | ||||||
| # Swipe ############################################################################################ | # Swipe ############################################################################################ | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,8 @@ | ||||||
| import flask; from flask import request | import flask; from flask import request | ||||||
| import time | import time | ||||||
| 
 | 
 | ||||||
|  | from voussoirkit import flasktools | ||||||
|  | 
 | ||||||
| import etiquette | import etiquette | ||||||
| 
 | 
 | ||||||
| from .. import common | from .. import common | ||||||
|  | @ -40,7 +42,7 @@ def get_tag_json(specific_tag_name): | ||||||
|     include_synonyms = include_synonyms is None or etiquette.helpers.truthystring(include_synonyms) |     include_synonyms = include_synonyms is None or etiquette.helpers.truthystring(include_synonyms) | ||||||
| 
 | 
 | ||||||
|     response = specific_tag.jsonify(include_synonyms=include_synonyms) |     response = specific_tag.jsonify(include_synonyms=include_synonyms) | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/tag/<tagname>/edit', methods=['POST']) | @site.route('/tag/<tagname>/edit', methods=['POST']) | ||||||
| def post_tag_edit(tagname): | def post_tag_edit(tagname): | ||||||
|  | @ -53,7 +55,7 @@ def post_tag_edit(tagname): | ||||||
|     tag.edit(description=description, commit=True) |     tag.edit(description=description, commit=True) | ||||||
| 
 | 
 | ||||||
|     response = tag.jsonify() |     response = tag.jsonify() | ||||||
|     response = jsonify.make_json_response(response) |     response = flasktools.make_json_response(response) | ||||||
|     return response |     return response | ||||||
| 
 | 
 | ||||||
| @site.route('/tag/<tagname>/add_child', methods=['POST']) | @site.route('/tag/<tagname>/add_child', methods=['POST']) | ||||||
|  | @ -63,7 +65,7 @@ def post_tag_add_child(tagname): | ||||||
|     child = common.P_tag(request.form['child_name'], response_type='json') |     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 flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/tag/<tagname>/add_synonym', methods=['POST']) | @site.route('/tag/<tagname>/add_synonym', methods=['POST']) | ||||||
| @decorators.required_fields(['syn_name'], forbid_whitespace=True) | @decorators.required_fields(['syn_name'], forbid_whitespace=True) | ||||||
|  | @ -74,7 +76,7 @@ def post_tag_add_synonym(tagname): | ||||||
|     syn_name = master_tag.add_synonym(syn_name, commit=True) |     syn_name = master_tag.add_synonym(syn_name, commit=True) | ||||||
| 
 | 
 | ||||||
|     response = {'action': 'add_synonym', 'synonym': syn_name} |     response = {'action': 'add_synonym', 'synonym': syn_name} | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/tag/<tagname>/remove_child', methods=['POST']) | @site.route('/tag/<tagname>/remove_child', methods=['POST']) | ||||||
| @decorators.required_fields(['child_name'], forbid_whitespace=True) | @decorators.required_fields(['child_name'], forbid_whitespace=True) | ||||||
|  | @ -83,7 +85,7 @@ def post_tag_remove_child(tagname): | ||||||
|     child = common.P_tag(request.form['child_name'], response_type='json') |     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 flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/tag/<tagname>/remove_synonym', methods=['POST']) | @site.route('/tag/<tagname>/remove_synonym', methods=['POST']) | ||||||
| @decorators.required_fields(['syn_name'], forbid_whitespace=True) | @decorators.required_fields(['syn_name'], forbid_whitespace=True) | ||||||
|  | @ -94,7 +96,7 @@ def post_tag_remove_synonym(tagname): | ||||||
|     syn_name = master_tag.remove_synonym(syn_name, commit=True) |     syn_name = master_tag.remove_synonym(syn_name, commit=True) | ||||||
| 
 | 
 | ||||||
|     response = {'action': 'delete_synonym', 'synonym': syn_name} |     response = {'action': 'delete_synonym', 'synonym': syn_name} | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| # Tag listings ##################################################################################### | # Tag listings ##################################################################################### | ||||||
| 
 | 
 | ||||||
|  | @ -104,7 +106,7 @@ def get_all_tag_names(): | ||||||
|     all_tags = list(common.P.get_all_tag_names()) |     all_tags = list(common.P.get_all_tag_names()) | ||||||
|     all_synonyms = common.P.get_all_synonyms() |     all_synonyms = common.P.get_all_synonyms() | ||||||
|     response = {'tags': all_tags, 'synonyms': all_synonyms} |     response = {'tags': all_tags, 'synonyms': all_synonyms} | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/tag/<specific_tag_name>') | @site.route('/tag/<specific_tag_name>') | ||||||
| @site.route('/tags') | @site.route('/tags') | ||||||
|  | @ -153,7 +155,7 @@ def get_tags_json(): | ||||||
|     tags = list(common.P.get_tags()) |     tags = list(common.P.get_tags()) | ||||||
|     response = [tag.jsonify(include_synonyms=include_synonyms) for tag in tags] |     response = [tag.jsonify(include_synonyms=include_synonyms) for tag in tags] | ||||||
| 
 | 
 | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| # Tag create and delete ############################################################################ | # Tag create and delete ############################################################################ | ||||||
| 
 | 
 | ||||||
|  | @ -165,7 +167,7 @@ def post_tag_create(): | ||||||
| 
 | 
 | ||||||
|     tag = common.P.new_tag(name, description, author=session_manager.get(request).user, commit=True) |     tag = common.P.new_tag(name, description, author=session_manager.get(request).user, commit=True) | ||||||
|     response = tag.jsonify() |     response = tag.jsonify() | ||||||
|     return jsonify.make_json_response(response) |     return flasktools.make_json_response(response) | ||||||
| 
 | 
 | ||||||
| @site.route('/tags/easybake', methods=['POST']) | @site.route('/tags/easybake', methods=['POST']) | ||||||
| @decorators.required_fields(['easybake_string'], forbid_whitespace=True) | @decorators.required_fields(['easybake_string'], forbid_whitespace=True) | ||||||
|  | @ -174,11 +176,11 @@ def post_tag_easybake(): | ||||||
| 
 | 
 | ||||||
|     notes = common.P.easybake(easybake_string, author=session_manager.get(request).user, commit=True) |     notes = common.P.easybake(easybake_string, author=session_manager.get(request).user, commit=True) | ||||||
|     notes = [{'action': action, 'tagname': tagname} for (action, tagname) in notes] |     notes = [{'action': action, 'tagname': tagname} for (action, tagname) in notes] | ||||||
|     return jsonify.make_json_response(notes) |     return flasktools.make_json_response(notes) | ||||||
| 
 | 
 | ||||||
| @site.route('/tag/<tagname>/delete', methods=['POST']) | @site.route('/tag/<tagname>/delete', methods=['POST']) | ||||||
| def post_tag_delete(tagname): | def post_tag_delete(tagname): | ||||||
|     tag = common.P_tag(tagname, response_type='json') |     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 flasktools.make_json_response(response) | ||||||
|  |  | ||||||
|  | @ -1,5 +1,7 @@ | ||||||
| import flask; from flask import request | import flask; from flask import request | ||||||
| 
 | 
 | ||||||
|  | from voussoirkit import flasktools | ||||||
|  | 
 | ||||||
| import etiquette | import etiquette | ||||||
| 
 | 
 | ||||||
| from .. import common | from .. import common | ||||||
|  | @ -21,7 +23,7 @@ def get_user_html(username): | ||||||
| def get_user_json(username): | def get_user_json(username): | ||||||
|     user = common.P_user(username, response_type='json') |     user = common.P_user(username, response_type='json') | ||||||
|     user = user.jsonify() |     user = user.jsonify() | ||||||
|     return jsonify.make_json_response(user) |     return flasktools.make_json_response(user) | ||||||
| 
 | 
 | ||||||
| @site.route('/userid/<user_id>') | @site.route('/userid/<user_id>') | ||||||
| @site.route('/userid/<user_id>.json') | @site.route('/userid/<user_id>.json') | ||||||
|  | @ -40,10 +42,10 @@ def post_user_edit(username): | ||||||
|     session = session_manager.get(request) |     session = session_manager.get(request) | ||||||
| 
 | 
 | ||||||
|     if not session: |     if not session: | ||||||
|         return jsonify.make_json_response(etiquette.exceptions.Unauthorized().jsonify(), status=403) |         return flasktools.make_json_response(etiquette.exceptions.Unauthorized().jsonify(), status=403) | ||||||
|     user = common.P_user(username, response_type='json') |     user = common.P_user(username, response_type='json') | ||||||
|     if session.user != user: |     if session.user != user: | ||||||
|         return jsonify.make_json_response(etiquette.exceptions.Unauthorized().jsonify(), status=403) |         return flasktools.make_json_response(etiquette.exceptions.Unauthorized().jsonify(), status=403) | ||||||
| 
 | 
 | ||||||
|     display_name = request.form.get('display_name') |     display_name = request.form.get('display_name') | ||||||
|     if display_name is not None: |     if display_name is not None: | ||||||
|  | @ -51,7 +53,7 @@ def post_user_edit(username): | ||||||
| 
 | 
 | ||||||
|     common.P.commit() |     common.P.commit() | ||||||
| 
 | 
 | ||||||
|     return jsonify.make_json_response(user.jsonify()) |     return flasktools.make_json_response(user.jsonify()) | ||||||
| 
 | 
 | ||||||
| # Login and logout ################################################################################# | # Login and logout ################################################################################# | ||||||
| 
 | 
 | ||||||
|  | @ -72,7 +74,7 @@ def post_login(): | ||||||
|     if session.user: |     if session.user: | ||||||
|         exc = etiquette.exceptions.AlreadySignedIn() |         exc = etiquette.exceptions.AlreadySignedIn() | ||||||
|         response = exc.jsonify() |         response = exc.jsonify() | ||||||
|         return jsonify.make_json_response(response, status=403) |         return flasktools.make_json_response(response, status=403) | ||||||
| 
 | 
 | ||||||
|     username = request.form['username'] |     username = request.form['username'] | ||||||
|     password = request.form['password'] |     password = request.form['password'] | ||||||
|  | @ -85,18 +87,18 @@ def post_login(): | ||||||
|     except (etiquette.exceptions.NoSuchUser, etiquette.exceptions.WrongLogin): |     except (etiquette.exceptions.NoSuchUser, etiquette.exceptions.WrongLogin): | ||||||
|         exc = etiquette.exceptions.WrongLogin() |         exc = etiquette.exceptions.WrongLogin() | ||||||
|         response = exc.jsonify() |         response = exc.jsonify() | ||||||
|         return jsonify.make_json_response(response, status=422) |         return flasktools.make_json_response(response, status=422) | ||||||
|     except etiquette.exceptions.FeatureDisabled as exc: |     except etiquette.exceptions.FeatureDisabled as exc: | ||||||
|         response = exc.jsonify() |         response = exc.jsonify() | ||||||
|         return jsonify.make_json_response(response, status=400) |         return flasktools.make_json_response(response, status=400) | ||||||
|     session = sessions.Session(request, user) |     session = sessions.Session(request, user) | ||||||
|     session_manager.add(session) |     session_manager.add(session) | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
| 
 | 
 | ||||||
| @site.route('/logout', methods=['POST']) | @site.route('/logout', methods=['POST']) | ||||||
| def logout(): | def logout(): | ||||||
|     session_manager.remove(request) |     session_manager.remove(request) | ||||||
|     response = jsonify.make_json_response({}) |     response = flasktools.make_json_response({}) | ||||||
|     return response |     return response | ||||||
| 
 | 
 | ||||||
| # User registration ################################################################################ | # User registration ################################################################################ | ||||||
|  | @ -112,7 +114,7 @@ def post_register(): | ||||||
|     if session.user: |     if session.user: | ||||||
|         exc = etiquette.exceptions.AlreadySignedIn() |         exc = etiquette.exceptions.AlreadySignedIn() | ||||||
|         response = exc.jsonify() |         response = exc.jsonify() | ||||||
|         return jsonify.make_json_response(response, status=403) |         return flasktools.make_json_response(response, status=403) | ||||||
| 
 | 
 | ||||||
|     username = request.form['username'] |     username = request.form['username'] | ||||||
|     display_name = request.form.get('display_name', None) |     display_name = request.form.get('display_name', None) | ||||||
|  | @ -124,10 +126,10 @@ def post_register(): | ||||||
|             'error_type': 'PASSWORDS_DONT_MATCH', |             'error_type': 'PASSWORDS_DONT_MATCH', | ||||||
|             'error_message': 'Passwords do not match.', |             'error_message': 'Passwords do not match.', | ||||||
|         } |         } | ||||||
|         return jsonify.make_json_response(response, status=422) |         return flasktools.make_json_response(response, status=422) | ||||||
| 
 | 
 | ||||||
|     user = common.P.new_user(username, password_1, display_name=display_name, commit=True) |     user = common.P.new_user(username, password_1, display_name=display_name, commit=True) | ||||||
| 
 | 
 | ||||||
|     session = sessions.Session(request, user) |     session = sessions.Session(request, user) | ||||||
|     session_manager.add(session) |     session_manager.add(session) | ||||||
|     return jsonify.make_json_response({}) |     return flasktools.make_json_response({}) | ||||||
|  |  | ||||||
|  | @ -1,8 +0,0 @@ | ||||||
| import flask |  | ||||||
| import json |  | ||||||
| 
 |  | ||||||
| def make_json_response(j, *args, **kwargs): |  | ||||||
|     dumped = json.dumps(j) |  | ||||||
|     response = flask.Response(dumped, *args, **kwargs) |  | ||||||
|     response.headers['Content-Type'] = 'application/json;charset=utf-8' |  | ||||||
|     return response |  | ||||||
		Loading…
	
		Reference in a new issue