예제 #1
0
def create_app(config=None):
    app = Flask(__name__)

    if config:
        app.config.from_object(config)
    else:
        app.config.from_object(os.environ['APP_SETTINGS'])

    handler = RotatingFileHandler(app.config['LOGGING_LOCATION'],
                                  maxBytes=10000,
                                  backupCount=1)

    from app.home.views import home
    app.register_blueprint(home)

    from app.song.api import songsearch
    app.register_blueprint(songsearch)

    from app.song.api import SongAPI, SongsAPI
    api.add_resource(SongAPI, '/api/song')
    api.add_resource(SongsAPI, '/api/songs')

    from app.playlist.api import PlaylistAPI, PlaylistsAPI, PlaylistSongAPI
    api.add_resource(PlaylistAPI, '/api/playlist')
    api.add_resource(PlaylistsAPI, '/api/playlists')
    api.add_resource(PlaylistSongAPI, '/api/playlist/<int:playlist_id>/song',
                     '/api/playlist/<int:playlist_id>/songs')

    api.init_app(app)
    db.init_app(app)

    return app
예제 #2
0
def create_app(config=None):

    app = Flask(__name__)

    if config:
        app.config.from_object(config)
    else:
        app.config.from_object(os.environ['APP_SETTINGS'])

    # Init logger
    handler = RotatingFileHandler(app.config['LOGGING_LOCATION'],
                                  maxBytes=10000,
                                  backupCount=1)
    handler.setLevel(app.config['LOGGING_LEVEL'])
    app.logger.addHandler(handler)

    # Init routes
    from app.home.views import home
    app.register_blueprint(home)

    from app.home.api import TestApi
    api.add_resource(TestApi, '/api/protected')

    from app.user.api import UserApi
    api.add_resource(UserApi, '/api/user/register')

    # Init extensions
    db.init_app(app)
    api.init_app(app)
    bcrypt.init_app(app)

    from app.user.auth import authenticate, identity, payload_handler
    jwt.authentication_handler(authenticate)
    jwt.identity_handler(identity)
    jwt.jwt_payload_handler(payload_handler)
    jwt.init_app(app)

    return app
예제 #3
0
def create_app(config=None):
    
    app = Flask(__name__)

    if config:
        app.config.from_object(config)
    else:
        app.config.from_object(os.environ['APP_SETTINGS'])

    # Init logger
    handler = RotatingFileHandler(app.config['LOGGING_LOCATION'], maxBytes=10000, backupCount=1)
    handler.setLevel(app.config['LOGGING_LEVEL'])
    app.logger.addHandler(handler)

    # Init routes
    from app.home.views import home
    app.register_blueprint(home)

    from app.home.api import TestApi
    api.add_resource(TestApi, '/api/protected')

    from app.user.api import UserApi
    api.add_resource(UserApi, '/api/user/register')

    # Init extensions
    db.init_app(app)
    api.init_app(app)
    bcrypt.init_app(app)

    from app.user.auth import authenticate, identity, payload_handler
    jwt.authentication_handler(authenticate)
    jwt.identity_handler(identity)
    jwt.jwt_payload_handler(payload_handler)
    jwt.init_app(app)

    return app
예제 #4
0
def register_routes():
    api.add_resource(UserListController, '/users')
    api.add_resource(UserController, '/users/<uuid>')
    api.add_resource(LoginController, '/login')
예제 #5
0
def initialize_routes(api):
    api.add_resource(SignupApi, '/api/v1.0/auth/signup/')
    api.add_resource(LoginApi, '/api/v1.0/auth/login/')
    api.add_resource(UserApi, '/api/v1.0/users/<int:user_id>/')
    api.add_resource(ProfileApi, '/api/v1.0/profiles/<int:user_id>/')
    api.add_resource(ChatsApi, '/api/v1.0/chats/')
    api.add_resource(ChatApi, '/api/v1.0/chats/<int:chat_id>/')
    return None
예제 #6
0
# -*- coding:utf-8 -*-
'''
@Time    : 2018/8/7 9:10
@Author  : Fate
@File    : __init__.py.py api
'''

from app.extensions import api
from .cityResource import CityResource
from .userResource import UserResource, ActivationResource, PermissionResource
from .movieResurce import MovieResource
from .cinemaResource import CinemaResource

# 添加城市资源
api.add_resource(CityResource, '/city/')
# 用户
api.add_resource(UserResource, '/user/')
# 激活
api.add_resource(ActivationResource, '/activation/')
# 权限
api.add_resource(PermissionResource, '/permission/')
# 电影
api.add_resource(MovieResource, '/movies/')
# 影院
api.add_resource(CinemaResource, '/cinema/')
예제 #7
0
 def register_controller(controller, url):
     api.add_resource(controller, url, '{}/<string:action>'.format(url))
예제 #8
0
                db.session.commit()
                res = user_schema.dump([new_data])
                return jsonify(res)
        except:
            abort(404, message="Can't add new user.")

    def post(self):
        res = {'user':'', 'login':'******', 'level':''}
        if len(request.json)>0:
            user = User.query.filter_by(**request.json).first()
            if user:
                res['user'] = user.name
                res['login'] = '******'
                res['level'] = user.level
        return jsonify(res)

    def delete(self):
        try:
            if request.json['key'] == KEY:
                name = request.json['name']
                data = User.query.filter_by(name=name).first()
                if data and data.pwd == request.json['pwd']:
                    db.session.delete(data)
                    db.session.commit()
                    res = user_schema.dump([data])
                    return jsonify(res)
        except:
            abort(404, message="Can't delete user.")

api.add_resource(UserAPI, '/api/users', endpoint = 'users')
예제 #9
0
        print(args)
        email = args.get('email')
        username = args.get('username')
        password = str(args.get('password'))
        users = User.query.filter_by(username=username)

        if User.query.filter_by(
                username=username).first() or User.query.filter_by(
                    email=email).first():
            data = {
                'msg': '用户名已存在',
                'status': 400,
                # 'data': {},
            }
            return data
        user = User(email=email,
                    username=username,
                    password=User().set_password(password))
        db.session.add(user)
        db.session.commit()
        data = {
            'msg': 'ok',
            'status': 201,
            'data': user,
        }
        return data


api.add_resource(UserListApi, '/user')
api.add_resource(UserAPi, '/user/<int:id>')
예제 #10
0
        for pos in db.session.query(DetailFkModel).filter_by(
                exp_geohash=id).all():
            # for pos in db.session.query(BasePickupDetail).filter_by(exp_geohash=id).all():
            recomms.append({
                "id": pos.id,
                "lat": float(pos.lat),
                "lng": float(pos.lng),
                "name": pos.name,
                "score": pos.score,
                "count": pos.count,
                "tag": pos.tag,
                "ext": pos.ext
            })
        log.debug("recomm size={s} -> {d}".format(s=len(recomms), d=recomms))

        out = {
            "geohash": id,
            "city": city,
            "regeo": info.regeo,
            "radius": info.radius,
            "num": info.num,
            "recomms": recomms,
            "create_time": int(info.create_time),
            "update_time": int(info.update_time)
        }

        return jsonify(out)


api.add_resource(recomms, '/recomms', endpoint="recomms")
예제 #11
0
    def post(self):
        name = request.form.get('name')
        price = request.form.get('price')
        product = Product(name, price)
        db.session.add(product)
        db.session.commit()
        return jsonify({
            product.id: {
                'name': product.name,
                'price': str(product.price),
            }
        })

    def put(self, id):
        # Update the record for the provided id
        # with the details provided.
        return

    def delete(self, id):

        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400

        # Delete the record for the provided id.
        return


api.add_resource(StickyNotes, '/api/v1/', endpoint='main')
api.add_resource(StickyNotes, '/api/v1/<int:id>', endpoint='main')
예제 #12
0
    def delete(self, todo_id):
        abort_if_todo_doesnt_exist(todo_id)
        del TODOS[todo_id]
        return '', 204

    def put(self, todo_id):
        args = parser.parse_args()
        task = {'task': args['task']}
        TODOS[todo_id] = task
        return task, 201


# TodoList
#   shows a list of all todos, and lets you POST to add new tasks
class TodoList(Resource):
    def get(self):
        return TODOS

    def post(self):
        args = parser.parse_args()
        todo_id = 'todo%d' % (len(TODOS) + 1)
        TODOS[todo_id] = {'task': args['task']}
        return TODOS[todo_id], 201


##
## Actually setup the Api resource routing here
##
api.add_resource(TodoList, '/todos')
api.add_resource(Todo, '/todos/<string:todo_id>')
예제 #13
0
from app.extensions import api
from .repositorios_routes import (RepositorioResource, RepositorioListResource)

api.add_resource(RepositorioListResource, '/')
api.add_resource(RepositorioResource, '/<string:repo_id>')
예제 #14
0
from app.extensions import api
from .firstApi import FirstApi

# 此处注册api
api.add_resource(FirstApi, '/hello')
예제 #15
0
파일: __init__.py 프로젝트: bigtree21cn/iot
def init_app(app):
    from app.extensions import api
    api.add_resource(UserAPI, '/api/users/', endpoint='users')
    api.add_resource(TokenAPI, '/api/login/', endpoint='token')
예제 #16
0
from app.extensions import api
from .cityApi import CityResource
from .userApi import UserResource
from .activationApi import ActivationResource

api.add_resource(CityResource, '/cities/')
api.add_resource(UserResource, '/user/')
api.add_resource(ActivationResource, '/activation/')
예제 #17
0

class NoteAPI_Filter(Resource):
    def get(self, table):
        Table = table_index[table][0]
        Table_schema = table_index[table][1]

        data = Table.query.filter_by(**request.json).all()
        res = Table_schema.dump(data)
        return jsonify(res)


class ClearTable(Resource):
    def delete(self, table):
        try:
            Table = table_index[table][0]
            Table_schema = table_index[table][1]
            if request.json['key'] == KEY:
                data = Table.query.all()
                for i in data:
                    db.session.delete(i)
                db.session.commit()
                return jsonify({"msg": "{} is cleared.".format(table)})
        except:
            abort(404, message="Delete table error.")


api.add_resource(NoteAPI, '/api/note/<table>')
api.add_resource(NoteAPI_Filter, '/api/note_filter/<table>')
api.add_resource(ClearTable, '/api/note_clear/<table>')
예제 #18
0
파일: urls.py 프로젝트: 77abe77/IBData
# -*- coding: utf-8 -*-
from app.extensions import api
from app.controllers import (health, stock)

# Health Routes
api.add_resource(health.HealthResource, '/', '/health')
api.add_resource(stock.EquityListResource, '/', '/equity')
예제 #19
0
            }
            return data

        except:
            db.session.rollback()
            db.session.flush()
            abort(404)

    def delete(self, id):
        post = Post.query.get(id)
        db.session.delete(post)
        db.session.commit()
        return '已删除'


api.add_resource(PostListApi, '/post', endpoint='posts')
# api.add_resource(PostApi, '/post/<int:id>', endpoint='post')

category_fields = {
    'msg': fields.String,
    'status': fields.Integer,
    'data': fields.List(fields.Nested(category_model_fields))
}


# 帖子分类
class PostCategory(Resource):
    @marshal_with(category_fields)
    def get(self):
        '''
        获取所有帖子类别
from app.extensions import api
from .firstApi import FirstApi

# 此处注册api
api.add_resource(FirstApi, '/compare')