Example #1
0
class BResource(RestResource):
    include_resources = {'a': AResource}

class CResource(RestResource):
    include_resources = {'b': BResource}

class EResource(RestResource):
    pass

class FResource(RestResource):
    include_resources = {'e': EResource}

# rest api stuff
dummy_auth = Authentication(protected_methods=[])
user_auth = UserAuthentication(auth)
admin_auth = AdminAuthentication(auth)
api_key_auth = APIKeyAuthentication(APIKey, ['GET', 'POST', 'PUT', 'DELETE'])

api = RestAPI(app, default_auth=user_auth)

api.register(Message, RestrictOwnerResource)
api.register(User, UserResource, auth=admin_auth)
api.register(Note)
api.register(TestModel, auth=api_key_auth)
api.register(AModel, AResource, auth=dummy_auth)
api.register(BModel, BResource, auth=dummy_auth)
api.register(CModel, CResource, auth=dummy_auth)

api.register(EModel, EResource, auth=dummy_auth)
api.register(FModel, FResource, auth=dummy_auth)
Example #2
0
# -*- coding: utf-8 -*-
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication, AdminAuthentication

from app import app
from auth import auth
from models import User

user_auth = UserAuthentication(auth)
admin_auth = AdminAuthentication(
    auth, protected_methods=['GET', 'POST', 'PUT', 'DELETE'])

api = RestAPI(app, default_auth=user_auth)


class UserResource(RestResource):
    exclude = (
        'password',
        'email',
    )


api.register(User, UserResource, auth=admin_auth, allowed_methods=['GET'])
api.setup()