Exemple #1
0
def create_query(request):
    """

    :param request:
    :return:
    """
    if request.method != 'POST':
        return json_response({
            'status': 'error',
            'message': 'Invalid request type'
        })

    form = QueryForm(request.POST)
    if form.is_valid():
        query = Query(**form.cleaned_data)
        query.user = request.user
        query.is_public = form.cleaned_data['is_public'] == u'True'
        query.save()
        return json_response({
            'status': 'success',
            'message': 'Query successfully created',
            'query': query.to_dict()
        })

    return json_response({
        'status': 'error',
        'message': 'Fill all required fields'
    })
    def post(self):
        json_data = request.json

        query = Query(json_data.get('term', None),
                      json_data.get('place', None),
                      json_data.get('startTime', None),
                      json_data.get('endTime', None), json_data.get('k', 10))

        logger.info('Executing search query')
        hits = self.search_adapter.find(query)
        logger.info('Done executing search query')
        return hits
Exemple #3
0
def create_query(request):
    """

    :param request:
    :return:
    """
    if request.method != 'POST':
        return json_response({
            'status': 'error',
            'message': 'Invalid request type'
        })

    form = QueryForm(request.POST)
    if form.is_valid():
        query = Query(**form.cleaned_data)
        query.user = request.user
        query.is_public = form.cleaned_data['is_public'] == u'True'
        query.save()
        return json_response({
            'status': 'success',
            'message': 'Query successfully created',
            'query': query.to_dict()
        })

    return json_response({
        'status': 'error',
        'message': 'Fill all required fields'
    })
    def handle(self, *args, **options):
        fake = Factory.create('es_ES')

        for _ in range(0, 5):
            oprtions = ['RE', 'OF']
            random.shuffle(oprtions)
            q = Query(intention=oprtions.pop())
            q.save()
            for _ in range(0, 5):
                q.keywords.add(fake.first_name())
            q.save()
def compute_new_state(request):
    """ GET - Get query state that represents a new query ready to get its similarities computed.
    <ul>
        <li>Polled by broker in algorithm project.</li>
        <li>
            <a href="https://github.com/PARC-projects/video-query-api/blob/master/src/queries/models/process_state.py">
                Processing State
            </a> == 1
        </li>
    </ul>
    """
    query = QuerySerializer(Query.get_latest_query_ready_for_new_matches(),
                            many=False).data
    if 'id' in query:
        return JsonResponse(_get_base_state_entity(query))
    else:
        return Response("No new queries were found.",
                        status=status.HTTP_204_NO_CONTENT)
def compute_finalized_state(request):
    """ GET - Get query state that represents a query ready to be finalized
    <ul>
        <li>Polled by broker in algorithm project.</li>
        <li>
            <a href="https://github.com/PARC-projects/video-query-api/blob/master/src/queries/models/process_state.py">
                Processing State
            </a> == 6
        </li>
    </ul>
    """
    query = QuerySerializer(Query.get_latest_query_ready_for_finalize(),
                            many=False).data
    if 'id' in query:
        base = _get_base_state_entity(query)
        base.update(_get_revision_update(query))
        return JsonResponse(base)
    else:
        return Response("No queries to be finalized were found.",
                        status=status.HTTP_204_NO_CONTENT)
Exemple #7
0
def prepop_queries(user):
    user = get_default_user()
    for t in Tag.objects.all():
        q = Query(name=t.descr,proximity=5,value=5,score=5,price=5,visited=False,deal=False,networked=False,text="",creator=user,is_default=True)
        q.save()
Exemple #8
0
def add_query(request):
    try:
        user = authenticate_api_request(request)
        authorize_user(user, request, "add")
        query = Query()
        query.name = get_json_post_or_error('queryName',request)
        query.creator = user#get_json_or_error('queryName',request)
        query.proximity = get_json_post_or_error('proximityWeight',request)
        query.price = get_json_post_or_error('priceWeight',request)
        query.value = get_json_post_or_error('valueWeight',request)
        query.score = get_json_post_or_error('scoreWeight',request)
        query.userHasVisited = get_json_post_or_error('userHasVisited',request)
        query.text = get_json_post_or_error('searchText',request)
        query.networked = get_json_post_or_error('networked',request)
        query.deal = get_json_post_or_error('deal',request)
        query.is_default = False# get_json_or_error('deal',request)
        query.save()
        if 'queryTags' not in request.POST:
            return server_error("Categories did not provide a list")
        categoryList = request.POST.getlist('queryCategories')
        for c in categoryList:
            if Tag.objects.filter(id=c).count() == 0:
                return server_error("Invalid Category provided")
            cat = Tag.objects.get(id=c)
            QueryTag.objects.create(query=query,tag=cat)
    except ReadJSONError as e:
        return server_error(e.value)
    except (AuthenticationFailed, AuthorizationError) as e:
        return server_error(e.value)
    except:
        return server_error("Could not save the object")
    data = get_query_data(query,user)
    return server_data(data)