Esempio n. 1
0
def advance_search_view(request):
    dataset = ''
    datasetLabel = ''
    conceptClass = ''
    user = request.user
    name = 'query-' + datetime.utcnow().strftime("%Y-%m-%d-%H:%M")
    results = ''
    breadcrum = [0, 0, 0]
    if request.GET.get('groups_query', None) is not None:

        groups_query = unquote(request.GET['groups_query'])
        load_groups = simplejson.loads(groups_query)

        ####### Save History #######
        if user.is_authenticated():
            query_obj = Query(name=name, query=groups_query)
            query_obj.save()
            query_obj.user.add(user)

        results = complex_query_connector(load_groups, request.user)
        breadcrum[0] = 1
    elif request.GET.get('id', None) is not None:

        query_obj = Query.objects.get(id=request.GET['id'])
        groups_query = unquote(query_obj.query)
        load_groups = simplejson.loads(groups_query)

        ####### Save History #######
        query_obj = Query.objects.get(id=id)
        if user.is_authenticated():
            if not query_obj.saved:
                query_obj.name = name
            query_obj.query = groups_query
            query_obj.date = datetime.utcnow()
            query_obj.save()
            query_obj.user.add(user)

        results = complex_query_connector(load_groups, request.user)
        breadcrum[0] = 1

    return render_to_response('scs_search/scs_search.html',
                              {'search': 'complex', 'results': results, 'dataset': dataset, 'datasetLabel': datasetLabel
                                  , 'class': conceptClass, 'breadcrum': breadcrum, 'classLabel': ''},
                              RequestContext(request))
Esempio n. 2
0
def complex_query_service(request):
    """
        Complex Query Service
    """

    if request.method == 'POST':

        groups_query = request.POST['groups_query']
        id = request.POST.get('id', "")
        load_groups = simplejson.loads(groups_query)

        ####### Save History #######
        user = request.user
        name = 'query-' + datetime.utcnow().strftime("%Y-%m-%d-%H:%M")

        try:
            if id == "":
                query_obj = Query(name=name, query=groups_query)
            else:
                query_obj = Query.objects.get(id=id)
                if not query_obj.saved:
                    query_obj.name = name
                query_obj.query = groups_query
                query_obj.date = datetime.utcnow()
            if user.is_authenticated():
                query_obj.save()
                query_obj.user.add(user)
        except Exception, e:
            pass
            ############################

        connector = json.dumps(complex_query_connector(load_groups,request.user), sort_keys=False)

        response = HttpResponse(content=connector,
                                content_type='application/json ')
        response._is_string = False

        return response
Esempio n. 3
0
def annotation_search_view(request):
    """
        annotation Search view
    """
    dataset = ''
    datasetLabel = ''
    conceptClass = ''
    conceptLabel = ''
    user = request.user
    name = 'query-' + datetime.utcnow().strftime("%Y-%m-%d-%H:%M")
    results = ''
    explore = ''
    if request.GET.get('groups_query', None) is not None:

        groups_query = unquote(request.GET['groups_query'])
        load_groups = simplejson.loads(groups_query)
        dataset = unquote(request.GET['dataset'])
        datasetLabel = unquote(request.GET['datasetLabel'])
        conceptClass = class_search_connector(None, datasetLabel, num_max_hits='200', page_num='1').get('1',[])

        import re
        r = re.compile('sparqlEndpoint=(.*?)&')
        endpoint_url = r.search(dataset)
        ####### Save History #######
        query_obj = Query(name=name, query=groups_query)
        query_obj.save()
        query_obj.user.add(user)
        query_sparql = json2sparql(load_groups)
        results =dataset_query_connector(query_sparql, endpoint_url, request.user.username, request.ticket)
    elif request.GET.get('id', None) is not None:

        query_obj = Query.objects.get(id=request.GET['id'])
        groups_query = unquote(query_obj.query)
        load_groups = simplejson.loads(groups_query)

        ####### Save History #######
        query_obj = Query.objects.get(id=id)
        if not query_obj.saved:
            query_obj.name = name
        query_obj.query = groups_query
        query_obj.date = datetime.utcnow()
        query_obj.save()
        query_obj.user.add(user)

        results = complex_query_connector(load_groups, request.user)
    if request.GET.get('dataset', None) is not None:
        dataset = unquote(request.GET['dataset'])
        datasetLabel = unquote(request.GET['datasetLabel'])
        import re
        r = re.compile('sparqlEndpoint=(.*?)&')
        endpoint_url = r.search(dataset)
        if 'read/sparql' in endpoint_url.group(1):
            explore = endpoint_url.group(1).replace('read/sparql', 'explore/sql.html')
            explore = explore.replace('https://','https://*****:*****@'%request.ticket)
        conceptClass = class_search_connector(None, datasetLabel, num_max_hits='200', page_num='1').get('1',[])
        #conceptClass = unquote(request.GET['conceptClass'])
        #conceptClassLabel = unquote(request.GET['conceptLabel'])
        #annotations = annotation_search_connector(None, dataset, conceptClass, conceptClassLabel, num_max_hits='200', page_num='1')

    return render_to_response('scs_search/scs_search.html',
                              {'search': 'complex', 'results': results, 'dataset': dataset, 'datasetLabel': datasetLabel
                                  , 'class': conceptClass, 'breadcrum': [1, 1, 1], 'classLabel': conceptLabel, 'conceptClass': conceptClass, 'explore':explore},
                              RequestContext(request))