@property
    @memoized
    def form(self):
        if self.request.method == "POST":
            form = SettingsForm(self.request.POST, cchq_domain=self.domain,
                cchq_is_previewer=self.previewer)
        else:
            domain_obj = Domain.get_by_name(self.domain, strict=True)
            enabled_disabled = lambda b: (ENABLED if b else DISABLED)
            default_custom = lambda b: (CUSTOM if b else DEFAULT)
            initial = {
                "use_default_sms_response":
                    enabled_disabled(domain_obj.use_default_sms_response),
                "default_sms_response":
                    domain_obj.default_sms_response,
                "use_restricted_sms_times":
                    enabled_disabled(len(domain_obj.restricted_sms_times) > 0),
                "restricted_sms_times_json":
                    [w.to_json() for w in domain_obj.restricted_sms_times],
                "send_to_duplicated_case_numbers":
                    enabled_disabled(domain_obj.send_to_duplicated_case_numbers),
                "use_custom_case_username":
                    default_custom(domain_obj.custom_case_username),
                "custom_case_username":
                    domain_obj.custom_case_username,
                "use_custom_message_count_threshold":
                    default_custom(
                        domain_obj.chat_message_count_threshold is not None),
                "custom_message_count_threshold":
                    domain_obj.chat_message_count_threshold,
                "use_sms_conversation_times":
                    enabled_disabled(len(domain_obj.sms_conversation_times) > 0),
                "sms_conversation_times_json":
                    [w.to_json() for w in domain_obj.sms_conversation_times],
                "sms_conversation_length":
                    domain_obj.sms_conversation_length,
                "survey_traffic_option":
                    (SHOW_ALL
                     if not domain_obj.filter_surveys_from_chat else
                     SHOW_INVALID
                     if domain_obj.show_invalid_survey_responses_in_chat else
                     HIDE_ALL),
                "count_messages_as_read_by_anyone":
                    enabled_disabled(domain_obj.count_messages_as_read_by_anyone),
                "use_custom_chat_template":
                    default_custom(domain_obj.custom_chat_template),
                "custom_chat_template":
                    domain_obj.custom_chat_template,
                "sms_case_registration_enabled":
                    enabled_disabled(domain_obj.sms_case_registration_enabled),
                "sms_case_registration_type":
                    domain_obj.sms_case_registration_type,
                "sms_case_registration_owner_id":
                    domain_obj.sms_case_registration_owner_id,
                "sms_case_registration_user_id":
                    domain_obj.sms_case_registration_user_id,
                "sms_mobile_worker_registration_enabled":
                    enabled_disabled(domain_obj.sms_mobile_worker_registration_enabled),
                "registration_welcome_message":
                    self.get_welcome_message_recipient(domain_obj),
            }
            form = SettingsForm(initial=initial, cchq_domain=self.domain,
                cchq_is_previewer=self.previewer)
        return form
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/sms/views.py/SMSSettingsView.form/original