Exemplo n.º 1
0
def delete_user_blob(request):
    user = get_user_by_client_id(authenticated_userid(request))
    if user is None:
        request.response.status = HTTPUnauthorized.code
        return {'error': "Guests can not delete resources."}
    client_id = request.matchdict.get('client_id')
    object_id = request.matchdict.get('object_id')
    if user != get_user_by_client_id(client_id):
        request.response.status = HTTPForbidden.code
        return {'error': "That file doesn't belong to you."}
    blob = DBSession.query(UserBlobs).filter_by(client_id=client_id,
                                                object_id=object_id).first()
    if not blob:
        request.response.status = HTTPNotFound.code
        return {'error': 'No such blob in the system'}

    filelocation = blob.real_storage_path
    DBSession.delete(blob)
    request.response.status = HTTPOk.code
    try:
        os.unlink(filelocation)
    except:
        # NOTE: intentionally not an error
        return {
            "warning":
            "File can not be deleted physically; deleting from DMBS only."
        }
    return
Exemplo n.º 2
0
def convert_dictionary(request):  # TODO: test
    req = request.json_body
    args = dict()
    args['client_id'] = req['blob_client_id']
    args['object_id'] = req['blob_object_id']
    args['parent_client_id'] = req['parent_client_id']
    args['parent_object_id'] = req['parent_object_id']
    args['dictionary_client_id'] = req.get('dictionary_client_id')
    args['dictionary_object_id'] = req.get('dictionary_object_id')
    args['perspective_client_id'] = req.get('perspective_client_id')
    args['perspective_object_id'] = req.get('perspective_object_id')
    args['user_id'] = authenticated_userid(request)
    #import pdb
    #pdb.set_trace()
    #import time
    #time.sleep(1)
    task_id = QueueClient.generate_task_id(args['user_id'])
    res = async_convert_dictionary.delay(task_id=task_id, **args)
    log.debug("Conversion started")
    QueueClient.add_task(get_user_by_client_id(args['user_id']), task_id, res)
    request.response.status = HTTPOk.code
    return {
        "status":
        "Your dictionary is being converted."
        " Wait 5-15 minutes and you will see new dictionary in your dashboard."
    }
Exemplo n.º 3
0
def blob_upload_get(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    if user is None:
        response = Response()
        return HTTPFound(location=request.route_url('login'),
                         headers=response.headers)

    dictionary_client_id = request.matchdict.get('dictionary_client_id')
    dictionary_object_id = request.matchdict.get('dictionary_object_id')
    perspective_client_id = request.matchdict.get('perspective_client_id')
    perspective_object_id = request.matchdict.get('perspective_object_id')

    variables = {
        'client_id': client_id,
        'user': user,
        'dictionary_client_id': dictionary_client_id,
        'dictionary_object_id': dictionary_object_id,
        'perspective_client_id': perspective_client_id,
        'perspective_object_id': perspective_object_id
    }

    return render_to_response('templates/user_upload.pt',
                              variables,
                              request=request)
Exemplo n.º 4
0
def languages_get(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    if user is None:
        response = Response()
        return HTTPFound(location=request.route_url('login'), headers=response.headers)
    variables = {'client_id': client_id, 'user': user}
    return render_to_response('templates/languages.pt', variables, request=request)
Exemplo n.º 5
0
def test_queue_set(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    task_id = QueueClient.generate_task_id(client_id)
    res = test_queue_set_logic.delay(task_id)
    QueueClient.add_task(user, task_id, res)
    response = dict()
    request.response.status = HTTPOk.code
    return response
Exemplo n.º 6
0
def test_queue_set(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    task_id = QueueClient.generate_task_id(client_id)
    res = test_queue_set_logic.delay(task_id)
    QueueClient.add_task(user, task_id, res)
    response = dict()
    request.response.status = HTTPOk.code
    return response
Exemplo n.º 7
0
def languages_get(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    if user is None:
        response = Response()
        return HTTPFound(location=request.route_url('login'),
                         headers=response.headers)
    variables = {'client_id': client_id, 'user': user}
    return render_to_response('templates/languages.pt',
                              variables,
                              request=request)
Exemplo n.º 8
0
def delete_user_blob(request):
    user = get_user_by_client_id(authenticated_userid(request))
    if user is None:
        request.response.status = HTTPUnauthorized.code
        return {'error': "Guests can not delete resources."}
    client_id = request.matchdict.get('client_id')
    object_id = request.matchdict.get('object_id')
    if user != get_user_by_client_id(client_id):
        request.response.status = HTTPForbidden.code
        return {'error': "That file doesn't belong to you."}
    blob = DBSession.query(UserBlobs).filter_by(client_id=client_id, object_id=object_id).first()
    if not blob:
        request.response.status = HTTPNotFound.code
        return {'error': 'No such blob in the system'}

    filelocation = blob.real_storage_path
    DBSession.delete(blob)
    request.response.status = HTTPOk.code
    try:
        os.unlink(filelocation)
    except:
        # NOTE: intentionally not an error
        return {"warning": "File can not be deleted physically; deleting from DMBS only."}
    return
Exemplo n.º 9
0
def blob_upload_get(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    if user is None:
        response = Response()
        return HTTPFound(location=request.route_url('login'), headers=response.headers)

    dictionary_client_id = request.matchdict.get('dictionary_client_id')
    dictionary_object_id = request.matchdict.get('dictionary_object_id')
    perspective_client_id = request.matchdict.get('perspective_client_id')
    perspective_object_id = request.matchdict.get('perspective_object_id')

    variables = {'client_id': client_id, 'user': user, 'dictionary_client_id': dictionary_client_id,
                 'dictionary_object_id': dictionary_object_id, 'perspective_client_id': perspective_client_id,
                 'perspective_object_id': perspective_object_id}

    return render_to_response('templates/user_upload.pt', variables, request=request)
Exemplo n.º 10
0
def convert_dictionary(request):  # TODO: test
    req = request.json_body
    args = dict()
    args['client_id'] = req['blob_client_id']
    args['object_id'] = req['blob_object_id']
    args['parent_client_id'] = req['parent_client_id']
    args['parent_object_id'] = req['parent_object_id']
    args['dictionary_client_id'] = req.get('dictionary_client_id')
    args['dictionary_object_id'] = req.get('dictionary_object_id')
    args['perspective_client_id'] = req.get('perspective_client_id')
    args['perspective_object_id'] = req.get('perspective_object_id')
    args['user_id'] = authenticated_userid(request)
    #import pdb
    #pdb.set_trace()
    #import time
    #time.sleep(1)
    task_id = QueueClient.generate_task_id(args['user_id'])
    res = async_convert_dictionary.delay(task_id=task_id, **args)
    log.debug("Conversion started")
    QueueClient.add_task(get_user_by_client_id(args['user_id']), task_id, res)
    request.response.status = HTTPOk.code
    return {"status": "Your dictionary is being converted."
                      " Wait 5-15 minutes and you will see new dictionary in your dashboard."}
Exemplo n.º 11
0
def test_queue_get(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    res = QueueClient.get_tasks_info(user)
    request.response.status = HTTPOk.code
    return res
Exemplo n.º 12
0
def main_get(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    variables = {'client_id': client_id, 'user': user}
    return render_to_response('templates/main.pt', variables, request=request)
Exemplo n.º 13
0
def test_queue_get(request):
    client_id = authenticated_userid(request)
    user = get_user_by_client_id(client_id)
    res = QueueClient.get_tasks_info(user)
    request.response.status = HTTPOk.code
    return res