custom profile fields: Rename "CHOICE" to "SELECT" in backend.

Rename the "CHOICE" field to "SELECT" in backend. This is
done to improve readability as a prep for the upcoming
"SELECT_MULTIPLE" field.
This commit is contained in:
tushar912 2021-03-20 16:09:22 +05:30 committed by Tim Abbott
parent 999b52d309
commit b220d29fed
6 changed files with 15 additions and 15 deletions

View File

@ -6748,7 +6748,7 @@ def try_add_realm_custom_profile_field(
field = CustomProfileField(realm=realm, name=name, field_type=field_type)
field.hint = hint
if (
field.field_type == CustomProfileField.CHOICE
field.field_type == CustomProfileField.SELECT
or field.field_type == CustomProfileField.EXTERNAL_ACCOUNT
):
field.field_data = orjson.dumps(field_data or {}).decode()
@ -6783,7 +6783,7 @@ def try_update_realm_custom_profile_field(
field.name = name
field.hint = hint
if (
field.field_type == CustomProfileField.CHOICE
field.field_type == CustomProfileField.SELECT
or field.field_type == CustomProfileField.EXTERNAL_ACCOUNT
):
field.field_data = orjson.dumps(field_data or {}).decode()

View File

@ -309,8 +309,8 @@ def validate_user_custom_profile_field(
if field_type in validators:
validator = validators[field_type]
return validator(var_name, value)
elif field_type == CustomProfileField.CHOICE:
choice_field_validator = CustomProfileField.CHOICE_FIELD_VALIDATORS[field_type]
elif field_type == CustomProfileField.SELECT:
choice_field_validator = CustomProfileField.SELECT_FIELD_VALIDATORS[field_type]
field_data = field.field_data
# Put an assertion so that mypy doesn't complain.
assert field_data is not None

View File

@ -3298,24 +3298,24 @@ class CustomProfileField(models.Model):
SHORT_TEXT = 1
LONG_TEXT = 2
CHOICE = 3
SELECT = 3
DATE = 4
URL = 5
USER = 6
EXTERNAL_ACCOUNT = 7
# These are the fields whose validators require more than var_name
# and value argument. i.e. CHOICE require field_data, USER require
# and value argument. i.e. SELECT require field_data, USER require
# realm as argument.
CHOICE_FIELD_TYPE_DATA: List[ExtendedFieldElement] = [
(CHOICE, ugettext_lazy("List of options"), validate_choice_field, str, "CHOICE"),
SELECT_FIELD_TYPE_DATA: List[ExtendedFieldElement] = [
(SELECT, ugettext_lazy("List of options"), validate_choice_field, str, "SELECT"),
]
USER_FIELD_TYPE_DATA: List[UserFieldElement] = [
(USER, ugettext_lazy("Person picker"), check_valid_user_ids, ast.literal_eval, "USER"),
]
CHOICE_FIELD_VALIDATORS: Dict[int, ExtendedValidator] = {
item[0]: item[2] for item in CHOICE_FIELD_TYPE_DATA
SELECT_FIELD_VALIDATORS: Dict[int, ExtendedValidator] = {
item[0]: item[2] for item in SELECT_FIELD_TYPE_DATA
}
USER_FIELD_VALIDATORS: Dict[int, RealmUserValidator] = {
item[0]: item[2] for item in USER_FIELD_TYPE_DATA
@ -3336,7 +3336,7 @@ class CustomProfileField(models.Model):
),
]
ALL_FIELD_TYPES = [*FIELD_TYPE_DATA, *CHOICE_FIELD_TYPE_DATA, *USER_FIELD_TYPE_DATA]
ALL_FIELD_TYPES = [*FIELD_TYPE_DATA, *SELECT_FIELD_TYPE_DATA, *USER_FIELD_TYPE_DATA]
FIELD_VALIDATORS: Dict[int, Validator[Union[int, str, List[int]]]] = {
item[0]: item[2] for item in FIELD_TYPE_DATA
@ -3355,7 +3355,7 @@ class CustomProfileField(models.Model):
# type/name/hint.
#
# The format depends on the type. Field types SHORT_TEXT, LONG_TEXT,
# DATE, URL, and USER leave this null. Fields of type CHOICE store the
# DATE, URL, and USER leave this null. Fields of type SELECT store the
# choices' descriptions.
#
# Note: There is no performance overhead of using TextField in PostgreSQL.

View File

@ -87,7 +87,7 @@ class CreateCustomProfileFieldTest(CustomProfileFieldTestCase):
self.login("iago")
data: Dict[str, Union[str, int]] = {}
data["name"] = "Favorite programming language"
data["field_type"] = CustomProfileField.CHOICE
data["field_type"] = CustomProfileField.SELECT
data["field_data"] = "invalid"
result = self.client_post("/json/realm/profile_fields", info=data)

View File

@ -58,7 +58,7 @@ def validate_field_name_and_hint(name: str, hint: str) -> None:
def validate_custom_field_data(field_type: int, field_data: ProfileFieldData) -> None:
try:
if field_type == CustomProfileField.CHOICE:
if field_type == CustomProfileField.SELECT:
# Choice type field must have at least have one choice
if len(field_data) < 1:
raise JsonableError(_("Field must have at least one choice."))

View File

@ -607,7 +607,7 @@ class Command(BaseCommand):
"emacs": {"text": "Emacs", "order": "2"},
}
favorite_editor = try_add_realm_custom_profile_field(
zulip_realm, "Favorite editor", CustomProfileField.CHOICE, field_data=field_data
zulip_realm, "Favorite editor", CustomProfileField.SELECT, field_data=field_data
)
birthday = try_add_realm_custom_profile_field(
zulip_realm, "Birthday", CustomProfileField.DATE