示例#1
0
文件: api_v1.py 项目: DOAJ/doaj
    # get the data from the request
    try:
        data = json.loads(request.data)
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    a = ApplicationsCrudApi.create(data, current_user._get_current_object())

    # respond with a suitable Created response
    return created(a, url_for("api_v1.retrieve_application", application_id=a.id))


@blueprint.route("/applications/<application_id>", methods=["GET"])
@api_key_required
@swag(swag_summary='Retrieve an application <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsCrudApi.retrieve_swag())  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
def retrieve_application(application_id):
    a = ApplicationsCrudApi.retrieve(application_id, current_user)
    return jsonify_models(a)


@blueprint.route("/applications/<application_id>", methods=["PUT"])
@api_key_required
@write_required(api=True)
@swag(swag_summary='Update an application <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsCrudApi.update_swag())  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
def update_application(application_id):
    # get the data from the request
    try:
        data = json.loads(request.data)
    except:
        raise Api400Error("Supplied data was not valid JSON")
示例#2
0
    # get the data from the request
    try:
        data = json.loads(request.data.decode("utf-8"))
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    a = ApplicationsCrudApi.create(data, current_user._get_current_object())

    # respond with a suitable Created response
    return created(a, url_for("api_v1.retrieve_application", application_id=a.id))


@blueprint.route("/applications/<application_id>", methods=["GET"])
@api_key_required
@swag(swag_summary='Retrieve an application <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsCrudApi.retrieve_swag())  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
@analytics.sends_ga_event(GA_CATEGORY, GA_ACTIONS.get('retrieve_application', 'Retrieve application'), record_value_of_which_arg='application_id')
def retrieve_application(application_id):
    a = ApplicationsCrudApi.retrieve(application_id, current_user)
    return jsonify_models(a)


@blueprint.route("/applications/<application_id>", methods=["PUT"])
@api_key_required
@write_required(api=True)
@swag(swag_summary='Update an application <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsCrudApi.update_swag())  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
@analytics.sends_ga_event(GA_CATEGORY, GA_ACTIONS.get('update_application', 'Update application'), record_value_of_which_arg='application_id')
def update_application(application_id):
    # get the data from the request
    try:
        data = json.loads(request.data.decode("utf-8"))
示例#3
0
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    a = ApplicationsCrudApi.create(data, current_user._get_current_object())

    # respond with a suitable Created response
    return created(a,
                   url_for("api_v1.retrieve_application", application_id=a.id))


@blueprint.route("/applications/<application_id>", methods=["GET"])
@api_key_required
@swag(
    swag_summary=
    'Retrieve an application <span class="red">[Authenticated, not public]</span>',
    swag_spec=ApplicationsCrudApi.retrieve_swag()
)  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
def retrieve_application(application_id):
    a = ApplicationsCrudApi.retrieve(application_id, current_user)
    return jsonify_models(a)


@blueprint.route("/applications/<application_id>", methods=["PUT"])
@api_key_required
@write_required(api=True)
@swag(
    swag_summary=
    'Update an application <span class="red">[Authenticated, not public]</span>',
    swag_spec=ApplicationsCrudApi.update_swag()
)  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
def update_application(application_id):