Beispiel #1
0
def key_list(request):
    '''
    For:
        GET /keys
        POST /keys
    '''
    api = API(request)
    api.authenticated_or_raise()
    if api.get:
        keys = Key.list_user(
            user=request.user
        )
        return api.respond(
            data=keys,
            paginate=True
        )
    elif api.post:
        key = Key.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=key
        )
    else:
        return api.raise_method_not_allowed()
Beispiel #2
0
def key_one(request, id):
    '''
    For:
        GET /keys/{id}
        PATCH /keys/{id}
        DELETE /keys/{id}
    '''
    api = API(request)
    api.authenticated_or_raise()
    if api.get:
        key = Key.read_one(
            id=id,
            user=request.user
        )
        return api.respond(
            data=key
        )
    elif api.patch:
        key = Key.update_one(
            id=id,
            user=request.user,
            data=api.data
        )
        return api.respond(
            data=key
        )
    elif api.delete:
        key = Key.delete_one(
            id=id,
            user=request.user
        )
        return api.respond()
    else:
        api.raise_method_not_allowed()