コード例 #1
0
ファイル: views.py プロジェクト: stencila/hub
def address_one(request, id):
    '''
    For:
        GET /addresses/{id}
        PATCH /addresses/{id}
        DELETE /addresses/{id}
    '''
    api = API(request)
    api.authenticated_or_raise()
    if api.get:
        address = Address.read_one(
            id=id,
            user=request.user
        )
        return api.respond(
            data=address
        )
    elif api.patch:
        address = Address.update_one(
            id=id,
            user=request.user,
            data=api.data
        )
        return api.respond(
            data=address
        )
    elif api.delete:
        address = Address.delete_one(
            id=id,
            user=request.user
        )
        return api.respond()
    else:
        api.raise_method_not_allowed()
コード例 #2
0
ファイル: views.py プロジェクト: stencila/hub
def address_list(request):
    '''
    For:
        GET /addresses
        POST /addresses
    '''
    api = API(request)
    api.authenticated_or_raise()
    if api.get:
        addresses = Address.list(
            user=request.user
        )
        return api.respond(
            data=addresses,
            paginate=100
        )
    elif api.post:
        address = Address.create_one(
            user=request.user,
            address=api.required('address'),
            type=api.required('type'),
            action=api.required('action'),
            users=api.required('users')
        )
        return api.respond(
            data=address
        )
    else:
        return api.raise_method_not_allowed()