models: Switch font size default to non-compact.

This is the intended longer-term default, and it's polished enough for
testing.
This commit is contained in:
Tim Abbott 2024-07-17 17:07:12 -07:00
parent b4c699db85
commit f37082c4ca
7 changed files with 120 additions and 14 deletions

View File

@ -0,0 +1,42 @@
# Generated by Django 5.0.6 on 2024-07-18 00:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("zerver", "0555_alter_onboardingstep_onboarding_step"),
]
operations = [
migrations.AlterField(
model_name="realmuserdefault",
name="dense_mode",
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name="realmuserdefault",
name="web_font_size_px",
field=models.PositiveSmallIntegerField(default=16),
),
migrations.AlterField(
model_name="realmuserdefault",
name="web_line_height_percent",
field=models.PositiveSmallIntegerField(default=140),
),
migrations.AlterField(
model_name="userprofile",
name="dense_mode",
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name="userprofile",
name="web_font_size_px",
field=models.PositiveSmallIntegerField(default=16),
),
migrations.AlterField(
model_name="userprofile",
name="web_line_height_percent",
field=models.PositiveSmallIntegerField(default=140),
),
]

View File

@ -0,0 +1,44 @@
# Generated by Django 5.0.6 on 2024-07-17 15:10
from django.db import migrations
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_default_values_for_information_density_settings(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
"""Set defaults for information density settings to their intended values."""
RealmUserDefault = apps.get_model("zerver", "RealmUserDefault")
UserProfile = apps.get_model("zerver", "UserProfile")
WEB_FONT_SIZE_PX_DEFAULT = 16
WEB_LINE_HEIGHT_PERCENT_DEFAULT = 140
RealmUserDefault.objects.update(
dense_mode=False,
web_font_size_px=WEB_FONT_SIZE_PX_DEFAULT,
web_line_height_percent=WEB_LINE_HEIGHT_PERCENT_DEFAULT,
)
UserProfile.objects.update(
dense_mode=False,
web_font_size_px=WEB_FONT_SIZE_PX_DEFAULT,
web_line_height_percent=WEB_LINE_HEIGHT_PERCENT_DEFAULT,
)
class Migration(migrations.Migration):
atomic = False
dependencies = [
("zerver", "0556_alter_realmuserdefault_dense_mode_and_more"),
]
operations = [
migrations.RunPython(
set_default_values_for_information_density_settings,
elidable=True,
reverse_code=migrations.RunPython.noop,
),
]

View File

@ -65,7 +65,6 @@ class UserBaseSettings(models.Model):
# Values for it are URL suffix after `#`. # Values for it are URL suffix after `#`.
web_home_view = models.TextField(default="inbox") web_home_view = models.TextField(default="inbox")
web_escape_navigates_to_home_view = models.BooleanField(default=True) web_escape_navigates_to_home_view = models.BooleanField(default=True)
dense_mode = models.BooleanField(default=True)
fluid_layout_width = models.BooleanField(default=False) fluid_layout_width = models.BooleanField(default=False)
high_contrast_mode = models.BooleanField(default=False) high_contrast_mode = models.BooleanField(default=False)
translate_emoticons = models.BooleanField(default=False) translate_emoticons = models.BooleanField(default=False)
@ -80,11 +79,14 @@ class UserBaseSettings(models.Model):
# Information density is established through # Information density is established through
# adjustments to the font size and line height. # adjustments to the font size and line height.
WEB_FONT_SIZE_PX_LEGACY = 14 WEB_FONT_SIZE_PX_COMPACT = 14
WEB_LINE_HEIGHT_PERCENT_LEGACY = 122 WEB_FONT_SIZE_PX_DEFAULT = 16
web_font_size_px = models.PositiveSmallIntegerField(default=WEB_FONT_SIZE_PX_LEGACY) WEB_LINE_HEIGHT_PERCENT_COMPACT = 122
WEB_LINE_HEIGHT_PERCENT_DEFAULT = 140
dense_mode = models.BooleanField(default=False)
web_font_size_px = models.PositiveSmallIntegerField(default=WEB_FONT_SIZE_PX_DEFAULT)
web_line_height_percent = models.PositiveSmallIntegerField( web_line_height_percent = models.PositiveSmallIntegerField(
default=WEB_LINE_HEIGHT_PERCENT_LEGACY default=WEB_LINE_HEIGHT_PERCENT_DEFAULT
) )
# UI setting controlling Zulip's behavior of demoting in the sort # UI setting controlling Zulip's behavior of demoting in the sort

View File

@ -3753,8 +3753,8 @@ class RealmPropertyActionTest(BaseAction):
def do_set_realm_user_default_setting_test(self, name: str) -> None: def do_set_realm_user_default_setting_test(self, name: str) -> None:
bool_tests: list[bool] = [True, False, True] bool_tests: list[bool] = [True, False, True]
test_values: dict[str, Any] = dict( test_values: dict[str, Any] = dict(
web_font_size_px=[UserProfile.WEB_FONT_SIZE_PX_LEGACY], web_font_size_px=[UserProfile.WEB_FONT_SIZE_PX_COMPACT],
web_line_height_percent=[UserProfile.WEB_LINE_HEIGHT_PERCENT_LEGACY], web_line_height_percent=[UserProfile.WEB_LINE_HEIGHT_PERCENT_COMPACT],
color_scheme=UserProfile.COLOR_SCHEME_CHOICES, color_scheme=UserProfile.COLOR_SCHEME_CHOICES,
web_home_view=["recent_topics", "inbox", "all_messages"], web_home_view=["recent_topics", "inbox", "all_messages"],
emojiset=[emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()], emojiset=[emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()],

View File

@ -1937,8 +1937,8 @@ class RealmAPITest(ZulipTestCase):
def do_test_realm_default_setting_update_api(self, name: str) -> None: def do_test_realm_default_setting_update_api(self, name: str) -> None:
bool_tests: list[bool] = [False, True] bool_tests: list[bool] = [False, True]
test_values: dict[str, Any] = dict( test_values: dict[str, Any] = dict(
web_font_size_px=[UserProfile.WEB_FONT_SIZE_PX_LEGACY], web_font_size_px=[UserProfile.WEB_FONT_SIZE_PX_COMPACT],
web_line_height_percent=[UserProfile.WEB_LINE_HEIGHT_PERCENT_LEGACY], web_line_height_percent=[UserProfile.WEB_LINE_HEIGHT_PERCENT_COMPACT],
color_scheme=UserProfile.COLOR_SCHEME_CHOICES, color_scheme=UserProfile.COLOR_SCHEME_CHOICES,
web_home_view=["recent_topics", "inbox", "all_messages"], web_home_view=["recent_topics", "inbox", "all_messages"],
emojiset=[emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()], emojiset=[emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()],
@ -1988,12 +1988,22 @@ class RealmAPITest(ZulipTestCase):
# settings in RealmUserDefault table will be used. # settings in RealmUserDefault table will be used.
if prop in ["default_language", "enable_login_emails", "enable_marketing_emails"]: if prop in ["default_language", "enable_login_emails", "enable_marketing_emails"]:
continue continue
if prop in ["dense_mode"]:
# Testing this is complicated, see test_update_default_information_density_settings.
continue
self.do_test_realm_default_setting_update_api(prop) self.do_test_realm_default_setting_update_api(prop)
def test_update_default_information_density_settings(self) -> None: def test_update_default_information_density_settings(self) -> None:
realm = get_realm("zulip") realm = get_realm("zulip")
# Start with the legacy settings configuration
realm_user_default = RealmUserDefault.objects.get(realm=realm) realm_user_default = RealmUserDefault.objects.get(realm=realm)
self.assertEqual(realm_user_default.dense_mode, True) realm_user_default.dense_mode = True
realm_user_default.web_font_size_px = RealmUserDefault.WEB_FONT_SIZE_PX_COMPACT
realm_user_default.web_line_height_percent = (
RealmUserDefault.WEB_LINE_HEIGHT_PERCENT_COMPACT
)
realm_user_default.save()
self.login("iago") self.login("iago")
data: dict[str, str | int] = {"web_font_size_px": 16} data: dict[str, str | int] = {"web_font_size_px": 16}

View File

@ -218,7 +218,12 @@ class ChangeSettingsTest(ZulipTestCase):
def test_toggling_boolean_user_settings(self) -> None: def test_toggling_boolean_user_settings(self) -> None:
"""Test updating each boolean setting in UserProfile property_types""" """Test updating each boolean setting in UserProfile property_types"""
boolean_settings = ( boolean_settings = (
s for s in UserProfile.property_types if UserProfile.property_types[s] is bool s
for s in UserProfile.property_types
if UserProfile.property_types[s] is bool
# Dense mode can't be toggled without changing other settings too.
# This setting is tested in test_changing_information_density_settings.
and s not in ["dense_mode"]
) )
for user_setting in boolean_settings: for user_setting in boolean_settings:
self.check_for_toggle_param_patch("/json/settings", user_setting) self.check_for_toggle_param_patch("/json/settings", user_setting)
@ -503,7 +508,10 @@ class ChangeSettingsTest(ZulipTestCase):
def test_changing_information_density_settings(self) -> None: def test_changing_information_density_settings(self) -> None:
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
self.assertEqual(hamlet.dense_mode, True) hamlet.dense_mode = True
hamlet.web_font_size_px = 14
hamlet.web_line_height_percent = 122
hamlet.save()
self.login("hamlet") self.login("hamlet")
data: dict[str, str | int] = {"web_font_size_px": 16} data: dict[str, str | int] = {"web_font_size_px": 16}

View File

@ -209,12 +209,12 @@ def check_information_density_setting_values(
) )
if dense_mode: if dense_mode:
if web_font_size_px != UserBaseSettings.WEB_FONT_SIZE_PX_LEGACY: if web_font_size_px != UserBaseSettings.WEB_FONT_SIZE_PX_COMPACT:
raise JsonableError( raise JsonableError(
_("Incompatible values for 'dense_mode' and 'web_font_size_px' settings.") _("Incompatible values for 'dense_mode' and 'web_font_size_px' settings.")
) )
if web_line_height_percent != UserBaseSettings.WEB_LINE_HEIGHT_PERCENT_LEGACY: if web_line_height_percent != UserBaseSettings.WEB_LINE_HEIGHT_PERCENT_COMPACT:
raise JsonableError( raise JsonableError(
_("Incompatible values for 'dense_mode' and 'web_line_height_percent' settings.") _("Incompatible values for 'dense_mode' and 'web_line_height_percent' settings.")
) )