custom fields: Allow list of users in user type of custom fields.

Allow user to add more than one user-value in user type of custom
fields.

Tweaked by tabbott to improve the models.py code and type annotations.
This commit is contained in:
Yashashvi Dave
2018-06-07 23:31:31 +05:30
committed by Tim Abbott
parent b0db90648a
commit 8909cb1d15
8 changed files with 68 additions and 53 deletions

View File

@@ -1,5 +1,5 @@
from typing import Union, List, Dict, Optional
from typing import Union, List, Dict, Optional, cast
import logging
import ujson
@@ -142,7 +142,7 @@ def remove_user_custom_profile_data(request: HttpRequest, user_profile: UserProf
def update_user_custom_profile_data(
request: HttpRequest,
user_profile: UserProfile,
data: List[Dict[str, Union[int, str]]]=REQ(validator=check_list(
data: List[Dict[str, Union[int, str, List[int]]]]=REQ(validator=check_list(
check_dict([('id', check_int)])))) -> HttpResponse:
for item in data:
field_id = item['id']
@@ -153,8 +153,8 @@ def update_user_custom_profile_data(
validators = CustomProfileField.FIELD_VALIDATORS
field_type = field.field_type
value = item['value']
var_name = '{}'.format(field.name)
value = item['value']
if field_type in validators:
validator = validators[field_type]
result = validator(var_name, value)
@@ -164,7 +164,8 @@ def update_user_custom_profile_data(
result = choice_field_validator(var_name, field_data, value)
elif field_type == CustomProfileField.USER:
user_field_validator = CustomProfileField.USER_FIELD_VALIDATORS[field_type]
result = user_field_validator(user_profile.realm.id, value, False)
result = user_field_validator(user_profile.realm.id, cast(List[int], value),
False)
else:
raise AssertionError("Invalid field type")