mirror of https://github.com/zulip/zulip.git
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:
parent
b220d29fed
commit
98a6bdbd4c
|
@ -357,7 +357,7 @@ def check_external_account_url_pattern(var_name: str, val: object) -> str:
|
||||||
return s
|
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
|
This function is used to validate the data sent to the server while
|
||||||
creating/editing choices of the choice field in Organization settings.
|
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)
|
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
|
This function is used to validate the value selected by the user against a
|
||||||
choice field. This is not used to validate admin data.
|
choice field. This is not used to validate admin data.
|
||||||
|
|
|
@ -88,7 +88,7 @@ from zerver.lib.validator import (
|
||||||
check_long_string,
|
check_long_string,
|
||||||
check_short_string,
|
check_short_string,
|
||||||
check_url,
|
check_url,
|
||||||
validate_choice_field,
|
validate_select_field,
|
||||||
)
|
)
|
||||||
|
|
||||||
MAX_TOPIC_NAME_LENGTH = 60
|
MAX_TOPIC_NAME_LENGTH = 60
|
||||||
|
@ -3308,7 +3308,7 @@ class CustomProfileField(models.Model):
|
||||||
# and value argument. i.e. SELECT require field_data, USER require
|
# and value argument. i.e. SELECT require field_data, USER require
|
||||||
# realm as argument.
|
# realm as argument.
|
||||||
SELECT_FIELD_TYPE_DATA: List[ExtendedFieldElement] = [
|
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_FIELD_TYPE_DATA: List[UserFieldElement] = [
|
||||||
(USER, ugettext_lazy("Person picker"), check_valid_user_ids, ast.literal_eval, "USER"),
|
(USER, ugettext_lazy("Person picker"), check_valid_user_ids, ast.literal_eval, "USER"),
|
||||||
|
|
|
@ -29,7 +29,7 @@ from zerver.lib.validator import (
|
||||||
check_list,
|
check_list,
|
||||||
check_string,
|
check_string,
|
||||||
check_union,
|
check_union,
|
||||||
validate_choice_field_data,
|
validate_select_field_data,
|
||||||
)
|
)
|
||||||
from zerver.models import CustomProfileField, UserProfile, custom_profile_fields_for_realm
|
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
|
# Choice type field must have at least have one choice
|
||||||
if len(field_data) < 1:
|
if len(field_data) < 1:
|
||||||
raise JsonableError(_("Field must have at least one choice."))
|
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:
|
elif field_type == CustomProfileField.EXTERNAL_ACCOUNT:
|
||||||
validate_external_account_field_data(field_data)
|
validate_external_account_field_data(field_data)
|
||||||
except ValidationError as error:
|
except ValidationError as error:
|
||||||
|
|
Loading…
Reference in New Issue