Python flask_restful.reqparse.RequestParser() Examples

The following are 30 code examples of flask_restful.reqparse.RequestParser(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_restful.reqparse , or try the search function .
Example #1
Source File: project.py    From zou with GNU Affero General Public License v3.0 8 votes vote down vote up
def delete(self, instance_id):
        parser = reqparse.RequestParser()
        parser.add_argument("force", default=False, type=bool)
        args = parser.parse_args()

        project = self.get_model_or_404(instance_id)
        project_dict = project.serialize()
        if projects_service.is_open(project_dict):
            return {
                "error": True,
                "message": "Only closed projects can be deleted"
            }, 400
        else:
            self.check_delete_permissions(project_dict)
            if args["force"] == True:
                deletion_service.remove_project(instance_id)
            else:
                project.delete()
            self.post_delete(project_dict)
            return "", 204 
Example #2
Source File: resources.py    From zou with GNU Affero General Public License v3.0 7 votes vote down vote up
def get_arguments(self):
        parser = reqparse.RequestParser()
        parser.add_argument(
            "email", help="The email is required.", required=True
        )
        parser.add_argument(
            "first_name", help="The first name is required.", required=True
        )
        parser.add_argument(
            "last_name", help="The last name is required.", required=True
        )
        parser.add_argument("phone", default="")
        parser.add_argument("role", default="user")
        parser.add_argument("desktop_login", default="")
        args = parser.parse_args()
        return args 
Example #3
Source File: resources.py    From zou with GNU Affero General Public License v3.0 7 votes vote down vote up
def get_arguments(self):
        parser = reqparse.RequestParser()
        parser.add_argument("person_id", default=None)
        parser.add_argument("comment", default="")
        parser.add_argument("name", default="main")
        parser.add_argument("revision", default=1, type=int)
        parser.add_argument("change_status", default=True, type=bool)
        args = parser.parse_args()

        return (
            args["person_id"],
            args["comment"],
            args["name"],
            args["revision"],
            args["change_status"],
        ) 
Example #4
Source File: endpoints.py    From mini-key-server with MIT License 7 votes vote down vote up
def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument("token", required=True)
        parser.add_argument("machine", required=True)
        parser.add_argument("user", required=True)
        parser.add_argument("hwid", required=True)
        parser.add_argument("app_id", required=True, type=int)

        args = parser.parse_args()

        origin = Origin(request.remote_addr,
                        args.machine, args.user, args.hwid)

        if key_valid_const(args.app_id, args.token, origin):
            return {"result": "ok"}, 201

        return {"result": "failure", "error": "invalid key"}, 404 
Example #5
Source File: Script.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            else:
                return self.read(id) 
Example #6
Source File: auth.py    From papers with MIT License 6 votes vote down vote up
def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('email', type=str, help='You need to enter your e-mail address', required=True)
        parser.add_argument('password', type=str, help='You need to enter your password', required=True)
        
        args = parser.parse_args()
        
        email = args.get('email')
        password = args.get('password')
        
        try:
            token = User.validate(email, password)
            return {'token': token}
        except ValidationError as e:
            abort(400, message='There was an error while trying to log you in -> {}'.format(e.message)) 
Example #7
Source File: resources.py    From zou with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_arguments(self):
        parser = reqparse.RequestParser()
        parser.add_argument("only_preview", default=False, type=bool)
        parser.add_argument("task_type_id", default=None)
        parser.add_argument("task_status_id", default=None)
        parser.add_argument("page", default=1, type=int)
        parser.add_argument("page_size", default=50, type=int)
        args = parser.parse_args()

        return (
            args["only_preview"],
            args["task_type_id"],
            args["task_status_id"],
            args["page"],
            args["page_size"],
        ) 
Example #8
Source File: auth.py    From papers with MIT License 6 votes vote down vote up
def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('fullname', type=str, help='You need to enter your full name', required=True)
        parser.add_argument('email', type=str, help='You need to enter your e-mail address', required=True)
        parser.add_argument('password', type=str, help='You need to enter your chosen password', required=True)
        parser.add_argument('password_conf', type=str, help='You need to enter the confirm password field', required=True)
        
        args = parser.parse_args()
        
        email = args.get('email')
        password = args.get('password')
        password_conf = args.get('password_conf')
        fullname = args.get('fullname')
        
        try:
            User.create(
                email=email,
                password=password,
                password_conf=password_conf,
                fullname=fullname
            )
            return {'message': 'Successfully created your account.'}
        except ValidationError as e:
            abort(400, message='There was an error while trying to create your account -> {}'.format(e.message)) 
Example #9
Source File: resources.py    From zou with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_arguments(self):
        parser = reqparse.RequestParser()
        parser.add_argument(
            "task_status_id", required=True, help="Task Status ID is missing"
        )
        parser.add_argument("comment", default="")
        parser.add_argument("person_id", default="")
        if request.json is None:
            parser.add_argument("checklist", default="[]")
            args = parser.parse_args()
            checklist = args["checklist"]
            checklist = json.loads(checklist)
        else:
            parser.add_argument("checklist", type=dict, action="append", default=[])
            args = parser.parse_args()
            checklist = args["checklist"]

        return (
            args["task_status_id"],
            args["comment"],
            args["person_id"],
            checklist
        ) 
Example #10
Source File: playsound.py    From pajbot with MIT License 6 votes vote down vote up
def put(self, playsound_name, **options):
        post_parser = RequestParser()
        post_parser.add_argument("link", required=True)
        args = post_parser.parse_args()

        try:
            link = args["link"]
        except (ValueError, KeyError):
            return {"error": "Invalid `link` parameter."}, 400

        with DBManager.create_session_scope() as db_session:
            count = db_session.query(Playsound).filter(Playsound.name == playsound_name).count()
            if count >= 1:
                return "Playsound already exists", 400

            # the rest of the parameters are initialized with defaults
            playsound = Playsound(name=playsound_name, link=link)
            db_session.add(playsound)

            return "OK", 200 
Example #11
Source File: resources.py    From zou with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_arguments(self):
        maxsoft = files_service.get_or_create_software("3ds Max", "max", ".max")

        parser = reqparse.RequestParser()
        parser.add_argument("name", default="main")
        parser.add_argument("mode", default="working")
        parser.add_argument("software_id", default=maxsoft["id"])
        parser.add_argument("comment", default="")
        parser.add_argument("revision", default=0)
        parser.add_argument("sep", default="/")
        args = parser.parse_args()

        return (
            args["name"],
            args["mode"],
            args["software_id"],
            args["comment"],
            args["revision"],
            args["sep"],
        ) 
Example #12
Source File: Engine.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            else:
                return self.read(id) 
Example #13
Source File: Engine.py    From FuzzFlow with MIT License 6 votes vote down vote up
def post(self, id=None):
        parser = reqparse.RequestParser()
        if id is None:
            parser.add_argument('name', required=True, location='json')
            parser.add_argument('path', required=True, location='json')
            parser.add_argument('platform_id', required=True, location='json')
            parser.add_argument('arch_id', required=True, location='json')
            parser.add_argument('options', location='json')
            return self.create(parser.parse_args())
        else:
            parser.add_argument('name', location='json')
            parser.add_argument('path', location='json')
            parser.add_argument('platform_id', location='json')
            parser.add_argument('arch_id', location='json')
            parser.add_argument('options', location='json')
            return self.update(id, parser.parse_args()) 
Example #14
Source File: Crash.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            else:
                return self.read(id) 
Example #15
Source File: Option.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('type', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            elif args['type'] == 1:
                return self.type()
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            else:
                return self.read(id) 
Example #16
Source File: Job.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        parser.add_argument('state', type=int)
        parser.add_argument('host', type=int)
        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            elif args['state'] == 1:
                return self.state()
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            elif args['host'] == 1:
                return self.read(id, 'host')
            else:
                return self.read(id) 
Example #17
Source File: Job.py    From FuzzFlow with MIT License 6 votes vote down vote up
def post(self, id=None):
        parser = reqparse.RequestParser()
        if id is None:
            parser.add_argument('name', required=True, location='json')
            parser.add_argument('state_id', required=True, location='json')
            parser.add_argument('engine_id', required=True, location='json')
            parser.add_argument('target_id', required=True, location='json')
            parser.add_argument('options', type=list, location='json')
            parser.add_argument('host_id', location='json')
            parser.add_argument('output', location='json')
            return self.create(parser.parse_args())
        else:
            parser.add_argument('name', location='json')
            parser.add_argument('state_id', location='json')
            parser.add_argument('engine_id', location='json')
            parser.add_argument('target_id', location='json')
            parser.add_argument('options', type=list, location='json')
            parser.add_argument('host_id', location='json')
            parser.add_argument('output', location='json')
            return self.update(id, parser.parse_args()) 
Example #18
Source File: Target.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            else:
                return self.read(id) 
Example #19
Source File: Target.py    From FuzzFlow with MIT License 6 votes vote down vote up
def post(self, id=None):
        parser = reqparse.RequestParser()
        if id is None:
            parser.add_argument('name', required=True, location='json')
            parser.add_argument('path', required=True, location='json')
            parser.add_argument('platform_id', required=True, location='json')
            parser.add_argument('arch_id', required=True, location='json')
            parser.add_argument('visible', type=int, location='json')
            return self.create(parser.parse_args())
        else:
            parser.add_argument('name', location='json')
            parser.add_argument('path', location='json')
            parser.add_argument('visible', type=int, location='json')
            parser.add_argument('platform_id', location='json')
            parser.add_argument('arch_id', location='json')
            return self.update(id, parser.parse_args()) 
Example #20
Source File: Platform.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            else:
                return self.read(id) 
Example #21
Source File: Arch.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            else:
                return self.read(id) 
Example #22
Source File: _deprecated_Config.py    From FuzzFlow with MIT License 6 votes vote down vote up
def get(self, id=None):
        parser = reqparse.RequestParser()
        parser.add_argument('delete', type=int)
        parser.add_argument('offset', type=int)
        parser.add_argument('limit', type=int)
        parser.add_argument('host', type=int)

        args = parser.parse_args()
        if id is None:
            if args['offset'] is not None and args['limit'] is not None:
                return self.list(args['offset'], args['limit'])
            else:
                return self.list()
        else:
            if args['delete'] == 1:
                return self.delete(id)
            elif args['host'] == 1:
                return self.read(id, 'host')
            else:
                return self.read(id) 
Example #23
Source File: _deprecated_Config.py    From FuzzFlow with MIT License 6 votes vote down vote up
def post(self, id=None):
        parser = reqparse.RequestParser()
        if id is None:
            parser.add_argument('host_id', required=True, location='json')
            parser.add_argument('arch_id', required=True, location='json')
            parser.add_argument('platform_id', required=True, location='json')
            parser.add_argument('engines', location='json')
            parser.add_argument('targets', location='json')
            return self.create(parser.parse_args())
        else:
            parser.add_argument('host_id', location='json')
            parser.add_argument('arch_id', location='json')
            parser.add_argument('platform_id', location='json')
            parser.add_argument('engines', location='json')
            parser.add_argument('targets', location='json')
            return self.update(id, parser.parse_args()) 
Example #24
Source File: Host.py    From FuzzFlow with MIT License 6 votes vote down vote up
def post(self, id=None):
        parser = reqparse.RequestParser()
        if id is None:
            parser.add_argument('name', required=True, location='json')
            parser.add_argument('mac', required=True, location='json')
            parser.add_argument('ip', required=True, location='json')
            parser.add_argument('platform_id', required=True, location='json')
            parser.add_argument('arch_id', required=True, location='json')
            return self.create(parser.parse_args())
        else:
            parser.add_argument('name', location='json')
            parser.add_argument('mac', location='json')
            parser.add_argument('ip', location='json')
            parser.add_argument('platform_id', location='json')
            parser.add_argument('arch_id', location='json')
            return self.update(id, parser.parse_args()) 
Example #25
Source File: profiles.py    From flask-restful-example with MIT License 6 votes vote down vote up
def __init__(self):
        self.parser = RequestParser() 
Example #26
Source File: views.py    From lemur with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        self.reqparse = reqparse.RequestParser()
        super(Endpoints, self).__init__() 
Example #27
Source File: modules.py    From pajbot with MIT License 5 votes vote down vote up
def __init__(self):
        super().__init__()

        self.post_parser = reqparse.RequestParser()
        self.post_parser.add_argument("new_state", required=True) 
Example #28
Source File: views.py    From lemur with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        self.reqparse = reqparse.RequestParser()
        super(CertificatesListValid, self).__init__() 
Example #29
Source File: pleblist.py    From pajbot with MIT License 5 votes vote down vote up
def __init__(self):
        super().__init__()

        self.post_parser = reqparse.RequestParser()
        self.post_parser.add_argument("password", required=True, location="cookies") 
Example #30
Source File: views.py    From lemur with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        self.reqparse = reqparse.RequestParser()
        super(Authorities, self).__init__()