Beispiel #1
0
def get_blueprints(blueprints, filter_path=''):
    paths = []
    for path in find_packages():
        if filter_path in path:
            paths.append(path)
    for path in paths:
        blueprints[path] = Blueprint(path, path)
    for path in paths:
        __import__(path)
        app.register_blueprint(blueprints[path])
Beispiel #2
0
def app():
    db_fd, db_path = tempfile.mkstemp()

    app = Flask(__name__,
                instance_relative_config=True,
                static_url_path='/static')
    app.testing = True
    app.register_blueprint(bp)

    # create and configure the app
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    )

    with app.app_context():
        init_db()
        get_db().executescript(
            "select Place_ID from PARKING_PLACE order by Place_ID desc")

    yield app

    os.close(db_fd)
    os.unlink(db_path)
Beispiel #3
0
api.add_resource(RegisterUser, '/register')

api.add_resource(StoresList, '/stores')
api.add_resource(Store, '/store/<string:name>')
api.add_resource(OneStore, '/store/<int:_id>')
api.add_resource(SearchStore, '/stores/<string:name>')
api.add_resource(StoreUpdate, '/store/<int:_id>/update')
api.add_resource(StoreDelete, '/store/<int:_id>/delete')

api.add_resource(Items, '/items')
api.add_resource(OneItem, '/search/<int:_id>')
api.add_resource(ItemDelete, '/delete/<int:_id>')
api.add_resource(Item, '/item/<string:name>')
api.add_resource(ItemUpdate, '/item/<int:_id>')
api.add_resource(ItemSearch, '/item/search/<string:name>')

from project.stores.views import stores_blueprints
from project.items.views import items_blueprints

app.register_blueprint(stores_blueprints, url_prefix='/query')
app.register_blueprint(items_blueprints, url_prefix='/all')

# @app.errorhandler(404)
# def page_not_found(e):

#     return jsonify({"Error":"Page could not be found"})

if __name__ == '__main__':
    app.run()
Beispiel #4
0
        response = jsonify({
            'failure': 'You must have a significant other in the system'
        })
        response.status_code = 400
        return response
    msg = user.ping_so()
    response = jsonify({
        'message_sent_at': msg.datetime,
    })
    response.status_code = 200
    return response

@login_required
@messaging_blueprint.route('/get_messages/', methods=['GET'])
def get_messages():
    """Gets all messages sent to current user from their current SO

    Returns:
        200 - [{'id': '<msg.id>', 'sent_at': '<msg.datetime>'}, ...] - success

    Notes:
        User must be logged in to make this request
    """
    user = User.query.get(current_user.id)
    received_messages = user.received_messages()
    response = jsonify([msg.serialize() for msg in received_messages])
    response.status_code = 200
    return response

app.register_blueprint(messaging_blueprint)
Beispiel #5
0
from project import app, make_response, jsonify, Blueprint
from flask_swagger_ui import get_swaggerui_blueprint

### swagger specific ###
SWAGGER_URL = '/swagger'
API_URL = '/static/swagger.json'
SWAGGERUI_BLUEPRINT = get_swaggerui_blueprint(
    SWAGGER_URL, API_URL, config={'app_name': "Frauenloop Bank App"})
app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_URL)
### end swagger specific ###


@app.errorhandler(400)
def handle_400_error(_error):
    """Return a http 400 error to client"""
    return make_response(jsonify({'error': 'Misunderstood'}), 400)


@app.errorhandler(401)
def handle_401_error(_error):
    """Return a http 401 error to client"""
    return make_response(jsonify({'error': 'Unauthorised'}), 401)


@app.errorhandler(404)
def handle_404_error(_error):
    """Return a http 404 error to client"""
    return make_response(jsonify({'error': 'Not found'}), 404)


@app.errorhandler(500)
Beispiel #6
0
            {'failure': 'You must have a significant other in the system'})
        response.status_code = 400
        return response
    msg = user.ping_so()
    response = jsonify({
        'message_sent_at': msg.datetime,
    })
    response.status_code = 200
    return response


@login_required
@api_blueprint.route('/get_messages/', methods=['GET'])
def get_messages():
    """Gets all messages sent to current user from their current SO

    Returns:
        200 - [{'id': '<msg.id>', 'sent_at': '<msg.datetime>'}, ...] - success

    Notes:
        User must be logged in to make this request
    """
    user = User.query.get(current_user.id)
    received_messages = user.received_messages()
    response = jsonify([msg.serialize() for msg in received_messages])
    response.status_code = 200
    return response


app.register_blueprint(api_blueprint)
Beispiel #7
0
from random import random


################
#### config ####
################

view_blueprint = Blueprint('view', __name__)


##########################
#### helper functions ####
##########################

def flash_errors(form):
    for field, errors in form.errors.items():
        for error in errors:
            flash(u"Error in the %s field - %s" % (
                getattr(form, field).label.text,
                error
            ), 'info')
################
#### routes ####
################

@view_blueprint.route('/')
def hello_world():
    return 'Hello World'

app.register_blueprint(view_blueprint)