diff --git a/protzilla/disk_operator.py b/protzilla/disk_operator.py index 93a077eb..afd343f7 100644 --- a/protzilla/disk_operator.py +++ b/protzilla/disk_operator.py @@ -84,7 +84,6 @@ def write(file_path: Path, dataframe: pd.DataFrame): class KEYS: # We add this here to avoid typos and signal to the developer that accessing the keys should be done through this class only CURRENT_STEP_INDEX = "current_step_index" - FAVOURITE = "favourite" STEPS = "steps" STEP_OUTPUTS = "output" STEP_FORM_INPUTS = "form_inputs" @@ -124,7 +123,6 @@ def read_run(self, file: Path | None = None) -> StepManager: run.get(KEYS.CURRENT_STEP_INDEX, 0), len(step_manager.all_steps) - 1 ), ) - step_manager.favourite = run.get(KEYS.FAVOURITE, False) return step_manager def write_run(self, step_manager: StepManager) -> None: @@ -136,7 +134,6 @@ def write_run(self, step_manager: StepManager) -> None: self.clean_dataframes_dir(step_manager) run = {} run[KEYS.CURRENT_STEP_INDEX] = step_manager.current_step_index - run[KEYS.FAVOURITE] = step_manager.favourite run[KEYS.DF_MODE] = step_manager.df_mode run[KEYS.STEPS] = [] for step in step_manager.all_steps: diff --git a/protzilla/run.py b/protzilla/run.py index e11838cb..d35bcb1b 100644 --- a/protzilla/run.py +++ b/protzilla/run.py @@ -46,12 +46,12 @@ def get_available_runinfo() -> tuple[list[dict[str, str | list[str]]], list[dict for step in steps: step_names.append(step.display_name) - tags = set() metadata_yaml_path = os.path.join(directory_path, "metadata.yaml") if os.path.isfile(metadata_yaml_path): yaml_operator = YamlOperator() metadata = yaml_operator.read(metadata_yaml_path) - tags = metadata.get("tags") + tags = metadata.get("tags", set()) + favourite = metadata.get("favourite", False) for tag in tags: all_tags.add(tag) @@ -62,11 +62,11 @@ def get_available_runinfo() -> tuple[list[dict[str, str | list[str]]], list[dict "modification_date": datetime.datetime.fromtimestamp(modification_time).strftime("%d %m %Y"), "memory_mode": step_manager.df_mode, "run_steps" : step_names, - "favourite_status" : step_manager.favourite, + "favourite_status" : favourite, "run_tags": tags } - if step_manager.favourite: + if favourite: runs_favourited.append(run) else: runs.append(run) diff --git a/protzilla/steps.py b/protzilla/steps.py index b18f4b5e..eecf0d04 100644 --- a/protzilla/steps.py +++ b/protzilla/steps.py @@ -324,7 +324,6 @@ def __init__( self.df_mode = df_mode self.disk_operator = disk_operator self.current_step_index = 0 - self.favourite = False #might cause problems because of backwards-compatibility self.importing = [] self.data_preprocessing = [] self.data_analysis = [] diff --git a/ui/runs/views.py b/ui/runs/views.py index 1a3de726..a75418f0 100644 --- a/ui/runs/views.py +++ b/ui/runs/views.py @@ -222,12 +222,19 @@ def favourite(request: HttpRequest): else: favourite_status = True - disk_operator = DiskOperator(run_name, "dummy_workflow_name") directory_path = os.path.join(paths.RUNS_PATH, run_name) - yaml_path = os.path.join(directory_path, "run.yaml") - step_manager = disk_operator.read_run(yaml_path) - step_manager.favourite = not favourite_status - disk_operator.write_run(step_manager) + metadata_yaml_path = os.path.join(directory_path, "metadata.yaml") + + yaml_operator = YamlOperator() + metadata = {} + if not os.path.exists(metadata_yaml_path): + with open(metadata_yaml_path, 'w') as file: + pass + else: + metadata = yaml_operator.read(metadata_yaml_path) + + metadata["favourite"]= not metadata.get("favourite", False) + yaml_operator.write(Path(metadata_yaml_path), metadata) return HttpResponseRedirect(reverse("runs:index")) @@ -259,11 +266,8 @@ def add_tag(request: HttpRequest): metadata = yaml_operator.read(metadata_yaml_path) tags_from_metadata = metadata.get("tags") tags.update(tags_from_metadata) - print(tags) tags.add(run_tag) - print(tags) metadata["tags"]= tags - print(metadata) yaml_operator.write(Path(metadata_yaml_path), metadata) return HttpResponseRedirect(reverse("runs:index"))