From baeab64f49e6bcc8b4e299cf9fbd67005c27b37a Mon Sep 17 00:00:00 2001 From: FSMPI Admin-Team <admin@fsmpi.rwth-aachen.de> Date: Fri, 3 Mar 2017 22:43:46 +0100 Subject: [PATCH] Reuse the old todo-id when recompiling a protocol --- tasks.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tasks.py b/tasks.py index 64000d7..903e34b 100644 --- a/tasks.py +++ b/tasks.py @@ -143,11 +143,15 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): db.session.commit() return # todos + old_todo_number_map = {} + for todo in protocol.todos: + old_todo_number_map[todo.description] = todo.get_id() protocol.delete_orphan_todos() db.session.commit() old_todos = list(protocol.todos) for todo in old_todos: protocol.todos.remove(todo) + print(old_todo_number_map) db.session.commit() tags = tree.get_tags() todo_tags = [tag for tag in tags if tag.name == "todo"] @@ -225,6 +229,12 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): db.session.add(error) db.session.commit() return + if todo is None and field_id is None and what in old_todo_number_map: + todo = Todo(type_id=protocol.protocoltype.id, + who=who, description=what, state=field_state, + date=field_date, number=old_todo_number_map[what]) + db.session.add(todo) + db.session.commit() if todo is None: protocol_key = protocol.get_identifier() old_candidates = OldTodo.query.filter( -- GitLab