Commit 30f6ab8d authored by Administrator's avatar Administrator
Browse files

Import todomails, hotfix since send_file currently does not work with uwsgi

parent 85470f2a
......@@ -2,14 +2,14 @@ from datetime import datetime
from fuzzywuzzy import fuzz, process
import tempfile
from models.database import Todo, OldTodo, Protocol, ProtocolType
from models.database import Todo, OldTodo, Protocol, ProtocolType, TodoMail
from shared import db
import config
def log_fuzzy(text):
with tempfile.NamedTemporaryFile(delete=False, mode="w") as tmpfile:
tmpfile.write(text + "\n\n")
#with tempfile.NamedTemporaryFile(delete=False, mode="w") as tmpfile:
# tmpfile.write(text + "\n\n")
def lookup_todo_id(old_candidates, new_who, new_description):
......@@ -40,6 +40,7 @@ def lookup_todo_id(old_candidates, new_who, new_description):
INSERT_PROTOCOLTYPE = "INSERT INTO `protocolManager_protocoltype`"
INSERT_PROTOCOL = "INSERT INTO `protocolManager_protocol`"
INSERT_TODO = "INSERT INTO `protocolManager_todo`"
INSERT_TODOMAIL = "INSERT INTO `protocolManager_todonamemailassignment`"
def import_old_protocols(sql_text):
protocoltype_lines = []
......@@ -73,6 +74,20 @@ def import_old_protocols(sql_text):
for protocol in sorted(protocols, key=lambda p:
def import_old_todomails(sql_text):
todomail_lines = []
for line in sql_text.splitlines():
if line.startswith(INSERT_TODOMAIL):
if len(todomail_lines) == 0:
raise ValueError("Necessary lines not found.")
for line in todomail_lines:
for assignment_id, name, mail in _split_insert_line(line):
todomail = TodoMail(name, mail)
print("done importing")
......@@ -2,7 +2,7 @@
import locale
locale.setlocale(locale.LC_TIME, "de_DE.utf8")
from flask import Flask, g, current_app, request, session, flash, redirect, url_for, abort, render_template, Response, send_file
from flask import Flask, g, current_app, request, session, flash, redirect, url_for, abort, render_template, Response#, send_file
from werkzeug.utils import secure_filename
from flask_script import Manager, prompt
from flask_migrate import Migrate, MigrateCommand
......@@ -17,6 +17,7 @@ from io import StringIO, BytesIO
import os
from datetime import datetime
import math
import mimetypes
import config
from shared import db, date_filter, datetime_filter, date_filter_long, date_filter_short, time_filter, ldap_manager, security_manager, current_user, check_login, login_required, group_required, class_filter, needs_date_test, todostate_name_filter, code_filter, indent_tab_filter
......@@ -24,7 +25,7 @@ from utils import is_past, mail_manager, url_manager, get_first_unused_int, set_
from models.database import ProtocolType, Protocol, DefaultTOP, TOP, Document, Todo, Decision, MeetingReminder, Error, TodoMail, DecisionDocument, TodoState, Meta, DefaultMeta
from views.forms import LoginForm, ProtocolTypeForm, DefaultTopForm, MeetingReminderForm, NewProtocolForm, DocumentUploadForm, KnownProtocolSourceUploadForm, NewProtocolSourceUploadForm, ProtocolForm, TopForm, SearchForm, NewProtocolFileUploadForm, NewTodoForm, TodoForm, TodoMailForm, DefaultMetaForm, MetaForm
from views.tables import ProtocolsTable, ProtocolTypesTable, ProtocolTypeTable, DefaultTOPsTable, MeetingRemindersTable, ErrorsTable, TodosTable, DocumentsTable, DecisionsTable, TodoTable, ErrorTable, TodoMailsTable, DefaultMetasTable
from legacy import import_old_todos, import_old_protocols
from legacy import import_old_todos, import_old_protocols, import_old_todomails
app = Flask(__name__)
......@@ -90,8 +91,14 @@ def import_legacy():
content ="utf-8")
# cause uwsgi currently has a bug
def send_file(file_like, cache_timeout, as_attachment, attachment_filename):
mimetype, _ = mimetypes.guess_type(attachment_filename)
response = Response(, mimetype)
response.headers["Content-Disposition"] = 'attachment; filename="{}"'.format(attachment_filename)
return response
def index():
......@@ -979,6 +986,9 @@ def download_document(document_id):
and not document.protocol.has_public_view_right(user))):
flash("Keine Berechtigung.", "alert-error")
return redirect(request.args.get("next") or url_for("index"))
#response = Response(document.as_file_like().read(), mimetype="application/pdf")
#response.headers["Content-Disposition"] = 'attachment; filename="{}"'.format(
#return response
return send_file(document.as_file_like(), cache_timeout=1, as_attachment=True,
@app.route("/document/upload/<int:protocol_id>", methods=["POST"])
Supports Markdown
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