docs: Remove recommendations of json_validator with check_string.

See #18035 for background.
This commit is contained in:
Tim Abbott 2021-05-07 15:12:18 -07:00
parent 00647b6fa7
commit 0044c8f85f
2 changed files with 7 additions and 2 deletions

View File

@ -415,7 +415,7 @@ annotation).
def update_realm( def update_realm(
request: HttpRequest, request: HttpRequest,
user_profile: UserProfile, user_profile: UserProfile,
name: Optional[str] = REQ(json_validator=check_string, default=None), name: Optional[str] = REQ(str_validator=check_string, default=None),
# ... # ...
+ mandatory_topics: Optional[bool] = REQ(json_validator=check_bool, default=None), + mandatory_topics: Optional[bool] = REQ(json_validator=check_bool, default=None),
# ... # ...

View File

@ -194,6 +194,11 @@ REQ also helps us with request variable validation. For example:
integer (`converter` differs from `json_validator` in that it does integer (`converter` differs from `json_validator` in that it does
not automatically marshall the input from JSON). not automatically marshall the input from JSON).
* Since there is no need to JSON-encode strings, usually simply
`my_string=REQ()` is correct. One can pass e.g.
`str_validator=check_string_in(...)` where one wants to run a
validator on the value of a string.
See See
[zerver/lib/validator.py](https://github.com/zulip/zulip/blob/master/zerver/lib/validator.py) [zerver/lib/validator.py](https://github.com/zulip/zulip/blob/master/zerver/lib/validator.py)
for more validators and their documentation. for more validators and their documentation.
@ -261,7 +266,7 @@ For example, in [zerver/views/realm.py](https://github.com/zulip/zulip/blob/mast
@has_request_variables @has_request_variables
def update_realm( def update_realm(
request: HttpRequest, user_profile: UserProfile, request: HttpRequest, user_profile: UserProfile,
name: Optional[str]=REQ(json_validator=check_string, default=None), name: Optional[str]=REQ(str_validator=check_string, default=None),
# ... # ...
): ):
realm = user_profile.realm realm = user_profile.realm