Ejemplo n.º 1
0
def route__index():
    import discograph
    app = current_app._get_current_object()
    is_a_return_visitor = request.cookies.get('is_a_return_visitor')
    initial_json = 'var dgData = null;'
    on_mobile = request.MOBILE
    parsed_args = helpers.parse_request_args(request.args)
    original_role_names, original_year = parsed_args
    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,
        multiselect_mapping=multiselect_mapping,
        og_title='Disco/graph: visualizing music as a social graph',
        og_url='/',
        on_mobile=on_mobile,
        original_role_names=original_role_names,
        original_year=original_year,
        title='Disco/graph: Visualizing music as a social graph',
        )
    response = make_response(rendered_template)
    response.set_cookie('is_a_return_visitor', 'true')
    return response
Ejemplo n.º 2
0
def route__index():
    import discograph
    app = current_app._get_current_object()
    is_a_return_visitor = request.cookies.get('is_a_return_visitor')
    initial_json = 'var dgData = null;'
    on_mobile = request.MOBILE
    parsed_args = helpers.parse_request_args(request.args)
    original_roles, original_year = parsed_args
    if not original_roles:
        original_roles = default_roles
    multiselect_mapping = discograph.CreditRole.get_multiselect_mapping()
    url = url_for(
        request.endpoint,
        roles=original_roles,
    )
    rendered_template = render_template(
        'index.html',
        application_url=app.config['APPLICATION_ROOT'],
        initial_json=initial_json,
        is_a_return_visitor=is_a_return_visitor,
        multiselect_mapping=multiselect_mapping,
        og_title='Disco/graph: visualizing music as a social graph',
        og_url=url,
        on_mobile=on_mobile,
        original_roles=original_roles,
        original_year=original_year,
        title='Disco/graph: Visualizing music as a social graph',
    )
    response = make_response(rendered_template)
    response.set_cookie('is_a_return_visitor', 'true')
    return response
Ejemplo n.º 3
0
def route__api__random():
    parsed_args = helpers.parse_request_args(request.args)
    original_roles, original_year = parsed_args
    print("Roles:", original_roles)
    entity_type, entity_id = helpers.get_random_entity(roles=original_roles)
    print("    Found: {}-{}".format(entity_type, entity_id))
    entity_type = {1: "artist", 2: "label"}[entity_type]
    data = {"center": "{}-{}".format(entity_type, entity_id)}
    return jsonify(data)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def route__api__random():
    parsed_args = helpers.parse_request_args(request.args)
    original_roles, original_year = parsed_args
    print('Roles:', original_roles)
    entity_type, entity_id = helpers.get_random_entity(roles=original_roles, )
    print('    Found: {}-{}'.format(entity_type, entity_id))
    entity_type = {
        1: 'artist',
        2: 'label',
    }[entity_type]
    data = {'center': '{}-{}'.format(entity_type, entity_id)}
    return jsonify(data)
Ejemplo n.º 8
0
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)