Esempio n. 1
0
def verify_inconsistency_in_system_variables(dbm, incoming_message_dict, language=None,
                                             is_account_wid_sms=False):
    if is_account_wid_sms:
        existing_message_list = account_wide_customized_message_details(dbm)
    else:
        existing_message_list = questionnaire_customized_message_details(dbm, language)

    existing_msg_dict = {}
    for msg_details in existing_message_list:
        existing_msg_dict.update({msg_details.get('code'): msg_details.get('message')})

    regex = re.compile("\{\<\{.*?\}\>\}")
    inconsistent_message_codes = []
    for code, message in incoming_message_dict.iteritems():
        modified_system_variable_list = regex.findall(message)
        existing_system_variable_list = regex.findall(existing_msg_dict[code])
        if not modified_system_variable_list == existing_system_variable_list:
            inconsistent_message_codes.append(code)

    corrected_message_list = []
    errored_msg_list = []
    if inconsistent_message_codes:
        corrected_message_list = existing_message_list
        for msg_details in corrected_message_list:
            msg_code = msg_details.get('code')
            if msg_code in inconsistent_message_codes:
                errored_msg_list.append(msg_code+":"+incoming_message_dict[msg_code])
                msg_details.update({'error': ugettext(ERROR_MSG_MISMATCHED_SYS_VARIABLE), 'valid': False})
    return corrected_message_list, errored_msg_list
Esempio n. 2
0
def _get_customized_message_for_language(dbm, language, message_code):
    reply_message_list = questionnaire_customized_message_details(
        dbm, language)
    return [
        reply_message['message'] for reply_message in reply_message_list
        if reply_message['code'] == message_code
    ][0]
Esempio n. 3
0
    def test_should_create_customized_message_dictionary(self):
        custom_messages = OrderedDict()
        custom_messages.update({"reply_success_submission": "Thank you for submission"})
        custom_messages.update({"reply_incorrect_answers": "Check your submission for errors"})
        custom_messages.update({"reply_incorrect_number_of_responses": "Your submission has incorrect number of answers"})
        custom_messages.update({"reply_identification_number_not_registered": "This identification number is not registered"})
        custom_messages.update({"reply_ds_not_authorized": "You are not authorized to send data"})

        DATA_FROM_DB = [{"id": "English", "key": "English",
                        "value": "English", "doc": {'_id': 'English', 'language_name': "English", 'messages':custom_messages}}]

        with patch.object(self.dbm, "load_all_rows_in_view") as load_all_rows_in_view:
            load_all_rows_in_view.return_value = DATA_FROM_DB

            details_list = questionnaire_customized_message_details(self.dbm, "English")

            self.assertEquals(details_list.__len__(),5)
            self.assertEquals(details_list[0],{"title":"Successful Submission","message":"Thank you for submission","code":"reply_success_submission"})
Esempio n. 4
0
 def get(self, request, *args, **kwargs):
     dbm = get_database_manager(request.user)
     return HttpResponse(json.dumps(questionnaire_customized_message_details(dbm, request.GET.get('language'))),
                         content_type="text/javascript")