Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete runs #537

Merged
merged 12 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.idea/
user_data/runs/*
user_data/workflows/*
user_data/external_data/*
user_data/debug/*
ui/static/admin/*
Expand Down
9 changes: 9 additions & 0 deletions protzilla/run_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import threading
import traceback

import os
import shutil

import protzilla.constants.paths as paths
from protzilla.steps import Messages, Output, Plots, Step
from protzilla.utilities import format_trace
Expand All @@ -18,6 +21,12 @@ def get_available_run_names() -> list[str]:
if not directory.name.startswith(".")
]

def delete_run_folder(run_name) -> None:
path = os.path.join(paths.RUNS_PATH, run_name)

if os.path.isdir(path):
shutil.rmtree(path)


class Run:
class ErrorHandlingContextManager:
Expand Down
99 changes: 56 additions & 43 deletions ui/runs/templates/runs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{% block content %}
<div class="container d-flex align-items-center justify-content-center" id="contain">
<div class="col" id="row">
<div class="col">
{% if messages %}
<div class="messages">
{% for message in messages %}
Expand All @@ -21,51 +21,64 @@
</div>
<br>
{% endif %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warum ist dieser messages Teil gelöscht?

<div class="row">
<div class="col mx-4">
<form action="{% url 'runs:create' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Work on a new run:</h3>
<input name="run_name" id="run_name" placeholder="Add run name" class="form-control">
</div>
<div class="mb-2">
<label for="workflow_config_name">With workflow:</label>
<select name="workflow_config_name" id="workflow_config_name" class="form-select">
{% for name in available_workflows %}
<option value="{{ name }}" {% if name == "standard" %} selected {% endif %}>{{ name }}</option>
{% endfor %}
</select>
</div>
<div class="mb-2">
<label for="df_mode">Memory mode:</label>
<select name="df_mode" id="df_mode" class="form-select">
<option value="disk_memory" selected >standard</option>
<option value="disk">low memory</option>
</select>
</div>
<input type="submit" value="Create" class="btn btn-red">
</form>
</div>

<div class="row">
<div class="col mx-4">
<form action="{% url 'runs:create' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Work on a new run:</h3>
<input name="run_name" id="run_name" placeholder="Add run name" class="form-control" required />
</div>
<div class="mb-2">
<label for="workflow_config_name">With workflow:</label>
<select name="workflow_config_name" id="workflow_config_name" class="form-select">
{% for name in available_workflows %}
<option value="{{ name }}" {% if name == "standard" %} selected {% endif %}>{{ name }}</option>
{% endfor %}
</select>
</div>
<div class="mb-2">
<label for="df_mode">Memory mode:</label>
<select name="df_mode" id="df_mode" class="form-select">
<option value="disk_memory" selected >standard</option>
<option value="disk">low memory</option>
</select>
</div>
<input type="submit" value="Create" class="btn btn-red">
</form>
</div>
<div class="col mx-4">
<form class="mb-5" action="{% url 'runs:continue' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Continue an existing run:</h3>
<select name="run_name" id="run_name_option" class="form-select">
{% for name in available_runs %}
<option value="{{ name }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<input type="submit" value="Continue" class="btn btn-red">
</form>
<a class="btn btn-grey" href="{% url 'databases' %}">Manage databases</a>
</div>

<div class="col mx-4">
<form class="mb-5" action="{% url 'runs:continue' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Continue an existing run:</h3>
<select name="run_name" id="run_name_option" class="form-select">
{% for name in available_runs %}
<option value="{{ name }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<input type="submit" value="Continue" class="btn btn-red">
</form>
<a class="btn btn-grey" href="{% url 'databases' %}">Manage databases</a>
</div>
<div class="col mx-4">
<form class="mb-5" action="{% url 'runs:delete' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Delete an existing run:</h3>
<select name="run_name" id="run_name_option" class="form-select">
{% for name in available_runs %}
<option value="{{ name }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<input type="submit" value="Delete" class="btn btn-red">
</form>
</div>
</div>
</div>

{% endblock %}
{% endblock %}
1 change: 1 addition & 0 deletions ui/runs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
path("", views.index, name="index"),
path("create", views.create, name="create"),
path("continue", views.continue_, name="continue"),
path("delete", views.delete_, name="delete"),
path("detail/<str:run_name>", views.detail, name="detail"),
path("<str:run_name>/plot", views.plot, name="plot"),
path("<str:run_name>/tables/<int:index>", views.tables, name="tables_nokey"),
Expand Down
36 changes: 34 additions & 2 deletions ui/runs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from django.shortcuts import render
from django.urls import reverse

from protzilla.run import Run, get_available_run_names
from protzilla.run import Run, get_available_run_names
from protzilla.run_v2 import delete_run_folder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zur Klasse run vs. run_v2 sollten wir mal das alte BP fragen, was warum wo verwendet wird und wo dann unsere Änderungen am ehesten rein gehören (ich hätte aber auch am ehesten in run_v2 geschrieben)

from protzilla.run_helper import log_messages
from protzilla.stepfactory import StepFactory
from protzilla.steps import Step
Expand Down Expand Up @@ -229,6 +230,37 @@ def continue_(request: HttpRequest):

return HttpResponseRedirect(reverse("runs:detail", args=(run_name,)))

def delete_(request: HttpRequest):
"""
Deletes an existing run. The user is redirected to the index page.

:param request: the request object
:type request: HttpRequest


:return: the rendered details page of the run
:rtype: HttpResponse
"""
run_name = request.POST["run_name"]
if run_name in active_runs:
del active_runs[run_name]

try:
delete_run_folder(run_name)
except Exception as e:
display_message(
{
"level": 40,
"msg": f"Couldn't delete the run '{run_name}' . Please check the permissions for this file or try running Protzilla as administrator.",
"trace": format_trace(traceback.format_exception(e)),
},
request,
)
traceback.print_exc()
return HttpResponseRedirect(reverse("runs:index"))

return HttpResponseRedirect(reverse("runs:index"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

voll schön geschrieben und an restliche File angepasst 💯



def next_(request, run_name):
"""
Expand All @@ -247,7 +279,7 @@ def next_(request, run_name):
run = active_runs[run_name]
name = request.POST.get("name", None)
if name:
run.steps.name_current_step_instance(name)
run.steps.name_current_step_instance(name)
run.step_next()

return HttpResponseRedirect(reverse("runs:detail", args=(run_name,)))
Expand Down
Loading