mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Simplify twenty-four-hour time logic to be more generic.
(imported from commit bda4972b32b17a36518eddef701748f3a548e376)
This commit is contained in:
		@@ -363,17 +363,17 @@ exports.setup_page = function () {
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $("#twenty_four_hour_time").change(function () {
 | 
			
		||||
        var time_checkbox = $("#twenty_four_hour_time").is(":checked");
 | 
			
		||||
        var data = {};
 | 
			
		||||
        data.twenty_four_hour_time = JSON.stringify(time_checkbox);
 | 
			
		||||
        var setting_value = $("#twenty_four_hour_time").is(":checked");
 | 
			
		||||
        data.twenty_four_hour_time = JSON.stringify(setting_value);
 | 
			
		||||
 | 
			
		||||
        channel.patch({
 | 
			
		||||
            url: '/json/time_setting',
 | 
			
		||||
            data: data,
 | 
			
		||||
            success: function (resp, statusText, xhr, form) {
 | 
			
		||||
                ui.report_success("Updated display settings!  You will need to reload for the changes to take effect",
 | 
			
		||||
                ui.report_success("Updated display settings!  You will need to reload the window for your changes to take effect",
 | 
			
		||||
                                  $('#display-settings-status').expectOne());
 | 
			
		||||
                },
 | 
			
		||||
            },
 | 
			
		||||
            error: function (xhr, error_type, xhn) {
 | 
			
		||||
                ui.report_error("Error updating display settings", xhr, $('#display-settings-status').expectOne());
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -1718,13 +1718,13 @@ def do_change_default_desktop_notifications(user_profile, default_desktop_notifi
 | 
			
		||||
    user_profile.default_desktop_notifications = default_desktop_notifications
 | 
			
		||||
    user_profile.save(update_fields=["default_desktop_notifications"])
 | 
			
		||||
 | 
			
		||||
def do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time, log=True):
 | 
			
		||||
    user_profile.twenty_four_hour_time = twenty_four_hour_time
 | 
			
		||||
def do_change_twenty_four_hour_time(user_profile, setting_value, log=True):
 | 
			
		||||
    user_profile.twenty_four_hour_time = setting_value
 | 
			
		||||
    user_profile.save(update_fields=["twenty_four_hour_time"])
 | 
			
		||||
    event = {'type': 'update_display_settings',
 | 
			
		||||
             'user': user_profile.email,
 | 
			
		||||
             'setting_name': 'twenty_four_hour_time',
 | 
			
		||||
             'setting': twenty_four_hour_time}
 | 
			
		||||
             'setting': setting_value}
 | 
			
		||||
    if log:
 | 
			
		||||
        log_event(event)
 | 
			
		||||
    send_event(event, [user_profile.id])
 | 
			
		||||
 
 | 
			
		||||
@@ -443,8 +443,8 @@ class EventsRegisterTest(AuthedTestCase):
 | 
			
		||||
            ('setting', check_bool),
 | 
			
		||||
            ])
 | 
			
		||||
        # The first False is probably a noop, then we get transitions in both directions.
 | 
			
		||||
        for twenty_four_hour_time in [False, True, False]:
 | 
			
		||||
            events = self.do_test(lambda: do_change_twenty_four_hour_time(self.user_profile, twenty_four_hour_time))
 | 
			
		||||
        for setting_value in [False, True, False]:
 | 
			
		||||
            events = self.do_test(lambda: do_change_twenty_four_hour_time(self.user_profile, setting_value))
 | 
			
		||||
            error = schema_checker('events[0]', events[0])
 | 
			
		||||
            self.assert_on_error(error)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user