コード例 #1
0
ファイル: model.py プロジェクト: NOAA-ORR-ERD/WebGnomeAPI
def get_model(request):
    '''
        Returns Model object in JSON.
        - This method varies slightly from the common object method in that
          if we don't specify a model ID, we:
          - return the current active model if it exists or...
          - return the specification.
    '''
    ret = None
    obj_id = obj_id_from_url(request)
    gnome_sema = request.registry.settings['py_gnome_semaphore']
    gnome_sema.acquire()

    try:
        if not obj_id:
            my_model = get_active_model(request)
            if my_model:
                ret = my_model.serialize()
            else:
                ret = get_specifications(request, implemented_types)
        else:
            obj = get_session_object(obj_id, request)
            if obj:
                if ObjectImplementsOneOf(obj, implemented_types):
                    set_active_model(request, obj.id)
                    ret = obj.serialize()
                else:
                    # we refer to an object, but it is not a Model
                    raise cors_exception(request, HTTPBadRequest)
            else:
                raise cors_exception(request, HTTPNotFound)
    finally:
        gnome_sema.release()

    return ret
コード例 #2
0
ファイル: model.py プロジェクト: govtmirror/WebGnomeAPI
def get_model(request):
    '''
        Returns Model object in JSON.
        - This method varies slightly from the common object method in that
          if we don't specify a model ID, we:
          - return the current active model if it exists or...
          - return the specification.
    '''
    ret = None
    obj_id = obj_id_from_url(request)
    gnome_sema = request.registry.settings['py_gnome_semaphore']
    gnome_sema.acquire()

    try:
        if not obj_id:
            my_model = get_active_model(request)
            if my_model:
                ret = my_model.serialize()
            else:
                ret = get_specifications(request, implemented_types)
        else:
            obj = get_session_object(obj_id, request)
            if obj:
                if ObjectImplementsOneOf(obj, implemented_types):
                    set_active_model(request, obj.id)
                    ret = obj.serialize()
                else:
                    # we refer to an object, but it is not a Model
                    raise cors_exception(request, HTTPBadRequest)
            else:
                raise cors_exception(request, HTTPNotFound)
    finally:
        gnome_sema.release()

    return ret
コード例 #3
0
ファイル: model.py プロジェクト: JamesMakela-NOAA/WebGnomeAPI
def get_model(request):
    '''
        Returns Model object in JSON.
        - This method varies slightly from the common object method in that
          if we don't specify a model ID, we:
          - return the current active model if it exists or...
          - return the specification.
    '''
    ret = None
    obj_id = obj_id_from_url(request)
    gnome_sema = request.registry.settings['py_gnome_semaphore']
    gnome_sema.acquire()

    if not obj_id:
        my_model = get_active_model(request.session)
        if my_model:
            ret = my_model.serialize()
        else:
            # - return a Model specification
            ret = get_specifications(request, implemented_types)
    else:
        obj = get_session_object(obj_id, request.session)
        if obj:
            if ObjectImplementsOneOf(obj, implemented_types):
                set_active_model(request.session, obj.id)
                ret = obj.serialize()
            else:
                raise HTTPUnsupportedMediaType()
        else:
            raise HTTPNotFound()

    gnome_sema.release()
    return ret