def test_rename_variable_true(self): self.assertTrue(self.compare(self.formula1, self.formula2)) f3 = evaluation.rename_variable(self.formula1, 'Course_Code_a', 'Course_Code_b') self.assertTrue(self.compare(self.formula3, f3)) f3 = evaluation.rename_variable(self.formula1, 'Course_Code_b', 'Course_Code_a')
def rename_variable( self, old_name: str, new_name: str, ) -> None: """Rename a variable present in the action content. Two steps are performed. Rename the variable in the text_content, and rename the varaible in all the conditions. :param old_name: Old name of the variable :param new_name: New name of the variable :return: Updates the current object """ if self.text_content: # Need to change name appearances in content self.text_content = var_use_res[0].sub( lambda match: '{{ ' + (new_name if match.group('vname') == html.escape(old_name) else match.group('vname')) + ' }}', self.text_content, ) self.save() # Rename the variable in all conditions for cond in self.conditions.all(): cond.formula = evaluation.rename_variable(cond.formula, old_name, new_name) cond.save()
def rename_df_column( workflow, old_name: str, new_name: str, ): """Change the name of a column in the dataframe. :param workflow: workflow object that is handling the data frame :param old_name: old column name :param new_name: new column name :return: Workflow object updated """ # Rename the appearances of the variable in all actions for action_item in workflow.actions.prefetch_related('conditions').all(): action_item.rename_variable(old_name, new_name) # Rename the appearances of the variable in the formulas in the views for view in workflow.views.all(): view.formula = evaluation.rename_variable( view.formula, old_name, new_name) view.save()