From 495812a2a606988deefef1a52a32fdf40a28ddb5 Mon Sep 17 00:00:00 2001 From: winet Date: Sat, 3 Feb 2024 14:36:46 +0000 Subject: [PATCH] changing session --- app/blueprints/api/tasks/routes.py | 22 +++++++++++++++--- .../api/tasks/templates/tasks_cards.j2 | 23 +++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/app/blueprints/api/tasks/routes.py b/app/blueprints/api/tasks/routes.py index b0f94de..7ba6a79 100644 --- a/app/blueprints/api/tasks/routes.py +++ b/app/blueprints/api/tasks/routes.py @@ -12,8 +12,9 @@ tasks = Blueprint("tasks", __name__, url_prefix="/tasks", template_folder="templ @tasks.route("/", methods=["GET"]) def get_tasks(): tasks = Task.query.all() + sessions = Session.query.all() - return render_template("tasks_cards.j2", tasks=tasks) + return render_template("tasks_cards.j2", tasks=tasks, sessions=sessions) @tasks.route("/", methods=["GET"]) def get_task(task_id: int): @@ -62,7 +63,7 @@ def stop_task(task_id: int): case 'add': fn = add_to_group_task - if task.task_id: + if task.task_id and fn: task_fn = fn.AsyncResult(task.task_id) task_fn.abort() @@ -85,4 +86,19 @@ def start_task(task_id: int): case 'add': add_to_group_task.delay(task_id=task_id) - return 'Started', 200 \ No newline at end of file + return 'Started', 200 + +@tasks.route("//change", methods=["PUT"]) +def change_settings(task_id: int): + task: Task = Task.query.get_or_404(task_id) + data = request.form + + if data.get("session"): + task.session = Session.query.get(data.get("session")) + + if data.get("name"): + task.name = data.get("name") + + db.session.commit() + + return 'Changed', 200 \ No newline at end of file diff --git a/app/blueprints/api/tasks/templates/tasks_cards.j2 b/app/blueprints/api/tasks/templates/tasks_cards.j2 index 6335a33..b7bf46e 100644 --- a/app/blueprints/api/tasks/templates/tasks_cards.j2 +++ b/app/blueprints/api/tasks/templates/tasks_cards.j2 @@ -8,10 +8,29 @@
  • Статус: {{ task.status }}
  • Сообщение: {{ task.status_message }}
  • Действие: {{ task.type }}
  • -
  • Сессия: {{ task.session.name }}
  • + +
  • + + +
  • -
    +