def parse_request(*args, **kwargs): """ Decorator used to parse request arguments. This method allows to parse args in different locations then the json body (query string, files, form, headers, etc) :param args: list of Arguments (flask_restful.reqparse.Argument) :return: decorator function """ parser = reqparse.RequestParser(bundle_errors=True) for arg in args: parser.add_argument(arg) if kwargs.get('allow_ordering', None): parser_args = [p.name for p in parser.args] default_args = [ reqparse.Argument("sort_by", type=str, store_missing=False), reqparse.Argument("order", type=str, store_missing=False, choices=('asc', 'desc')), ] for p in default_args: if p.name not in parser_args: parser.add_argument(p) def decorator(f): @functools.wraps(f) def inner(*fargs, **fkwargs): fkwargs.update(parser.parse_args()) return f(*fargs, **fkwargs) return inner return decorator
class UsersRessource(Resource): @parse_params( reqparse.Argument('page', type=int, required=False, location='args', default=1), reqparse.Argument('size', type=int, required=False, location='args', default=10), ) @marshal_with(paginated(user_fields)) def get(self, page, size): return User.query.paginate(page, size, False)
def __init__(self, name, default=None, validate=None, typeof=lambda x: six.text_type(x)): self.argument_class = reqparse.Argument(name=name, default=default, type=typeof) if validate and inspect.isfunction(validate): self.validate_func = validate else: self.validate_func = None self.name = name
from urllib.parse import unquote_plus from flask import Blueprint from flask_restful import reqparse from app.helpers import helpers from app.helpers.helpers import parse_params from app.mod_pedido.services import CerberoLogDataService pedido_bp = Blueprint('pedido_bp', __name__) @pedido_bp.route('/', methods=['GET']) @parse_params(reqparse.Argument('limit', default=100, type=int), reqparse.Argument('conta_identificador_conta', type=str), reqparse.Argument('usuario_email', type=str), reqparse.Argument('evento_status', type=str), reqparse.Argument('modulo_chave', type=str), reqparse.Argument('data_inicial', type=str), reqparse.Argument( 'data_final', type=str, )) def get_all_com_erros(url_params): service = CerberoLogDataService() if url_params.evento_status: url_params.evento_status = unquote_plus( url_params.evento_status).replace('[', '').replace(']', '') url_params.evento_status = [ s.strip() for s in url_params.evento_status.split(',')
""" Defines APIs for restaurants management. """ from flask import current_app from flask_restful import Resource, reqparse from sqlalchemy.exc import IntegrityError from api.models.restaurant import Restaurant from api.database import db from api.auth import only_admin from api.restaurants import register_restaurant nameArg = reqparse.Argument(name='name', type=str, required=True, help='name of restaurant', location='json') cnameArg = reqparse.Argument(name='cname', type=str, required=True, help='canonical name of restaurant', location='json') phoneArg = reqparse.Argument(name='phone', type=str, required=True, help='phone of restaurant', location='json') addressArg = reqparse.Argument(name='address', type=str, required=False,
from flask import current_app from flask_restful import Resource, reqparse from sqlalchemy.exc import IntegrityError import jwt from api.models.user import User from api.database import db from api.auth import only_admin, authenticated_user from api.auth import current_identity from api.email import send_email nameArg = reqparse.Argument(name='name', type=str, required=False, help='name of user', location='json') phoneArg = reqparse.Argument(name='phone', type=str, required=False, help='phone of user', location='json') emailArg = reqparse.Argument(name='email', type=str, required=True, help='No email provided', location='json') pwdArg = reqparse.Argument(name='password', type=str, required=True,
""" Defines APIs for menu management. """ from flask_restful import Resource, reqparse from sqlalchemy.exc import IntegrityError from api.models.menu import Item, Section from api.database import db from api.auth import only_manager, current_identity from api.utils import get_current_restaurant titleArg = reqparse.Argument(name='title', type=str, required=True, help='title of item', location='json') descriptionArg = reqparse.Argument(name='description', type=str, required=True, help='description of item', location='json') imgArg = reqparse.Argument(name='image_url', type=str, required=False, help='image of item', location='json') prcArg = reqparse.Argument(name='price', type=str, required=True, help='image of item',
""" Defines APIs for user handling. """ from flask_restful import Resource, reqparse from flask_jwt import jwt_required from sqlalchemy.exc import IntegrityError from application.models.user import User from application.database import db from application.auth import only_manager, only_admin emailArg = reqparse.Argument(name='email', type=str, required=True, help='No email provided', location='json') pwdArg = reqparse.Argument(name='password', type=str, required=True, help='No password provided', location='json') mngArg = reqparse.Argument(name='is_manager', type=bool, required=False, help='If user is manager', location='json') class UsersAPI(Resource): """
""" Defines APIs for user handling. """ from flask import request, jsonify from flask_restful import Resource, reqparse from flask_jwt import jwt_required from application.models.user import User, Role from application.database import db from application.auth import hasrole nameArg = reqparse.Argument(name='name', type=str, required=True, help='No name provided', location='json') emailArg = reqparse.Argument(name='email', type=str, required=True, help='No email provided', location='json') pwdArg = reqparse.Argument(name='password', type=str, required=True, help='No password provided', location='json') """ Defines routes for users listing and user adding. """
from urllib.parse import unquote_plus from flask import Blueprint from flask_restful import reqparse from app.mod_migracao.services import CerberoLogDataService from app.helpers import helpers from app.helpers.helpers import parse_params migracao_bp = Blueprint('migracao_bp', __name__) @migracao_bp.route('/', methods=['GET']) @parse_params(reqparse.Argument('limit', default=100, type=int), reqparse.Argument('conta_identificador_conta', type=str), reqparse.Argument('tipo_migracao', type=str), reqparse.Argument('evento_instancia_id', type=str), reqparse.Argument('evento_status', type=str), reqparse.Argument('modulo_chave', type=str), reqparse.Argument('data_inicial', type=str), reqparse.Argument('data_final', type=str, )) def get_all_com_erros(url_params): service = CerberoLogDataService() if url_params.evento_status: url_params.evento_status = unquote_plus(url_params.evento_status).replace('[', '').replace(']', '') url_params.evento_status = [s.strip() for s in url_params.evento_status.split(',')] if url_params.evento_status else None migracoes = service.listar_migracoes(conta_identificador_conta=url_params.conta_identificador_conta, tipo_migracao=url_params.tipo_migracao,