def route__api__entity_type__relations__entity_id(entity_type, entity_id): if entity_type not in ('artist', 'label'): raise exceptions.APIError(message='Bad Entity Type', status_code=404) data = helpers.get_relations( entity_id, entity_type, ) if data is None: raise exceptions.APIError(message='No Data', status_code=400) return jsonify(data)
def route__entity_type__entity_id(entity_type, entity_id): import discograph app = current_app._get_current_object() parsed_args = helpers.parse_request_args(request.args) original_roles, original_year = parsed_args if not original_roles: original_roles = default_roles if entity_type not in ('artist', 'label'): raise exceptions.APIError(message='Bad Entity Type', status_code=404) on_mobile = request.MOBILE data = helpers.get_network( entity_id, entity_type, on_mobile=on_mobile, cache=True, roles=original_roles, ) if data is None: raise exceptions.APIError(message='No Data', status_code=500) initial_json = json.dumps( data, sort_keys=True, indent=4, separators=(',', ': '), ) initial_json = 'var dgData = {};'.format(initial_json) entity_name = data['center']['name'] is_a_return_visitor = request.cookies.get('is_a_return_visitor') key = '{}-{}'.format(entity_type, entity_id) #url = '/{}/{}'.format(entity_type, entity_id) url = url_for( request.endpoint, entity_type=entity_type, entity_id=entity_id, roles=original_roles, ) title = 'Disco/graph: {}'.format(entity_name) multiselect_mapping = discograph.CreditRole.get_multiselect_mapping() rendered_template = render_template( 'index.html', application_url=app.config['APPLICATION_ROOT'], initial_json=initial_json, is_a_return_visitor=is_a_return_visitor, key=key, multiselect_mapping=multiselect_mapping, og_title='Disco/graph: The "{}" network'.format(entity_name), og_url=url, on_mobile=on_mobile, original_roles=original_roles, original_year=original_year, title=title, ) response = make_response(rendered_template) response.set_cookie('is_a_return_visitor', 'true') return response
def route__api__entity_type__network__entity_id(entity_type, entity_id): if entity_type not in ('artist', 'label'): raise exceptions.APIError(message='Bad Entity Type', status_code=404) parsed_args = helpers.parse_request_args(request.args) original_roles, original_year = parsed_args on_mobile = request.MOBILE data = helpers.get_network( entity_id, entity_type, on_mobile=on_mobile, cache=True, roles=original_roles, ) if data is None: raise exceptions.APIError(message='No Data', status_code=400) return jsonify(data)
def handle_error_500(error): status_code = 500 error = exceptions.APIError( message='Something Broke', status_code=status_code, ) rendered_template = render_template('error.html', error=error) response = make_response(rendered_template) response.status_code = status_code return response
def handle_error_404(error): status_code = 404 error = exceptions.APIError( message='Not Found', status_code=status_code, ) rendered_template = render_template('error.html', error=error) response = make_response(rendered_template) response.status_code = status_code return response