Python flask_restplus.reqparse.RequestParser() Examples

The following are 5 code examples of flask_restplus.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_restplus.reqparse , or try the search function .
Example #1
Source File: adapter.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def as_request_parser(cls, paginate=True):
        parser = RequestParser()
        # q parameter
        parser.add_argument('q', type=str, location='args',
                            help='The search query')
        # Expected facets
        # (ie. I want all facets or I want both tags and licenses facets)
        facets = list(cls.facets)
        if facets:
            parser.add_argument('facets', type=str, location='args',
                                choices=['all'] + facets,
                                action='append',
                                help='Selected facets to fetch')
        # Add facets filters arguments
        # (apply a value to a facet ie. tag=value)
        for name, facet in cls.facets.items():
            kwargs = facet.as_request_parser_kwargs()
            parser.add_argument(name, location='args', **kwargs)
        # Sort arguments
        keys = list(cls.sorts)
        choices = keys + ['-' + k for k in keys]
        help_msg = 'The field (and direction) on which sorting apply'
        parser.add_argument('sort', type=str, location='args', choices=choices,
                            help=help_msg)
        if paginate:
            parser.add_argument('page', type=int, location='args',
                                default=0, help='The page to display')
            parser.add_argument('page_size', type=int, location='args',
                                default=20, help='The page size')
        return parser 
Example #2
Source File: test_adapter.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_as_request_parser_terms_facet(self):
        parser = FakeSearch.as_request_parser()
        assert isinstance(parser, RequestParser)

        # query + facets selector + tag and other facets + sorts + pagination
        assert len(parser.args) == 7
        assertHasArgument(parser, 'q', str)
        assertHasArgument(parser, 'sort', str)
        assertHasArgument(parser, 'facets', str)
        assertHasArgument(parser, 'tag', clean_string)
        assertHasArgument(parser, 'other', clean_string)
        assertHasArgument(parser, 'page', int)
        assertHasArgument(parser, 'page_size', int) 
Example #3
Source File: test_adapter.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_as_request_parser_bool_facet(self):
        parser = FakeSearchWithBool.as_request_parser()
        assert isinstance(parser, RequestParser)

        # query + facets selector + boolean facet + sorts + pagination
        assert len(parser.args) == 6
        assertHasArgument(parser, 'q', str)
        assertHasArgument(parser, 'sort', str)
        assertHasArgument(parser, 'facets', str)
        assertHasArgument(parser, 'boolean', inputs.boolean)
        assertHasArgument(parser, 'page', int)
        assertHasArgument(parser, 'page_size', int) 
Example #4
Source File: test_adapter.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_as_request_parser_range_facet(self):
        parser = FakeSearchWithRange.as_request_parser()
        facet = FakeSearchWithRange.facets['range']
        assert isinstance(parser, RequestParser)

        # query + facets selector + range facet + sorts + pagination
        assert len(parser.args) == 6
        assertHasArgument(parser, 'q', str)
        assertHasArgument(parser, 'sort', str)
        assertHasArgument(parser, 'facets', str)
        assertHasArgument(parser, 'range', facet.validate_parameter,
                          choices=RANGE_LABELS.keys())
        assertHasArgument(parser, 'page', int)
        assertHasArgument(parser, 'page_size', int) 
Example #5
Source File: test_adapter.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_as_request_parser_temporal_coverage_facet(self):
        parser = FakeSearchWithCoverage.as_request_parser()
        facet = FakeSearchWithCoverage.facets['coverage']
        assert isinstance(parser, RequestParser)

        # query + facets selector + range facet + sorts + pagination
        assert len(parser.args) == 6
        assertHasArgument(parser, 'q', str)
        assertHasArgument(parser, 'sort', str)
        assertHasArgument(parser, 'facets', str)
        assertHasArgument(parser, 'coverage', facet.validate_parameter)
        assertHasArgument(parser, 'page', int)
        assertHasArgument(parser, 'page_size', int)