예제 #1
0
def sms_settings(request, domain):
    domain_obj = Domain.get_by_name(domain, strict=True)
    is_previewer = request.couch_user.is_previewer()
    if request.method == "POST":
        form = SMSSettingsForm(request.POST)
        form._cchq_is_previewer = is_previewer
        if form.is_valid():
            domain_obj.use_default_sms_response = form.cleaned_data["use_default_sms_response"]
            domain_obj.default_sms_response = form.cleaned_data["default_sms_response"]
            if is_previewer:
                domain_obj.custom_case_username = form.cleaned_data["custom_case_username"]
                domain_obj.chat_message_count_threshold = form.cleaned_data["custom_message_count_threshold"]
                domain_obj.custom_chat_template = form.cleaned_data["custom_chat_template"]
            domain_obj.save()
            messages.success(request, _("Changes Saved."))
    else:
        initial = {
            "use_default_sms_response": domain_obj.use_default_sms_response,
            "default_sms_response": domain_obj.default_sms_response,
            "use_custom_case_username": domain_obj.custom_case_username is not None,
            "custom_case_username": domain_obj.custom_case_username,
            "use_custom_message_count_threshold": domain_obj.chat_message_count_threshold is not None,
            "custom_message_count_threshold": domain_obj.chat_message_count_threshold,
            "use_custom_chat_template": domain_obj.custom_chat_template is not None,
            "custom_chat_template": domain_obj.custom_chat_template,
        }
        form = SMSSettingsForm(initial=initial)

    context = {"domain": domain, "form": form, "is_previewer": is_previewer}
    return render(request, "sms/settings.html", context)
예제 #2
0
파일: views.py 프로젝트: wpride/commcare-hq
def sms_settings(request, domain):
    domain_obj = Domain.get_by_name(domain, strict=True)
    is_previewer = request.couch_user.is_previewer()
    if request.method == "POST":
        form = SMSSettingsForm(request.POST, _cchq_is_previewer=is_previewer)
        if form.is_valid():
            domain_obj.use_default_sms_response = form.cleaned_data["use_default_sms_response"]
            domain_obj.default_sms_response = form.cleaned_data["default_sms_response"]
            if settings.SMS_QUEUE_ENABLED:
                domain_obj.restricted_sms_times = form.cleaned_data["restricted_sms_times_json"]
            if is_previewer:
                domain_obj.custom_case_username = form.cleaned_data["custom_case_username"]
                domain_obj.chat_message_count_threshold = form.cleaned_data["custom_message_count_threshold"]
                domain_obj.custom_chat_template = form.cleaned_data["custom_chat_template"]
                domain_obj.filter_surveys_from_chat = form.cleaned_data["filter_surveys_from_chat"]
                domain_obj.show_invalid_survey_responses_in_chat = form.cleaned_data["show_invalid_survey_responses_in_chat"]
                domain_obj.count_messages_as_read_by_anyone = form.cleaned_data["count_messages_as_read_by_anyone"]
                domain_obj.send_to_duplicated_case_numbers = form.cleaned_data["send_to_duplicated_case_numbers"]
                if settings.SMS_QUEUE_ENABLED:
                    domain_obj.sms_conversation_times = form.cleaned_data["sms_conversation_times_json"]
                    domain_obj.sms_conversation_length = int(form.cleaned_data["sms_conversation_length"])
            domain_obj.save()
            messages.success(request, _("Changes Saved."))
    else:
        initial = {
            "use_default_sms_response" : domain_obj.use_default_sms_response,
            "default_sms_response" : domain_obj.default_sms_response,
            "use_custom_case_username" : domain_obj.custom_case_username is not None,
            "custom_case_username" : domain_obj.custom_case_username,
            "use_custom_message_count_threshold" : domain_obj.chat_message_count_threshold is not None,
            "custom_message_count_threshold" : domain_obj.chat_message_count_threshold,
            "use_custom_chat_template" : domain_obj.custom_chat_template is not None,
            "custom_chat_template" : domain_obj.custom_chat_template,
            "restricted_sms_times" : domain_obj.restricted_sms_times,
            "sms_conversation_times" : domain_obj.sms_conversation_times,
            "sms_conversation_length" : domain_obj.sms_conversation_length,
            "filter_surveys_from_chat" : domain_obj.filter_surveys_from_chat,
            "show_invalid_survey_responses_in_chat" : domain_obj.show_invalid_survey_responses_in_chat,
            "count_messages_as_read_by_anyone" : domain_obj.count_messages_as_read_by_anyone,
            "send_to_duplicated_case_numbers": domain_obj.send_to_duplicated_case_numbers,
        }
        form = SMSSettingsForm(initial=initial)

    context = {
        "domain" : domain,
        "form" : form,
        "is_previewer" : is_previewer,
        "sms_queue_enabled" : settings.SMS_QUEUE_ENABLED,
        'can_use_survey': can_use_survey_reminders(request),
    }
    return render(request, "sms/settings.html", context)