custom profile fields: Rename "SELECT" field validator.

Rename the "SELECT" field validator so that it can be reused
with the upcoming "SELECT_MULTIPLE" field.
This commit is contained in:
tushar912 2021-03-24 17:18:00 +05:30 committed by Tim Abbott
parent b220d29fed
commit 98a6bdbd4c
3 changed files with 6 additions and 6 deletions

View File

@ -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.

View File

@ -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"),

View File

@ -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: