Example #1
0
def help():
    func_list = []
    for rule in app.url_map.iter_rules():
        if rule.endpoint != "static":
            func_list.append({
                'rule': rule.rule,
                'methods': [method for method in rule.methods],
            })

    return respond_json(message="All URL endpoints",
                        success=True,
                        data=func_list)
Example #2
0
def index():
    # capture log with level info store to storage/logs/yyyy-mm-dd.log
    app.logger.info('Hi, im logger with level info')

    # perform job with params
    # for n in range(10):
    #     example_job.perform.queue(n)

    return respond_json(
        message="Don't know where to go? Query /help for more information.",
        success=True,
        data=None)
def store():
    if 'file' not in request.files or request.files['file'].filename == '':
        return respond_json_with_validation_errors(
            {'file': ['file doest not exists!']})

    file = storage.put('my_files', request.files['file'])

    return respond_json(success=True,
                        message='Successfully upload files',
                        data={
                            "file": storage.temporary_url(file),
                        },
                        code=200)
def index():
    users = User.query.order_by(desc(User.username)).paginate(
        page=request.args.get('page', type=int, default=1),
        per_page=request.args.get('per_page', type=int, default=15),
    )

    return respond_json(
        success=True,
        message=None,
        data=[user.serialize for user in users.items],
        meta={
            'pagination': paginator.paginate(users)
        }
    )
def send():
    try:
        # please read docs https://pythonhosted.org/Flask-Mail/
        message = Message('Hello this is my subject mail')
        message.recipients = [
            '*****@*****.**',
        ]
        message.html = 'Hello my name is <b>ilhamarrouf</b>'

        with app.app_context():
            mail.send(message)

        return respond_json(success=True, message='Successfully send mail...')
    except Exception as err:
        app.logger.error(getattr(err, 'message', repr(err)))
        abort(BadRequest.code)
def account():
    return respond_json(success=True, data=current_user.serialize)
Example #7
0
def handle_authentication_http_exception(error):
    return respond_json(success=False,
                        code=error.status_code,
                        message=error.message,
                        errors=error.errors)
Example #8
0
def internal_server_error(error):
    return respond_json(
        message="Error 500: Internal server error",
        success=False,
        code=InternalServerError.code,
    )
Example #9
0
def too_many_request(error):
    return respond_json(
        message="429 Too Many Requests",
        success=False,
        code=TooManyRequests.code,
    )
Example #10
0
def method_not_allowed(error):
    return respond_json(
        message="Error 405: Method not allowed",
        success=False,
        code=MethodNotAllowed.code,
    )
Example #11
0
def not_found(error):
    return respond_json(
        message="Error 404: Not found",
        success=False,
        code=NotFound.code,
    )
Example #12
0
def unauthenticated(error):
    return respond_json(
        message="Error 401: Unauthenticated",
        success=False,
        code=Unauthorized.code,
    )
Example #13
0
def bad_request(error):
    return respond_json(
        message="Error 400: Bad request",
        success=False,
        code=BadRequest.code,
    )
Example #14
0
def custom_user_loader_error(identity):
    return respond_json(success=False,
                        message="Auth user {} not found".format(identity),
                        code=Unauthorized.code)
Example #15
0
def expired_token_loader():
    return respond_json(success=False,
                        message='Token has expired.',
                        code=Unauthorized.code)
Example #16
0
def unauthorized_loader(callback):
    return respond_json(success=False,
                        message='unauthenticated.',
                        code=Unauthorized.code)