From 0044c8f85fcee4e07967126b26ce8dbbea91ba37 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 7 May 2021 15:12:18 -0700 Subject: [PATCH] docs: Remove recommendations of json_validator with check_string. See #18035 for background. --- docs/tutorials/new-feature-tutorial.md | 2 +- docs/tutorials/writing-views.md | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/tutorials/new-feature-tutorial.md b/docs/tutorials/new-feature-tutorial.md index ecc032fcbb..07f234d864 100644 --- a/docs/tutorials/new-feature-tutorial.md +++ b/docs/tutorials/new-feature-tutorial.md @@ -415,7 +415,7 @@ annotation). def update_realm( 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), # ... + mandatory_topics: Optional[bool] = REQ(json_validator=check_bool, default=None), # ... diff --git a/docs/tutorials/writing-views.md b/docs/tutorials/writing-views.md index 604e7fd541..d62e4e524d 100644 --- a/docs/tutorials/writing-views.md +++ b/docs/tutorials/writing-views.md @@ -194,6 +194,11 @@ REQ also helps us with request variable validation. For example: integer (`converter` differs from `json_validator` in that it does 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 [zerver/lib/validator.py](https://github.com/zulip/zulip/blob/master/zerver/lib/validator.py) 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 def update_realm( 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