Пример #1
0
def create_connector(request, project_id=None):
    query_parameters = {}
    default_values = {'x': 0, 'y': 0, 'z': 0, 'confidence': 5}
    for p in default_values.keys():
        query_parameters[p] = request.POST.get(p, default_values[p])

    parsed_confidence = int(query_parameters['confidence'])
    if parsed_confidence < 1 or parsed_confidence > 5:
        return HttpResponse(json.dumps({'error': 'Confidence not in range 1-5 inclusive.'}))

    new_connector = Connector(
        user=request.user,
        editor=request.user,
        project=Project.objects.get(id=project_id),
        location_x=float(query_parameters['x']),
        location_y=float(query_parameters['y']),
        location_z=float(query_parameters['z']),
        confidence=parsed_confidence)
    new_connector.save()

    return HttpResponse(json.dumps({'connector_id': new_connector.id}))
Пример #2
0
def create_connector(request, project_id=None):
    query_parameters = {}
    default_values = {'x': 0, 'y': 0, 'z': 0, 'confidence': 5}
    for p in default_values.keys():
        query_parameters[p] = request.POST.get(p, default_values[p])

    parsed_confidence = int(query_parameters['confidence'])
    if parsed_confidence < 1 or parsed_confidence > 5:
        return HttpResponse(
            json.dumps({'error': 'Confidence not in range 1-5 inclusive.'}))

    new_connector = Connector(user=request.user,
                              editor=request.user,
                              project=Project.objects.get(id=project_id),
                              location_x=float(query_parameters['x']),
                              location_y=float(query_parameters['y']),
                              location_z=float(query_parameters['z']),
                              confidence=parsed_confidence)
    new_connector.save()

    return HttpResponse(json.dumps({'connector_id': new_connector.id}))
Пример #3
0
def create_connector(request, project_id=None):
    query_parameters = {}
    default_values = {'x': 0, 'y': 0, 'z': 0, 'confidence': 5}
    for p in default_values.keys():
        query_parameters[p] = request.POST.get(p, default_values[p])

    project_id = int(project_id)

    parsed_confidence = int(query_parameters['confidence'])
    if parsed_confidence < 1 or parsed_confidence > 5:
        return HttpResponse(
            json.dumps({'error': 'Confidence not in range 1-5 inclusive.'}))

    cursor = connection.cursor()

    # Get optional initial links to connectors, expect each entry to be a list
    # of connector ID, relation ID and confidence.
    links = get_request_list(request.POST, 'links', [], map_fn=int)

    new_connector = Connector(user=request.user,
                              editor=request.user,
                              project=Project.objects.get(id=project_id),
                              location_x=float(query_parameters['x']),
                              location_y=float(query_parameters['y']),
                              location_z=float(query_parameters['z']),
                              confidence=parsed_confidence)
    new_connector.save()

    # Create all initial links
    if links:
        created_links = create_treenode_links(project_id, request.user.id,
                                              new_connector.id, links, cursor)
    else:
        created_links = []

    return JsonResponse({
        'connector_id': new_connector.id,
        'connector_edition_time': new_connector.edition_time,
        'created_links': created_links
    })
Пример #4
0
def create_connector(request, project_id=None):
    query_parameters = {}
    default_values = {'x': 0, 'y': 0, 'z': 0, 'confidence': 5}
    for p in default_values.keys():
        query_parameters[p] = request.POST.get(p, default_values[p])

    project_id = int(project_id)

    parsed_confidence = int(query_parameters['confidence'])
    if parsed_confidence < 1 or parsed_confidence > 5:
        return HttpResponse(json.dumps({'error': 'Confidence not in range 1-5 inclusive.'}))

    cursor = connection.cursor()

    # Get optional initial links to connectors, expect each entry to be a list
    # of connector ID, relation ID and confidence.
    links = get_request_list(request.POST, 'links', [], map_fn=int)

    new_connector = Connector(
        user=request.user,
        editor=request.user,
        project=Project.objects.get(id=project_id),
        location_x=float(query_parameters['x']),
        location_y=float(query_parameters['y']),
        location_z=float(query_parameters['z']),
        confidence=parsed_confidence)
    new_connector.save()

    # Create all initial links
    if links:
        created_links = create_treenode_links(project_id, request.user.id,
                new_connector.id, links, cursor)
    else:
        created_links = []

    return JsonResponse({
        'connector_id': new_connector.id,
        'connector_edition_time': new_connector.edition_time,
        'created_links': created_links
    })