本文整理汇总了Python中flask_restplus.reqparse.RequestParser方法的典型用法代码示例。如果您正苦于以下问题:Python reqparse.RequestParser方法的具体用法?Python reqparse.RequestParser怎么用?Python reqparse.RequestParser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_restplus.reqparse
的用法示例。
在下文中一共展示了reqparse.RequestParser方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: as_request_parser
# 需要导入模块: from flask_restplus import reqparse [as 别名]
# 或者: from flask_restplus.reqparse import RequestParser [as 别名]
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
示例2: test_as_request_parser_terms_facet
# 需要导入模块: from flask_restplus import reqparse [as 别名]
# 或者: from flask_restplus.reqparse import RequestParser [as 别名]
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)
示例3: test_as_request_parser_bool_facet
# 需要导入模块: from flask_restplus import reqparse [as 别名]
# 或者: from flask_restplus.reqparse import RequestParser [as 别名]
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)
示例4: test_as_request_parser_range_facet
# 需要导入模块: from flask_restplus import reqparse [as 别名]
# 或者: from flask_restplus.reqparse import RequestParser [as 别名]
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)
示例5: test_as_request_parser_temporal_coverage_facet
# 需要导入模块: from flask_restplus import reqparse [as 别名]
# 或者: from flask_restplus.reqparse import RequestParser [as 别名]
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)