本文整理汇总了Python中webargs.fields.Int方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Int方法的具体用法?Python fields.Int怎么用?Python fields.Int使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webargs.fields
的用法示例。
在下文中一共展示了fields.Int方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: param
# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Int [as 别名]
def param(name, cast=None):
def switch(case):
return {
int: wf.Int(missing=None),
float: wf.Float(missing=None),
bool: wf.Bool(missing=None),
list: wf.DelimitedList(wf.Str(), delimiter=',', missing=[]),
}.get(case)
if cast is None or cast is ndb.Key:
cast_ = wf.Str(missing=None)
else:
cast_ = switch(cast) or cast
args = parser.parse({name: cast_})
value = args[name]
return ndb.Key(urlsafe=value) if cast is ndb.Key and value else value
示例2: get_dbs
# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Int [as 别名]
def get_dbs(cls, query=None, ancestor=None, order=None, limit=None, cursor=None, **kwargs):
args = parser.parse({
'cursor': wf.Str(missing=None),
'limit': wf.Int(missing=None, validate=validate.Range(min=-1)),
'order': wf.Str(missing=None),
})
return util.get_dbs(
query or cls.query(ancestor=ancestor),
limit=limit or args['limit'],
cursor=cursor or args['cursor'],
order=order or args['order'],
**kwargs
)
示例3: index
# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Int [as 别名]
def index(self, request):
try:
# patch __log
self.__log = self._GRest__log
__validation_rules__ = {
"skip": fields.Int(required=False,
validate=lambda skip: skip >= 0,
missing=0),
"limit": fields.Int(required=False,
validate=lambda lim: lim >= 1 and lim <= 100,
missing=QUERY_LIMIT),
"order_by": fields.Str(required=False,
missing="?")
}
(primary, secondary) = validate_models(self)
query_data = validate_input(__validation_rules__, request)
skip = query_data.get("skip")
limit = query_data.get("skip") + query_data.get("limit")
order_by = escape(query_data.get("order_by"))
if order_by:
if order_by.startswith("-"):
# select property for descending ordering
order_by_prop = order_by[1:]
else:
# select property for ascending ordering
order_by_prop = order_by
primary_model_props = primary.model.defined_properties().keys()
if all([order_by_prop not in primary_model_props,
order_by_prop != "?"]):
raise HTTPException(msg.INVALID_ORDER_PROPERTY, 404)
total_items = len(primary.model.nodes)
if total_items <= 0:
raise HTTPException(msg.NO_ITEM_EXISTS.format(
model=primary.model_name), 404)
if skip > total_items:
raise HTTPException(msg.VALIDATION_FAILED, 422)
items = primary.model.nodes.order_by(order_by)[skip:limit]
if items:
return serialize({pluralize(primary.model_name):
[item.to_dict() for item in items]})
else:
raise HTTPException(msg.NO_ITEM_EXISTS.format(
model=primary.model_name), 404)
except DoesNotExist as e:
self.__log.exception(e)
raise HTTPException(msg.ITEM_DOES_NOT_EXIST, 404)
示例4: validation_rules
# 需要导入模块: from webargs import fields [as 别名]
# 或者: from webargs.fields import Int [as 别名]
def validation_rules(self):
"""
if the user has defined validation rules,
return that, otherwise construct a set of
predefined rules and return it.
All internal GRest methods should use this property.
"""
if hasattr(self, "__validation_rules__"):
if len(self.__validation_rules__) > 0:
# there is a set of user-defined validation rules
return self.__validation_rules__
model_types = [
StringProperty, DateTimeProperty, DateProperty,
EmailProperty, BooleanProperty, UniqueIdProperty,
ArrayProperty, IntegerProperty, JSONProperty
]
model_mapping = {
IntegerProperty: fields.Int,
StringProperty: fields.Str,
BooleanProperty: fields.Bool,
DateTimeProperty: fields.DateTime,
DateProperty: fields.Date,
EmailProperty: fields.Email,
ArrayProperty: fields.List,
JSONProperty: fields.Dict,
UniqueIdProperty: fields.UUID
}
name = 0
value = 1
for field in self.defined_properties().items():
if field[name] not in self.__validation_rules__:
if type(field[value]) in model_types:
if isinstance(field[value], ArrayProperty):
if field[value].unique_index:
# what it contains: Array of *String*
container = model_mapping[
type(field[value].unique_index)]
else:
# defaults to Raw for untyped ArrayProperty
container = fields.Raw
self.__validation_rules__[field[name]] = model_mapping[
type(field[value])](container,
required=field[value].required)
else:
self.__validation_rules__[field[name]] = model_mapping[
type(field[value])](required=field[value].required)
return self.__validation_rules__