Skip to content

Commit

Permalink
bugfix(): big fix for different dest key while cross filed
Browse files Browse the repository at this point in the history
  • Loading branch information
Eastwu5788 committed May 19, 2020
1 parent ab63ff3 commit 8bb0d10
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
.. py:currentmodule:: pre_request
Version 2.2.0 (20200630)
Version 2.1.1 (20200630)
-------------------------

Unreleased

- TODO: 优化项目结构,脱离Flask限制,将不同web框架作为扩展实现
- TODO: 核心能力抽象,支持普通函数入参校验能力

Version 2.1.0
Expand Down
9 changes: 5 additions & 4 deletions examples/example_filter/example_gt_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
""" 演示 pre-request 框架验证不同参数联动限制禁止相等
"""
import json
from datetime import datetime
from flask import Flask
from pre_request import pre, Rule

Expand All @@ -18,8 +19,8 @@

# 指定gt_key, 禁止两个参数相等
gt_key_params = {
"p1": Rule(type=int),
"p2": Rule(type=int, gt_key="p1")
"p1": Rule(type=datetime, dest="P1"),
"p2": Rule(type=datetime, gt_key="P1", dest="P2")
}


Expand All @@ -33,8 +34,8 @@ def example_gt_key_filter():
""" 演示gt_key包含函数
"""
resp = client.get("/gt/key", data={
"p1": 15,
"p2": 13
"p1": "2020-01-01 12:00:00",
"p2": "2019-12-12 12:00:00"
})
print(json.loads(resp.data))

Expand Down
4 changes: 2 additions & 2 deletions examples/example_filter/example_required_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# 指定required_with=other, 当指定的其它参数填写后,要求此参数也必须填写
required_with_params = {
"p1": Rule(required=False),
"p2": Rule(required=False, required_with="p1", type=float)
"p2": Rule(required=False, required_with="p1", type=float, dest="P2")
}


Expand All @@ -36,7 +36,7 @@ def example_required_with_filter():
"p1": "H",
# "p2": 13
})
print(resp.data)
print(resp.json)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion pre_request/filters/cross/equal_key_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __call__(self, *args, **kwargs):

# 所有请求后的处理函数
params = kwargs.get("params", dict())
value = get_deep_value(self.key, params, None, deep=True)
value = get_deep_value(self.rule.key_map or self.key, params, None, deep=True)

for r_key, r_code in self.support_rules.items():
rule = getattr(self.rule, r_key, None)
Expand Down
2 changes: 1 addition & 1 deletion pre_request/filters/cross/required_with_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __call__(self, *args, **kwargs):

other_v = get_deep_value(self.rule.required_with, params, None, deep=True)

if other_v is not None and get_deep_value(self.key, params, None, deep=True) is None:
if other_v is not None and get_deep_value(self.rule.key_map or self.key, params, None, deep=True) is None:
raise ParamsValueError(self.required_with_error, filter=self)

return self.value

0 comments on commit 8bb0d10

Please sign in to comment.