Ejemplo n.º 1
0
def get_compliant(request, hashed_sets, graph):
    try:
        neo_licenses = get_compatible_licenses(hashed_sets, graph)
        compatible_licenses = []
        for neo_license in neo_licenses:
            license_object = ObjectFactory.objectLicense(neo_license)
            compatible_licenses.append(license_object.to_json())
        response = HttpResponse(json.dumps(compatible_licenses),
                                content_type='application/json')
    except DoesNotExist:
        response = HttpResponse(
            "[]",
            content_type='application/json',
            status=404,
        )
    response['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 2
0
def rep_search(request):
    graph = 'rep'
    query = request.GET.get('query', '')
    hashed_sets = request.GET.get('license', '')
    sens = request.GET.get('sens', '')
    keywords = query.split()
    results = []
    nodes = []
    links = []
    added_nodes = []
    if sens == 'compatible':
        neo_licenses = get_compliant_licenses(hashed_sets, graph)
    else:
        neo_licenses = get_compatible_licenses(hashed_sets, graph)
    for neo_license in neo_licenses:
        license_object = ObjectFactory.objectLicense(neo_license)
        if keywords:
            license_object = query_filter(license_object, keywords)
        if license_object.datasets:
            results.append(license_object.to_json())
        # we add license and datasets to the graph
        if license_object not in added_nodes:
            nodes.append(D3jsData.license_node(license_object))
            added_nodes.append(license_object)
        for dataset_object in license_object.datasets:
            nodes.append(
                D3jsData.dataset_node(dataset_object,
                                      license_object.get_level()))
            links.append(D3jsData.dataset_link(license_object, dataset_object))
        for compatible_neo_license in neo_license.followings.all():
            compatible_license_object = ObjectFactory.objectLicense(
                compatible_neo_license)
            if compatible_license_object not in added_nodes and compatible_neo_license in neo_licenses:
                nodes.append(D3jsData.license_node(compatible_license_object))
                added_nodes.append(compatible_license_object)
            if compatible_neo_license in neo_licenses:
                links.append(
                    D3jsData.compatible_link(license_object,
                                             compatible_license_object))
    return render(
        request, 'search.html', {
            'results': json.dumps(results),
            'nb_datasets': nb_datasets(results),
            'graph': json.dumps(D3jsData.graph(nodes, links)),
            'classification': graph
        })
Ejemplo n.º 3
0
def search(request):
    query = request.GET.get('query', '')
    hashed_sets = request.GET.get('license', '')
    sens = request.GET.get('sens', '')
    keywords = query.split()
    results = []
    if sens == 'compatible':
        neo_licenses = get_compliant_licenses(hashed_sets)
    else:
        neo_licenses = get_compatible_licenses(hashed_sets)
    for neo_license in neo_licenses:
        license_object = ObjectFactory.objectLicense(neo_license)
        if keywords:
            license_object = query_filter(license_object, keywords)
        if license_object:
            results.append(license_object.to_json())
    return render(request, 'search.html', {'results': json.dumps(results), 'nb_datasets': nb_datasets(results)})