Commit c160a9d0 authored by Administrator's avatar Administrator
Browse files

Fixed errors connected to importing the legacy

parent ac091dbd
...@@ -62,10 +62,10 @@ def import_old_protocols(sql_text): ...@@ -62,10 +62,10 @@ def import_old_protocols(sql_text):
deleted, sent, document_id) in _split_insert_line(protocol_line): deleted, sent, document_id) in _split_insert_line(protocol_line):
date = datetime.strptime(date, "%Y-%m-%d") date = datetime.strptime(date, "%Y-%m-%d")
handle = type_id_to_handle[int(old_type_id)] handle = type_id_to_handle[int(old_type_id)]
type = ProtocolType.query.filter(ProtocolType.short_name.ilike(handle)).first() protocoltype = ProtocolType.query.filter(ProtocolType.short_name.ilike(handle)).first()
if type is None: if protocoltype is None:
raise KeyError("No protocoltype for handle '{}'.".format(handle)) raise KeyError("No protocoltype for handle '{}'.".format(handle))
protocol = Protocol(type.id, date, source=source) protocol = Protocol(protocoltype.id, date, source=source)
db.session.add(protocol) db.session.add(protocol)
db.session.commit() db.session.commit()
import tasks import tasks
...@@ -73,6 +73,7 @@ def import_old_protocols(sql_text): ...@@ -73,6 +73,7 @@ def import_old_protocols(sql_text):
for protocol in sorted(protocols, key=lambda p: p.date): for protocol in sorted(protocols, key=lambda p: p.date):
print(protocol.date) print(protocol.date)
tasks.parse_protocol(protocol) tasks.parse_protocol(protocol)
print("done importing")
def import_old_todos(sql_text): def import_old_todos(sql_text):
...@@ -106,7 +107,7 @@ def import_old_todos(sql_text): ...@@ -106,7 +107,7 @@ def import_old_todos(sql_text):
for old_id, protocol_id, who, what, start_time, end_time, done in _split_insert_line(todo_line): for old_id, protocol_id, who, what, start_time, end_time, done in _split_insert_line(todo_line):
protocol_id = int(protocol_id) protocol_id = int(protocol_id)
if protocol_id not in protocol_id_to_key: if protocol_id not in protocol_id_to_key:
print("Missing protocol with ID {} for Todo {}".format(protocol_id, what)) #print("Missing protocol with ID {} for Todo {}".format(protocol_id, what))
continue continue
todo = OldTodo(old_id=old_id, who=who, description=what, todo = OldTodo(old_id=old_id, who=who, description=what,
protocol_key=protocol_id_to_key[protocol_id]) protocol_key=protocol_id_to_key[protocol_id])
......
...@@ -86,8 +86,8 @@ def import_legacy(): ...@@ -86,8 +86,8 @@ def import_legacy():
"""Import the old todos and protocols from an sql dump""" """Import the old todos and protocols from an sql dump"""
filename = prompt("SQL-file") filename = prompt("SQL-file")
#filename = "legacy.sql" #filename = "legacy.sql"
with open(filename, "r") as sqlfile: with open(filename, "rb") as sqlfile:
content = sqlfile.read() content = sqlfile.read().decode("utf-8")
import_old_todos(content) import_old_todos(content)
import_old_protocols(content) import_old_protocols(content)
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
{\bf Datum:} & \VAR{protocol.date|datify_long|escape_tex}\\ {\bf Datum:} & \VAR{protocol.date|datify_long|escape_tex}\\
\ENV{endif} \ENV{endif}
\ENV{for meta in protocol.metas} \ENV{for meta in protocol.metas}
{\bf \ENV{meta.name|escape_tex}:} & \VAR{meta.value|escape_tex}\\ {\bf \VAR{meta.name|escape_tex}:} & \VAR{meta.value|escape_tex}\\
\ENV{endfor} \ENV{endfor}
\end{tabular} \end{tabular}
\normalsize \normalsize
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment