Exemplo n.º 1
0
def create_map(request):
    '''Creates a Gnome Map object.'''
    init_session_objects(request.session)
    try:
        json_request = json.loads(request.body)
    except:
        raise HTTPBadRequest()

    if not JSONImplementsOneOf(json_request, implemented_types):
        raise HTTPNotImplemented()

    # TODO: should we tie our data directory to the installation path?
    #       or should we be more flexible?
    map_dir = get_map_dir_from_config(request)
    json_request['filename'] = os.path.join(map_dir, json_request['filename'])

    obj = CreateObject(json_request, request.session['objects'])

    set_session_object(obj, request.session)
    return obj.serialize()
Exemplo n.º 2
0
def create_model(request):
    '''
        Creates a new model
    '''
    log_prefix = 'req({0}): create_object():'.format(id(request))
    print '>>', log_prefix

    try:
        json_request = json.loads(request.body)
    except:
        json_request = None

    if json_request and not JSONImplementsOneOf(json_request,
                                                implemented_types):
        raise HTTPNotImplemented()

    gnome_sema = request.registry.settings['py_gnome_semaphore']
    gnome_sema.acquire()
    print '  ', log_prefix, 'semaphore acquired...'

    try:
        init_session_objects(request.session, force=True)
        if json_request:
            new_model = CreateObject(json_request,
                                     get_session_objects(request.session))
        else:
            new_model = Model()
        set_session_object(new_model, request.session)
        set_session_object(new_model._map, request.session)
        set_active_model(request.session, new_model.id)
    finally:
        gnome_sema.release()
        print '  ', log_prefix, 'semaphore released...'

    print '<<', log_prefix
    return new_model.serialize()