Ejemplo n.º 1
0
 def page_context(self):
     context = super(AppFormSummaryView, self).page_context
     modules, errors = get_form_data(self.domain, self.app, include_shadow_forms=False)
     context.update({
         'is_form_summary': True,
         'modules': modules,
         'errors': errors,
     })
     return context
Ejemplo n.º 2
0
 def get(self, request, *args, **kwargs):
     modules, errors = get_form_data(self.domain, self.app, include_shadow_forms=False)
     return json_response({
         'response': {
             'form_data': {
                 'modules': modules,
                 'errors': errors,
             },
             'case_data': self.app.get_case_metadata().to_json(),
             'form_name_map': _get_name_map(self.app),
         },
         'success': True,
     })
Ejemplo n.º 3
0
    def test_advanced_form_get_action_type(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        form = app.new_form(0, "Untitled Form", None)
        form.xmlns = 'http://id_m1-f0'
        form.actions.load_update_cases.append(LoadUpdateAction(case_type="clinic", case_tag='load_0'))

        modules, errors = util.get_form_data('domain', app)
        self.assertEqual(modules[0]['forms'][0]['action_type'], 'load (load_0)')
Ejemplo n.º 4
0
 def get(self, request, *args, **kwargs):
     modules, errors = get_form_data(self.domain,
                                     self.app,
                                     include_shadow_forms=False)
     return json_response({
         'response': {
             'form_data': {
                 'modules': modules,
                 'errors': errors,
             },
             'case_data': self.app.get_case_metadata().to_json(),
             'form_name_map': _get_name_map(self.app),
         },
         'success': True,
     })
Ejemplo n.º 5
0
    def test_advanced_form_get_action_type(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(
            AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        form = app.new_form(0, "Untitled Form", None)
        form.xmlns = 'http://id_m1-f0'
        form.actions.load_update_cases.append(
            LoadUpdateAction(case_type="clinic", case_tag='load_0'))

        modules, errors = util.get_form_data('domain', app)
        self.assertEqual(modules[0]['forms'][0]['action_type'],
                         'load (load_0)')
Ejemplo n.º 6
0
    def test_default_followup_form(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        context = {
            'lang': None,
            'default_label': "Default label message"
        }
        attachment = get_default_followup_form_xml(context=context)
        followup = app.new_form(0, "Followup Form", None, attachment=attachment)

        modules, _ = util.get_form_data('domain', app)
        self.assertEqual(followup.name['en'], "Followup Form")
        self.assertEqual(modules[0]['forms'][0]['name']['en'], "Followup Form")
        self.assertEqual(modules[0]['forms'][0]['questions'][0]['label'], " Default label message ")
Ejemplo n.º 7
0
    def test_default_followup_form(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(
            AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        context = {'lang': None, 'default_label': "Default label message"}
        attachment = get_default_followup_form_xml(context=context)
        followup = app.new_form(0,
                                "Followup Form",
                                None,
                                attachment=attachment)

        modules, _ = util.get_form_data('domain', app)
        self.assertEqual(followup.name['en'], "Followup Form")
        self.assertEqual(modules[0]['forms'][0]['name']['en'], "Followup Form")
        self.assertEqual(modules[0]['forms'][0]['questions'][0]['label'],
                         " Default label message ")
Ejemplo n.º 8
0
    def _get_labels_to_skip(self):
        """Returns the labels of questions that have the skip string in the comment,
        so that those labels are not sent to transifex later.

        If there are questions that share the same label reference (and thus the
        same translation), they will be included if any question does not have the
        skip string.
        """
        def _labels_from_question(question):
            ret = {
                question.get('label_ref'),
                question.get('constraintMsg_ref'),
            }
            if question.get('options'):
                for option in question['options']:
                    ret.add(option.get('label_ref'))
            return ret

        labels_to_skip = defaultdict(set)
        necessary_labels = defaultdict(set)
        module_data, errors = get_form_data(self.domain, self.app)

        for module in module_data:
            for form in module['forms']:
                for question in form['questions']:
                    if not question.get('label_ref'):
                        continue
                    if question['comment'] and SKIP_TRANSFEX_STRING in question[
                            'comment']:
                        labels_to_skip[form['id']] |= _labels_from_question(
                            question)
                    else:
                        necessary_labels[form['id']] |= _labels_from_question(
                            question)

        for form_id in labels_to_skip.keys():
            labels_to_skip[
                form_id] = labels_to_skip[form_id] - necessary_labels[form_id]

        return labels_to_skip
Ejemplo n.º 9
0
    def _get_labels_to_skip(self):
        """Returns the labels of questions that have the skip string in the comment,
        so that those labels are not sent to transifex later.

        If there are questions that share the same label reference (and thus the
        same translation), they will be included if any question does not have the
        skip string.
        """
        def _labels_from_question(question):
            ret = {
                question.get('label_ref'),
                question.get('constraintMsg_ref'),
            }
            if question.get('options'):
                for option in question['options']:
                    ret.add(option.get('label_ref'))
            return ret

        labels_to_skip = defaultdict(set)
        necessary_labels = defaultdict(set)
        module_data, errors = get_form_data(self.domain, self.app)

        for module in module_data:
            for form in module['forms']:
                for question in form['questions']:
                    if not question.get('label_ref'):
                        continue
                    if question['comment'] and SKIP_TRANSFEX_STRING in question['comment']:
                        labels_to_skip[form['id']] |= _labels_from_question(question)
                    else:
                        necessary_labels[form['id']] |= _labels_from_question(question)

        for form_id in labels_to_skip.keys():
            labels_to_skip[form_id] = labels_to_skip[form_id] - necessary_labels[form_id]

        return labels_to_skip