Esempio n. 1
0
def update_display_settings_backend(request, user_profile,
                                    twenty_four_hour_time=REQ(validator=check_bool, default=None),
                                    default_language=REQ(validator=check_string, default=None),
                                    left_side_userlist=REQ(validator=check_bool, default=None)):
    # type: (HttpRequest, UserProfile, Optional[bool], Optional[str], Optional[bool]) -> HttpResponse
    if (default_language is not None and
            default_language not in get_available_language_codes()):
        raise JsonableError(_("Invalid language '%s'" % (default_language,)))

    result = {} # type: Dict[str, Any]
    if (default_language is not None and
            user_profile.default_language != default_language):
        do_change_default_language(user_profile, default_language)
        result['default_language'] = default_language

    elif (twenty_four_hour_time is not None and
            user_profile.twenty_four_hour_time != twenty_four_hour_time):
        do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time)
        result['twenty_four_hour_time'] = twenty_four_hour_time

    elif (left_side_userlist is not None and
            user_profile.left_side_userlist != left_side_userlist):
        do_change_left_side_userlist(user_profile, left_side_userlist)
        result['left_side_userlist'] = left_side_userlist

    return json_success(result)
Esempio n. 2
0
def update_display_settings_backend(request, user_profile,
                                    twenty_four_hour_time=REQ(validator=check_bool, default=None),
                                    default_language=REQ(validator=check_string, default=None),
                                    left_side_userlist=REQ(validator=check_bool, default=None),
                                    emoji_alt_code=REQ(validator=check_bool, default=None)):
    # type: (HttpRequest, UserProfile, Optional[bool], Optional[str], Optional[bool], Optional[bool]) -> HttpResponse
    if (default_language is not None and
            default_language not in get_available_language_codes()):
        raise JsonableError(_("Invalid language '%s'" % (default_language,)))

    result = {} # type: Dict[str, Any]
    if (default_language is not None and
            user_profile.default_language != default_language):
        do_change_default_language(user_profile, default_language)
        result['default_language'] = default_language

    elif (twenty_four_hour_time is not None and
            user_profile.twenty_four_hour_time != twenty_four_hour_time):
        do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time)
        result['twenty_four_hour_time'] = twenty_four_hour_time

    elif (left_side_userlist is not None and
            user_profile.left_side_userlist != left_side_userlist):
        do_change_left_side_userlist(user_profile, left_side_userlist)
        result['left_side_userlist'] = left_side_userlist

    elif (emoji_alt_code is not None and
            user_profile.emoji_alt_code != emoji_alt_code):
        do_change_emoji_alt_code(user_profile, emoji_alt_code)
        result['emoji_alt_code'] = emoji_alt_code

    return json_success(result)
Esempio n. 3
0
def json_time_setting(request, user_profile, twenty_four_hour_time=REQ(validator=check_bool, default=None)):
    result = {}
    if twenty_four_hour_time is not None and \
        user_profile.twenty_four_hour_time != twenty_four_hour_time:
        do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time)

    result['twenty_four_hour_time'] = twenty_four_hour_time

    return json_success(result)
Esempio n. 4
0
def json_time_setting(request, user_profile, twenty_four_hour_time=REQ(validator=check_bool, default=None)):
    result = {}
    if twenty_four_hour_time is not None and \
        user_profile.twenty_four_hour_time != twenty_four_hour_time:
        do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time)

    result['twenty_four_hour_time'] = twenty_four_hour_time

    return json_success(result)
Esempio n. 5
0
def json_time_setting(request, user_profile, twenty_four_hour_time=REQ(validator=check_bool, default=None)):
    # type: (HttpRequest, UserProfile, Optional[bool]) -> HttpResponse
    result = {}
    if twenty_four_hour_time is not None and \
        user_profile.twenty_four_hour_time != twenty_four_hour_time:
        do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time)

    result['twenty_four_hour_time'] = twenty_four_hour_time

    return json_success(result)
Esempio n. 6
0
def json_time_setting(request, user_profile, twenty_four_hour_time=REQ(validator=check_bool, default=None)):
    # type: (HttpRequest, UserProfile, Optional[bool]) -> HttpResponse
    result = {}
    if twenty_four_hour_time is not None and \
        user_profile.twenty_four_hour_time != twenty_four_hour_time:
        do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time)

    result['twenty_four_hour_time'] = twenty_four_hour_time

    return json_success(result)
Esempio n. 7
0
 def test_change_twenty_four_hour_time(self):
     schema_checker = check_dict([
         ('type', equals('update_display_settings')),
         ('setting_name', equals('twenty_four_hour_time')),
         ('user', check_string),
         ('setting', check_bool),
         ])
     # The first False is probably a noop, then we get transitions in both directions.
     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)
Esempio n. 8
0
 def test_change_twenty_four_hour_time(self):
     schema_checker = check_dict([
         ('type', equals('update_display_settings')),
         ('setting_name', equals('twenty_four_hour_time')),
         ('user', check_string),
         ('setting', check_bool),
         ])
     # The first False is probably a noop, then we get transitions in both directions.
     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)