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):
db.session.commit()
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
@db_lookup(Protocol)
@require_modify_right()
def send_protocol(protocol):
def send_protocol_private(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(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")
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):
protocol.delete_orphan_todos()
db.session.commit()
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"]
raw_todos = []
for todo_tag in todo_tags:
if len(todo_tag.values) < 2:
error = protocol.create_error("Parsing", "Invalid todo-tag",
......@@ -239,6 +237,15 @@ def parse_protocol_async_inner(protocol, encoded_kwargs):
db.session.add(error)
db.session.commit()
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:
field_state = TodoState.open
if field_state.needs_date() and field_date is None:
......@@ -255,7 +262,6 @@ def parse_protocol_async_inner(protocol, encoded_kwargs):
if field_id is not None:
todo = Todo.query.filter_by(number=field_id).first()
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",
"Invalid Todo ID",
"The todo in line {} has the ID {}, but there is no "
......@@ -537,11 +543,13 @@ def send_reminder_async(reminder_id, protocol_id):
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)
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=False)
send_todomails_async.delay(protocol.id)
def send_protocol_public(protocol):
send_protocol_async.delay(protocol.id, show_private=False)
@celery.task
def send_protocol_async(protocol_id, show_private):
with app.app_context():
......
......@@ -36,7 +36,10 @@
{% endif %}
{% else %}
{% 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 %}
{% if not protocol.public %}
<a class="btn btn-default" href="{{url_for("publish_protocol", protocol_id=protocol.id)}}">Veröffentlichen</a>
......@@ -153,7 +156,7 @@
{% endif %}
</div>
</div>
{% if content_html %}
{% if content_html is not none %}
<div>
<h3>Protokollinhalt</h3>
{{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