mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
profile: Remove integer and float fields.
This commit is contained in:
20
zerver/migrations/0153_remove_int_float_custom_fields.py
Normal file
20
zerver/migrations/0153_remove_int_float_custom_fields.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.6 on 2018-04-02 12:42
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('zerver', '0152_realm_default_twenty_four_hour_time'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='customprofilefield',
|
||||||
|
name='field_type',
|
||||||
|
field=models.PositiveSmallIntegerField(choices=[(1, 'Short Text'), (2, 'Long Text')], default=1),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1868,15 +1868,11 @@ class CustomProfileField(models.Model):
|
|||||||
realm = models.ForeignKey(Realm, on_delete=CASCADE) # type: Realm
|
realm = models.ForeignKey(Realm, on_delete=CASCADE) # type: Realm
|
||||||
name = models.CharField(max_length=100) # type: Text
|
name = models.CharField(max_length=100) # type: Text
|
||||||
|
|
||||||
INTEGER = 1
|
SHORT_TEXT = 1
|
||||||
FLOAT = 2
|
LONG_TEXT = 2
|
||||||
SHORT_TEXT = 3
|
|
||||||
LONG_TEXT = 4
|
|
||||||
|
|
||||||
FIELD_TYPE_DATA = [
|
FIELD_TYPE_DATA = [
|
||||||
# Type, Name, Validator, Converter
|
# Type, Name, Validator, Converter
|
||||||
(INTEGER, u'Integer', check_int, int),
|
|
||||||
(FLOAT, u'Float', check_float, float),
|
|
||||||
(SHORT_TEXT, u'Short Text', check_short_string, str),
|
(SHORT_TEXT, u'Short Text', check_short_string, str),
|
||||||
(LONG_TEXT, u'Long Text', check_string, str),
|
(LONG_TEXT, u'Long Text', check_string, str),
|
||||||
] # type: List[Tuple[int, Text, Validator, Callable[[Any], Any]]]
|
] # type: List[Tuple[int, Text, Validator, Callable[[Any], Any]]]
|
||||||
|
|||||||
@@ -126,40 +126,6 @@ class CustomProfileDataTest(ZulipTestCase):
|
|||||||
self.assert_json_error(result,
|
self.assert_json_error(result,
|
||||||
u"Field id 1234 not found.")
|
u"Field id 1234 not found.")
|
||||||
|
|
||||||
def test_update_invalid_value(self) -> None:
|
|
||||||
self.login(self.example_email("iago"))
|
|
||||||
realm = get_realm('zulip')
|
|
||||||
age_field = try_add_realm_custom_profile_field(
|
|
||||||
realm,
|
|
||||||
u"age",
|
|
||||||
CustomProfileField.INTEGER
|
|
||||||
)
|
|
||||||
|
|
||||||
data = [{'id': age_field.id, 'value': 'text'}]
|
|
||||||
result = self.client_patch("/json/users/me/profile_data", {
|
|
||||||
'data': ujson.dumps(data)
|
|
||||||
})
|
|
||||||
self.assert_json_error(
|
|
||||||
result,
|
|
||||||
u"value[{}] is not an integer".format(age_field.id))
|
|
||||||
|
|
||||||
def test_update_invalid_double(self) -> None:
|
|
||||||
self.login(self.example_email("iago"))
|
|
||||||
realm = get_realm('zulip')
|
|
||||||
field = try_add_realm_custom_profile_field(
|
|
||||||
realm,
|
|
||||||
u"distance",
|
|
||||||
CustomProfileField.FLOAT
|
|
||||||
)
|
|
||||||
|
|
||||||
data = [{'id': field.id, 'value': 'text'}]
|
|
||||||
result = self.client_patch("/json/users/me/profile_data", {
|
|
||||||
'data': ujson.dumps(data)
|
|
||||||
})
|
|
||||||
self.assert_json_error(
|
|
||||||
result,
|
|
||||||
u"value[{}] is not a float".format(field.id))
|
|
||||||
|
|
||||||
def test_update_invalid_short_text(self) -> None:
|
def test_update_invalid_short_text(self) -> None:
|
||||||
self.login(self.example_email("iago"))
|
self.login(self.example_email("iago"))
|
||||||
realm = get_realm('zulip')
|
realm = get_realm('zulip')
|
||||||
@@ -183,7 +149,7 @@ class CustomProfileDataTest(ZulipTestCase):
|
|||||||
fields = [
|
fields = [
|
||||||
('Phone number', 'short text data'),
|
('Phone number', 'short text data'),
|
||||||
('Biography', 'long text data'),
|
('Biography', 'long text data'),
|
||||||
('Favorite integer', 1),
|
('Favorite food', 'short text data'),
|
||||||
]
|
]
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
|
|||||||
@@ -256,20 +256,20 @@ class Command(BaseCommand):
|
|||||||
CustomProfileField.SHORT_TEXT)
|
CustomProfileField.SHORT_TEXT)
|
||||||
biography = try_add_realm_custom_profile_field(zulip_realm, "Biography",
|
biography = try_add_realm_custom_profile_field(zulip_realm, "Biography",
|
||||||
CustomProfileField.LONG_TEXT)
|
CustomProfileField.LONG_TEXT)
|
||||||
favorite_integer = try_add_realm_custom_profile_field(zulip_realm, "Favorite integer",
|
favorite_food = try_add_realm_custom_profile_field(zulip_realm, "Favorite food",
|
||||||
CustomProfileField.INTEGER)
|
CustomProfileField.SHORT_TEXT)
|
||||||
|
|
||||||
# Fill in values for Iago and Hamlet
|
# Fill in values for Iago and Hamlet
|
||||||
hamlet = get_user("hamlet@zulip.com", zulip_realm)
|
hamlet = get_user("hamlet@zulip.com", zulip_realm)
|
||||||
do_update_user_custom_profile_data(iago, [
|
do_update_user_custom_profile_data(iago, [
|
||||||
{"id": phone_number.id, "value": "+1-234-567-8901"},
|
{"id": phone_number.id, "value": "+1-234-567-8901"},
|
||||||
{"id": biography.id, "value": "Betrayer of Othello."},
|
{"id": biography.id, "value": "Betrayer of Othello."},
|
||||||
{"id": favorite_integer.id, "value": 17},
|
{"id": favorite_food.id, "value": "Apples"},
|
||||||
])
|
])
|
||||||
do_update_user_custom_profile_data(hamlet, [
|
do_update_user_custom_profile_data(hamlet, [
|
||||||
{"id": phone_number.id, "value": "+0-11-23-456-7890"},
|
{"id": phone_number.id, "value": "+0-11-23-456-7890"},
|
||||||
{"id": biography.id, "value": "Prince of Denmark, and other things!"},
|
{"id": biography.id, "value": "Prince of Denmark, and other things!"},
|
||||||
{"id": favorite_integer.id, "value": 12},
|
{"id": favorite_food.id, "value": "Dark chocolate"},
|
||||||
])
|
])
|
||||||
else:
|
else:
|
||||||
zulip_realm = get_realm("zulip")
|
zulip_realm = get_realm("zulip")
|
||||||
|
|||||||
Reference in New Issue
Block a user