Commit 54ad8da1 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Split sending the private and public protocol

/close #114
parent f371686f
...@@ -712,15 +712,27 @@ def publish_protocol(protocol): ...@@ -712,15 +712,27 @@ def publish_protocol(protocol):
db.session.commit() db.session.commit()
return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id)) return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id))
@app.route("/prococol/send/<int:protocol_id>") @app.route("/prococol/send/private/<int:protocol_id>")
@login_required @login_required
@db_lookup(Protocol) @db_lookup(Protocol)
@require_modify_right() @require_modify_right()
def send_protocol(protocol): def send_protocol_private(protocol):
if not config.MAIL_ACTIVE: if not config.MAIL_ACTIVE:
flash("Die Mailfunktion ist nicht aktiviert.", "alert-error") flash("Die Mailfunktion ist nicht aktiviert.", "alert-error")
return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol_id)) return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol_id))
tasks.send_protocol(protocol) tasks.send_protocol_private(protocol)
flash("Das Protokoll wurde versandt.", "alert-success")
return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id))
@app.route("/prococol/send/public/<int:protocol_id>")
@login_required
@db_lookup(Protocol)
@require_modify_right()
def send_protocol_public(protocol):
if not config.MAIL_ACTIVE:
flash("Die Mailfunktion ist nicht aktiviert.", "alert-error")
return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol_id))
tasks.send_protocol_public(protocol)
flash("Das Protokoll wurde versandt.", "alert-success") flash("Das Protokoll wurde versandt.", "alert-success")
return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id)) return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id))
......
...@@ -184,10 +184,8 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): ...@@ -184,10 +184,8 @@ def parse_protocol_async_inner(protocol, encoded_kwargs):
protocol.delete_orphan_todos() protocol.delete_orphan_todos()
db.session.commit() db.session.commit()
old_todos = list(protocol.todos) old_todos = list(protocol.todos)
for todo in old_todos:
protocol.todos.remove(todo)
db.session.commit()
todo_tags = [tag for tag in tags if tag.name == "todo"] todo_tags = [tag for tag in tags if tag.name == "todo"]
raw_todos = []
for todo_tag in todo_tags: for todo_tag in todo_tags:
if len(todo_tag.values) < 2: if len(todo_tag.values) < 2:
error = protocol.create_error("Parsing", "Invalid todo-tag", error = protocol.create_error("Parsing", "Invalid todo-tag",
...@@ -239,6 +237,15 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): ...@@ -239,6 +237,15 @@ def parse_protocol_async_inner(protocol, encoded_kwargs):
db.session.add(error) db.session.add(error)
db.session.commit() db.session.commit()
return return
raw_todos.append((who, what, field_id, field_state, field_date, todo_tag))
for (_, _, field_id, _, _, _) in raw_todos:
if field_id is not None:
old_todos = [todo for todo in old_todos
if todo.id != field_id]
for todo in old_todos:
protocol.todos.remove(todo)
db.session.commit()
for (who, what, field_id, field_state, field_date, todo_tag) in raw_todos:
if field_state is None: if field_state is None:
field_state = TodoState.open field_state = TodoState.open
if field_state.needs_date() and field_date is None: if field_state.needs_date() and field_date is None:
...@@ -255,7 +262,6 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): ...@@ -255,7 +262,6 @@ def parse_protocol_async_inner(protocol, encoded_kwargs):
if field_id is not None: if field_id is not None:
todo = Todo.query.filter_by(number=field_id).first() todo = Todo.query.filter_by(number=field_id).first()
if todo is None and not config.PARSER_LAZY: if todo is None and not config.PARSER_LAZY:
# TODO: add non-strict mode (at least for importing old protocols)
error = protocol.create_error("Parsing", error = protocol.create_error("Parsing",
"Invalid Todo ID", "Invalid Todo ID",
"The todo in line {} has the ID {}, but there is no " "The todo in line {} has the ID {}, but there is no "
...@@ -537,11 +543,13 @@ def send_reminder_async(reminder_id, protocol_id): ...@@ -537,11 +543,13 @@ def send_reminder_async(reminder_id, protocol_id):
print("sending private reminder mail to {}".format(protocol.protocoltype.private_mail)) print("sending private reminder mail to {}".format(protocol.protocoltype.private_mail))
send_mail(protocol, protocol.protocoltype.private_mail, "Tagesordnung der {}".format(protocol.protocoltype.name), reminder_text) send_mail(protocol, protocol.protocoltype.private_mail, "Tagesordnung der {}".format(protocol.protocoltype.name), reminder_text)
def send_protocol(protocol): def send_protocol_private(protocol):
send_protocol_async.delay(protocol.id, show_private=True) send_protocol_async.delay(protocol.id, show_private=True)
send_protocol_async.delay(protocol.id, show_private=False)
send_todomails_async.delay(protocol.id) send_todomails_async.delay(protocol.id)
def send_protocol_public(protocol):
send_protocol_async.delay(protocol.id, show_private=False)
@celery.task @celery.task
def send_protocol_async(protocol_id, show_private): def send_protocol_async(protocol_id, show_private):
with app.app_context(): with app.app_context():
......
...@@ -36,7 +36,10 @@ ...@@ -36,7 +36,10 @@
{% endif %} {% endif %}
{% else %} {% else %}
{% if config.MAIL_ACTIVE %} {% if config.MAIL_ACTIVE %}
<a class="btn btn-default" href="{{url_for("send_protocol", protocol_id=protocol.id)}}">Mail versenden</a> <a class="btn btn-default" href="{{url_for("send_protocol_private", protocol_id=protocol.id)}}">Intern versenden</a>
{% if protocol.public %}
<a class="btn btn-default" href="{{url_for("send_protocol_public", protocol_id=protocol.id)}}">Öffentlich versenden</a>
{% endif %}
{% endif %} {% endif %}
{% if not protocol.public %} {% if not protocol.public %}
<a class="btn btn-default" href="{{url_for("publish_protocol", protocol_id=protocol.id)}}">Veröffentlichen</a> <a class="btn btn-default" href="{{url_for("publish_protocol", protocol_id=protocol.id)}}">Veröffentlichen</a>
...@@ -153,7 +156,7 @@ ...@@ -153,7 +156,7 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% if content_html %} {% if content_html is not none %}
<div> <div>
<h3>Protokollinhalt</h3> <h3>Protokollinhalt</h3>
{{content_html|safe}} {{content_html|safe}}
......
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