core.form --- 表单模型验证器

class core.form.PropertyType

基类:object

定义模型属性类型,用于验证映射,注意装饰器必须加在property.setter下面

static array(modal_type: Type[Model]) → Callable

数组类实例模型

返回:Callable
static model(modal_type: Type[Model]) → Callable

嵌套子模型类型

返回:Callable
class core.form.Rule

基类:object

定义规则限制,用于验证属性,注意装饰器必须加在property.setter下面

static length(min_len: int, max_len: int) → Callable

字段长度限制规则

参数:
  • min_len -- 字符串最小长度
  • max_len -- 字符串最大长度
返回:

Callable

static scope(min_size: int, max_size: int, number=<class 'int'>) → Callable

参数最小到最大的范围

参数:
  • min_size -- 字符串最小长度
  • max_size -- 字符串最大长度
  • number -- 数字类型,整型或者浮点类型
返回:

Callable

core.form.verify(model_type: Type[Model], catch_method: Callable[str, Any]) → Model

验证参数是否符合模型需求

参数:
  • model_type -- 继承IModal的模型对象
  • catch_method -- 捕获参数的方法,例如self.get_argument,dict().get等等,你甚至可以自定义,始终会传递一个value参数
返回:

验证后的模型实例对象

core.form.weak_verify(pool: List[str], catch_method: Callable[str, Any]) → Dict

对类型验证更随意,主要用来收集数据,无须建立model实例对象

返回:数据对象Dict