From 98a6bdbd4ccdc2189af84cda0d4bc119666a28b5 Mon Sep 17 00:00:00 2001 From: tushar912 Date: Wed, 24 Mar 2021 17:18:00 +0530 Subject: [PATCH] custom profile fields: Rename "SELECT" field validator. Rename the "SELECT" field validator so that it can be reused with the upcoming "SELECT_MULTIPLE" field. --- zerver/lib/validator.py | 4 ++-- zerver/models.py | 4 ++-- zerver/views/custom_profile_fields.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zerver/lib/validator.py b/zerver/lib/validator.py index 34ccacad45..7cb06ab428 100644 --- a/zerver/lib/validator.py +++ b/zerver/lib/validator.py @@ -357,7 +357,7 @@ def check_external_account_url_pattern(var_name: str, val: object) -> str: return s -def validate_choice_field_data(field_data: ProfileFieldData) -> Dict[str, Dict[str, str]]: +def validate_select_field_data(field_data: ProfileFieldData) -> Dict[str, Dict[str, str]]: """ This function is used to validate the data sent to the server while creating/editing choices of the choice field in Organization settings. @@ -379,7 +379,7 @@ def validate_choice_field_data(field_data: ProfileFieldData) -> Dict[str, Dict[s return cast(Dict[str, Dict[str, str]], field_data) -def validate_choice_field(var_name: str, field_data: str, value: object) -> str: +def validate_select_field(var_name: str, field_data: str, value: object) -> str: """ This function is used to validate the value selected by the user against a choice field. This is not used to validate admin data. diff --git a/zerver/models.py b/zerver/models.py index 60cf3f67b6..829b0f9a5e 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -88,7 +88,7 @@ from zerver.lib.validator import ( check_long_string, check_short_string, check_url, - validate_choice_field, + validate_select_field, ) MAX_TOPIC_NAME_LENGTH = 60 @@ -3308,7 +3308,7 @@ class CustomProfileField(models.Model): # and value argument. i.e. SELECT require field_data, USER require # realm as argument. SELECT_FIELD_TYPE_DATA: List[ExtendedFieldElement] = [ - (SELECT, ugettext_lazy("List of options"), validate_choice_field, str, "SELECT"), + (SELECT, ugettext_lazy("List of options"), validate_select_field, str, "SELECT"), ] USER_FIELD_TYPE_DATA: List[UserFieldElement] = [ (USER, ugettext_lazy("Person picker"), check_valid_user_ids, ast.literal_eval, "USER"), diff --git a/zerver/views/custom_profile_fields.py b/zerver/views/custom_profile_fields.py index 61b9b72c35..4d90e48385 100644 --- a/zerver/views/custom_profile_fields.py +++ b/zerver/views/custom_profile_fields.py @@ -29,7 +29,7 @@ from zerver.lib.validator import ( check_list, check_string, check_union, - validate_choice_field_data, + validate_select_field_data, ) from zerver.models import CustomProfileField, UserProfile, custom_profile_fields_for_realm @@ -62,7 +62,7 @@ def validate_custom_field_data(field_type: int, field_data: ProfileFieldData) -> # Choice type field must have at least have one choice if len(field_data) < 1: raise JsonableError(_("Field must have at least one choice.")) - validate_choice_field_data(field_data) + validate_select_field_data(field_data) elif field_type == CustomProfileField.EXTERNAL_ACCOUNT: validate_external_account_field_data(field_data) except ValidationError as error: