本文整理汇总了Python中flask_peewee.rest.RestAPI类的典型用法代码示例。如果您正苦于以下问题:Python RestAPI类的具体用法?Python RestAPI怎么用?Python RestAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RestAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
def initialize():
global db, api
db = Database(app)
# Setup models
import models
models.setup()
# Register REST api
api = RestAPI(app)
api.register(models.Flow)
api.setup()
示例2: setup_api
def setup_api(auth):
user_auth = UserAuthentication(auth)
api = RestAPI(app, default_auth=user_auth)
api.register(Note)
api.register(Author)
api.setup()
return api
示例3: UserAuthentication
from flask_peewee.rest import RestAPI, UserAuthentication
from app import app
from auth import auth
from models import Note
user_auth = UserAuthentication(auth)
api = RestAPI(app, default_auth=user_auth)
api.register(Note)
api.setup()
示例4: SessionAuthResource
class SessionAuthResource(RestResource):
def authorize(self):
return True
# return session.get('magic', '') == 'a'
class ScriptResource(SessionAuthResource):
pass
class ReportResource(SessionAuthResource):
paginate_by = 100
def get_query(self):
if request.args.get('method', '') == "listURI":
# monkey patch fields
self._fields = {self.model: ['latest', 'count', 'uri']}
return Report.select(Report.uri, fn.Count(Report.id).alias(
'count'), fn.Max(Report.created).alias('latest')).group_by(
Report.uri).order_by(fn.Max(Report.created).desc())
else:
self._fields = {self.model: self.model._meta.get_field_names()}
return SessionAuthResource.get_query(self)
api = RestAPI(app)
api.register(Report, ReportResource)
api.register(Script, ScriptResource)
api.setup()
示例5: UserAuthentication
from flask_peewee.rest import RestAPI, UserAuthentication
from psyc import app
#from models.models import Note
import psyc.models.processor as processor
from auth import auth
user_auth = UserAuthentication(auth)
api = RestAPI(app, default_auth=user_auth)
#api.register(processor.Processor, processor.ProcessorResource)
api.setup()
示例6: UserAuthentication
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication, AdminAuthentication, RestrictOwnerResource
from app import app
from auth import auth
from models import User, Message, Relationship, City, Pinche
user_auth = UserAuthentication(auth)
admin_auth = AdminAuthentication(auth)
# instantiate our api wrapper
api = RestAPI(app, default_auth=user_auth)
class UserResource(RestResource):
exclude = ('password', 'email',)
class MessageResource(RestrictOwnerResource):
owner_field = 'user'
include_resources = {'user': UserResource}
class RelationshipResource(RestrictOwnerResource):
owner_field = 'from_user'
include_resources = {
'from_user': UserResource,
'to_user': UserResource,
}
paginate_by = None
class CityResource(RestResource):
exclude = ()
示例7: RestAPI
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication, AdminAuthentication, RestrictOwnerResource
from app import app
from auth import auth
from models import Councillor, Promise, Decision, Comment
api = RestAPI(app)
admin_auth = AdminAuthentication(auth)
class CantonResource(RestResource):
exclude = ()
class CouncilResource(RestResource):
exclude = ()
class PartyResource(RestResource):
exclude = ()
class CouncillorResource(RestResource):
include_resources = {
'canton': CantonResource,
'council': CouncilResource,
'party': PartyResource,
}
class PromiseResource(RestResource):
include_resources = {
'councillor': CouncillorResource
}
class DecisionResource(RestResource):
示例8: UserResource
admin.register_panel('Notes', NotePanel)
class UserResource(RestResource):
exclude = ('password', 'email',)
def get_query(self):
return User.filter(active=True)
# rest api stuff
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)
# views
@app.route('/')
def homepage():
return Response()
@app.route('/private/')
@auth.login_required
def private_timeline():
示例9: UserAuthentication
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication, AdminAuthentication, RestrictOwnerResource
from app import app
from auth import auth
from models import User, Message, Relationship, City, Pinche
from models import CarBrand, CarSeries, CarModel
user_auth = UserAuthentication(auth)
admin_auth = AdminAuthentication(auth)
# instantiate our api wrapper
api = RestAPI(app, default_auth=user_auth)
class UserResource(RestResource):
exclude = ('password', 'email',)
class MessageResource(RestrictOwnerResource):
owner_field = 'user'
include_resources = {'user': UserResource}
class RelationshipResource(RestrictOwnerResource):
owner_field = 'from_user'
include_resources = {
'from_user': UserResource,
'to_user': UserResource,
}
paginate_by = None
class CityResource(RestResource):
exclude = ()
示例10: UserAuthentication
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication, AdminAuthentication, RestrictOwnerResource
from app import app
from auth import auth
from models import User, Message#, Relationship
user_auth = UserAuthentication(auth)
admin_auth = AdminAuthentication(auth)
# instantiate our api wrapper
api = RestAPI(app, default_auth=user_auth)
class UserResource(RestResource):
exclude = ('password', 'email',)
class MessageResource(RestrictOwnerResource):
owner_field = 'user'
include_resources = {'user': UserResource}
# register our models so they are exposed via /api/<model>/
api.register(User, UserResource, auth=admin_auth)
api.register(Message, MessageResource)
示例11: Authentication
from flask import render_template
from flask_peewee.rest import Authentication
from flask_peewee.rest import RestAPI
from flask_peewee.rest import RestResource
from app import app
from models import Note
from models import Task
# Allow GET and POST requests without requiring authentication.
auth = Authentication(protected_methods=['PUT', 'DELETE'])
api = RestAPI(app, default_auth=auth)
class NoteResource(RestResource):
fields = ('id', 'content', 'timestamp', 'status')
paginate_by = 30
def get_query(self):
return Note.public()
def prepare_data(self, obj, data):
data['rendered'] = render_template('note.html', note=obj)
return data
class TaskResource(RestResource):
paginate_by = 50
api.register(Note, NoteResource)
api.register(Task, TaskResource)
示例12: Flask
from rui.series.model import Fansub
from rui.series.model import ScrapParam
from rui.series.model import ScrapParamTemplate
from rui.series.model import Notification
from rui.series.model import db
from rui.config import data as dataConfig
from rui.series.resources import NotificationResource
# Define the WSGI application object
app = Flask(__name__)
app.config["DATABASE"] = {"name": dataConfig["path"], "engine": "peewee.SqliteDatabase"}
app.config["SECRET_KEY"] = '?\xbf,\xb4\x8d\xa3"<\x9c\[email protected]\x0f5\xab,w\xee\x8d$0\x13\x8b83'
# instantiate our api wrapper
api = RestAPI(app)
# Admin area
db = Database(app)
# needed for authentication
auth = Auth(app, db)
# auth.User.create_table(fail_silently=True)
demo = auth.User(username="demo", email="", admin=True, active=True)
demo.set_password("sonata")
demo.save()
admin = Admin(app, auth)
示例13: Flask
from flask import Flask
from flask_peewee.rest import RestAPI
import models
app = Flask(__name__)
# instantiate our api wrapper
api = RestAPI(app)
# register our models so they are exposed via /api/<model>/
api.register(models.Article)
# configure the urls
api.setup()
if __name__ == '__main__':
app.run(debug=True)
示例14: RestAPI
from flask_peewee.rest import RestAPI, RestResource
from app import app
from customer import Customer
from product import Product
api = RestAPI(app)
api.register(Customer)
api.register(Product)
api.setup()
示例15: UserResource
# create a special resource for users that excludes email and password
class UserResource(RestResource):
exclude = ('password', 'email',)
# class LogrefillResource(RestResource):
# def prepare_data(self, obj, data):
# data["credit"] = str(data["credit"])
# return data
# instantiate the user auth
user_auth = UserAuthentication(auth, protected_methods=['GET', 'POST', 'PUT', 'DELETE'])
# create a RestAPI container
api = RestAPI(app, default_auth=user_auth)
# register the models
api.register(Card, CardResource, auth=user_auth)
api.register(CardGroup, auth=user_auth)
api.register(Callerid, auth=user_auth)
api.register(Logrefill, auth=user_auth)
api.register(Logpayment, auth=user_auth)
api.register(Call, auth=user_auth)
api.register(Country, auth=user_auth)
api.register(Charge, auth=user_auth)
# api.register(Did, auth=user_auth)
# api.register(DidDestination, auth=user_auth)
api.register(auth.User, UserResource, auth=user_auth)