本文整理汇总了Python中flask_peewee.rest.RestAPI.register方法的典型用法代码示例。如果您正苦于以下问题:Python RestAPI.register方法的具体用法?Python RestAPI.register怎么用?Python RestAPI.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_peewee.rest.RestAPI
的用法示例。
在下文中一共展示了RestAPI.register方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_api
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
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
示例2: initialize
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
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()
示例3: UserResource
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
admin.register(Note, NoteAdmin)
admin.register(User, UserAdmin)
auth.register_admin(admin)
admin.setup()
class UserResource(RestResource):
exclude = ("password", "email")
class NoteResource(RestrictOwnerResource):
owner_field = "user"
user_auth = UserAuthentication(auth)
admin_auth = AdminAuthentication(auth)
api = RestAPI(app, default_auth=user_auth)
api.register(User, UserResource, auth=admin_auth)
api.register(Note, NoteResource)
api.setup()
@app.route("/version")
def version():
return "2.1"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=app.config["PORT"])
示例4: Admin
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
return self.model.select()
admin = Admin(app, auth)
admin.register(Contents, ContentsAdmin)
admin.setup()
# instantiate the user auth
user_auth = UserAuthentication(auth)
admin_auth = AdminAuthentication(auth)
# create a RestAPI container
api = RestAPI(app, default_auth=user_auth)
#register the Content model
api.register(Contents, ContentsResource, auth=admin_auth)
api.setup()
# customize template tag
def date_now(value):
return datetime.datetime.now().strftime(value).decode('utf-8')
app.jinja_env.filters['date_now'] = date_now
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.errorhandler(404)
def page_not_found(e):
示例5: Flask
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
break
print "yrs"
a['type'] = obj_type
a['id'] = a[obj_type+'ID']
a['text'] = a[obj_type]
print "end"
r.append(a)
return r
app = Flask(__name__)
class SubjectsResource(RestResource):
paginate_by = 200
api = RestAPI(app)
api.register(Departments, SubjectsResource)
api.register(Courses)
api.register(Subjects, SubjectsResource)
api.register(Colleges, SubjectsResource)
api.setup()
@app.route('/')
def index():
return render_template('latech.html',
require=url_for('static', filename='require.min.js'),
js=url_for('static', filename='latech.js'),
css=url_for('static', filename='latech.css'),
mainjs=url_for('static', filename='main.js'))
示例6: UserAuthentication
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
__author__ = 'ajboehmler'
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication
from app import app
from auth import auth
from models import User
user_auth = UserAuthentication(auth)
# instantiate our api wrapper and tell it to use HTTP basic auth using
# the same credentials as our auth system. If you prefer this could
# instead be a key-based auth, or god forbid some open auth protocol.
api = RestAPI(app, default_auth=user_auth)
class UserResource(RestResource):
exclude = ('password', 'email',)
# register our models so they are exposed via /api/<model>/
api.register(User, UserResource, auth=user_auth)
示例7: UserResource
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
# 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)
示例8: UserResource
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
'''
Modulo gestione chiamate Restful
Es.: http://localhost:8080/api/relay/
'''
from app import app
from auth import auth
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication, \
AdminAuthentication
from models import User, Relay
class UserResource(RestResource):
'''
Gestione risorse User
Consente di configurare i campi esportati nel json
'''
exclude = ('password', 'email',)
"Configura Authenticator per User e Admin"
user_auth = UserAuthentication(auth)
admin_auth = AdminAuthentication(auth)
"Crea oggetto API per la gestione delle chiamate Restful"
api = RestAPI(app, default_auth=user_auth)
"Registra Modelli"
api.register(User, UserResource, auth=admin_auth)
api.register(Relay)
示例9: ForeignKeyField
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
user = ForeignKeyField(auth.User, related_name='gifts')
item = ForeignKeyField(Item, related_name='parts')
# admin part
admin = Admin(app, auth)
admin.register(WishList)
admin.register(Item)
admin.register(Part)
# api part
user_auth = UserAuthentication(auth)
api = RestAPI(app, default_auth=user_auth)
api.register(WishList)
api.register(Item, ItemResource)
api.register(Part)
# setup
admin.setup()
api.setup()
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
auth.User.create_table(fail_silently=True)
WishList.create_table(fail_silently=True)
Item.create_table(fail_silently=True)
示例10: CarBrandResource
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
'city': CityResource,
}
class CarBrandResource(RestResource):
exclude = ()
class CarSeriesResource(RestResource):
exclude = ()
owner_field = 'brand'
include_resources = {
'brand': CarBrandResource,
}
class CarModelResource(RestResource):
exclude = ()
owner_field = 'series'
include_resources = {
'series': CarSeriesResource,
}
# register our models so they are exposed via /api/<model>/
api.register(User, UserResource, auth=admin_auth)
api.register(Relationship, RelationshipResource)
api.register(Message, MessageResource)
api.register(City, CityResource)
api.register(Pinche, PincheResource)
api.register(CarBrand, CarBrandResource)
api.register(CarSeries, CarSeriesResource)
api.register(CarModel, CarModelResource)
示例11: UserAuthentication
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
# -*- coding: utf-8 -*-
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication
from web.app import app, auth
from web.model import Label, Inspiration, LabelInspirationRelationShip
user_auth = UserAuthentication(auth)
api = RestAPI(app, default_auth=user_auth)
class InspirationResource(RestResource):
def prepare_data(self, obj, data):
data["labels"] = [l.to_json() for l in obj.labels]
return data
api.register(Inspiration, InspirationResource)
class LabelInspirationRelationShipResource(RestResource):
paginate_by = 200
def prepare_data(self, obj, data):
inspiration_id = data["inspiration"]
inspiration = Inspiration.select().where(Inspiration.id == inspiration_id).first()
data["inspiration"] = inspiration.to_json()
return data
api.register(LabelInspirationRelationShip, LabelInspirationRelationShipResource)
# setup user
register_class = [Label, auth.User]
for klass in register_class:
api.register(klass)
示例12: Authentication
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
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)
示例13: UserAuthentication
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
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)
示例14: Admin
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
demo.set_password("sonata")
demo.save()
admin = Admin(app, auth)
admin.register(User)
admin.register(Serie)
admin.register(Fansub)
admin.register(ScrapParam)
admin.register(ScrapParamTemplate)
admin.register(Notification)
admin.setup()
# register our models so they are exposed via /api/<model>/
api.register(User)
api.register(Serie)
api.register(Fansub)
api.register(ScrapParam)
api.register(Notification, NotificationResource)
# configure the urls
api.setup()
# HTTP error handling
@app.errorhandler(404)
def not_found(error):
return "404: Not Found.", 404
@app.route("/")
示例15: Flask
# 需要导入模块: from flask_peewee.rest import RestAPI [as 别名]
# 或者: from flask_peewee.rest.RestAPI import register [as 别名]
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)