(self, module)
Add a CommCare form of this form's item groups and items to a given CommCare module
Add a CommCare form of this form's item groups and items to a given CommCare module
Add a CommCare form of this form s item groups and items to a given CommCare module
def add_form_to_module(self, module):
        """
        Add a CommCare form of this form's item groups and items to a given CommCare module
        """
        def get_preload_action():
            preload = {
                '/data/start_date': 'start_date',
                '/data/start_time': 'start_time',
                '/data/end_date': 'end_date',
                '/data/end_time': 'end_time',
            }
            for item_group in self.iter_item_groups():
                for item in item_group.iter_items():
                    preload['/data/{}/{}'.format(
                        item_group.question_name,
                        item.question_name
                    )] = item.question_name
            return PreloadAction(
                preload=preload,
                condition=FormActionCondition(type='always')
            )

        def get_update_case_action():
            update = {
                'start_date': '/data/start_date',
                'start_time': '/data/start_time',
                'end_date': '/data/end_date',
                'end_time': '/data/end_time',
            }
            for item_group in self.iter_item_groups():
                for item in item_group.iter_items():
                    update[item.question_name] = '/data/{}/{}'.format(
                        item_group.question_name,
                        item.question_name
                    )
            return UpdateCaseAction(
                update=update,
                condition=FormActionCondition(type='always')
            )

        form = module.new_form(self.name, None)
        form.get_unique_id()
        form.source = self.build_xform()
        # Must require case for case list to work
        form.requires = 'case'
        form.actions.case_preload = get_preload_action()
        form.actions.update_case = get_update_case_action()
def add_form_to_module ( self , module ) : def get_preload_action ( ) : preload = { '/data/start_date' : 'start_date' , '/data/start_time' : 'start_time' , '/data/end_date' : 'end_date' , '/data/end_time' : 'end_time' , } for item_group in self . iter_item_groups ( ) : for item in item_group . iter_items ( ) : preload [ '/data/{}/{}' . format ( item_group . question_name , item . question_name ) ] = item . question_name return PreloadAction ( preload = preload , condition = FormActionCondition ( type = 'always' ) ) def get_update_case_action ( ) : update = { 'start_date' : '/data/start_date' , 'start_time' : '/data/start_time' , 'end_date' : '/data/end_date' , 'end_time' : '/data/end_time' , } for item_group in self . iter_item_groups ( ) : for item in item_group . iter_items ( ) : update [ item . question_name ] = '/data/{}/{}' . format ( item_group . question_name , item . question_name ) return UpdateCaseAction ( update = update , condition = FormActionCondition ( type = 'always' ) ) form = module . new_form ( self . name , None ) form . get_unique_id ( ) form . source = self . build_xform ( ) # Must require case for case list to work form . requires = 'case' form . actions . case_preload = get_preload_action ( ) form . actions . update_case = get_update_case_action ( )