Commit 2d22bca3 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Differentiate between identifier and pad name

/close #98
parent 5941fee8
......@@ -230,6 +230,9 @@ class Protocol(DatabaseModel):
return self.pad_identifier
if self.date is None:
return None
return self.get_short_identifier()
def get_short_identifier(self):
return "{}-{}".format(
self.protocoltype.short_name.lower(),
self.date.strftime("%y-%m-%d"))
......
......@@ -90,7 +90,7 @@ def import_legacy():
def recompile_all():
for protocol in sorted(Protocol.query.all(), key=lambda p: p.date):
if protocol.is_done():
print(protocol.get_identifier())
print(protocol.get_short_identifier())
tasks.parse_protocol(protocol)
@manager.command
......@@ -514,7 +514,7 @@ def show_protocol(protocol):
@db_lookup(Protocol)
@require_modify_right()
def delete_protocol(protocol):
name = protocol.get_identifier()
name = protocol.get_short_identifier()
protocol.delete_orphan_todos()
db.session.delete(protocol)
db.session.commit()
......@@ -638,7 +638,7 @@ def recompile_protocol(protocol):
@require_modify_right()
def get_protocol_source(protocol):
file_like = BytesIO(protocol.source.encode("utf-8"))
return send_file(file_like, cache_timeout=1, as_attachment=True, attachment_filename="{}.txt".format(protocol.get_identifier()))
return send_file(file_like, cache_timeout=1, as_attachment=True, attachment_filename="{}.txt".format(protocol.get_short_identifier()))
@app.route("/protocol/template/<int:protocol_id>")
@login_required
......@@ -646,7 +646,7 @@ def get_protocol_source(protocol):
@require_modify_right()
def get_protocol_template(protocol):
file_like = BytesIO(protocol.get_template().encode("utf-8"))
return send_file(file_like, cache_timeout=1, as_attachment=True, attachment_filename="{}-template.txt".format(protocol.get_identifier()))
return send_file(file_like, cache_timeout=1, as_attachment=True, attachment_filename="{}-template.txt".format(protocol.get_short_identifier()))
@app.route("/protocol/etherpush/<int:protocol_id>")
@login_required
......
......@@ -44,7 +44,7 @@
{% endif %}
{% if has_admin_right %}
<a class="btn btn-default" href="{{url_for("recompile_protocol", protocol_id=protocol.id)}}">Neu kompilieren</a>
<a class="btn btn-danger" href="{{url_for("delete_protocol", protocol_id=protocol.id)}}" onclick="return confirm('Bist du dir sicher, dass du das Protokoll {{protocol.get_identifier()}} löschen möchtest?');">Löschen</a>
<a class="btn btn-danger" href="{{url_for("delete_protocol", protocol_id=protocol.id)}}" onclick="return confirm('Bist du dir sicher, dass du das Protokoll {{protocol.get_short_identifier()}} löschen möchtest?');">Löschen</a>
{% endif %}
{% endif %}
</div>
......
......@@ -102,7 +102,7 @@ class ProtocolsTable(Table):
if user is not None and protocol.protocoltype.has_private_view_right(user):
result.append(Table.link(url_for("show_type", protocoltype_id=protocol.protocoltype.id), protocol.protocoltype.short_name))
if protocol.protocoltype.has_admin_right(user):
result.append(Table.link(url_for("delete_protocol", protocol_id=protocol.id), "Löschen", confirm="Bist du dir sicher, dass du das Protokoll {} löschen möchtest?".format(protocol.get_identifier())))
result.append(Table.link(url_for("delete_protocol", protocol_id=protocol.id), "Löschen", confirm="Bist du dir sicher, dass du das Protokoll {} löschen möchtest?".format(protocol.get_short_identifier())))
else:
result.append("")
else:
......@@ -137,7 +137,7 @@ class ProtocolTypesTable(Table):
mobile_name = "{} ({})".format(protocoltype.name, protocoltype.short_name)
mobile_links = []
if protocol is not None:
mobile_links.append(Table.link(protocol_link, protocol.get_identifier()))
mobile_links.append(Table.link(protocol_link, protocol.get_short_identifier()))
if has_modify_right:
mobile_links.append(Table.link(new_protocol_link, "Neues Protokoll"))
mobile_part = [
......@@ -147,7 +147,7 @@ class ProtocolTypesTable(Table):
desktop_part = [
Table.link(protocoltype_link, protocoltype.short_name) if has_private_view_right else protocoltype.short_name,
protocoltype.name,
Table.link(protocol_link, protocol.get_identifier()) if protocol is not None else "Noch kein Protokoll",
Table.link(protocol_link, protocol.get_short_identifier()) if protocol is not None else "Noch kein Protokoll",
Table.link(new_protocol_link, "Neues Protokoll") if has_modify_right else ""
"" # TODO: add link for modify, delete
]
......@@ -291,7 +291,7 @@ class ErrorsTable(Table):
def row(self, error):
return [
Table.link(url_for("show_protocol", protocol_id=error.protocol.id), error.protocol.get_identifier()),
Table.link(url_for("show_protocol", protocol_id=error.protocol.id), error.protocol.get_short_identifier()),
error.action,
Table.link(url_for("show_error", error_id=error.id), error.name),
datetime_filter(error.datetime),
......@@ -308,7 +308,7 @@ class ErrorTable(SingleValueTable):
def row(self):
return [
Table.link(url_for("show_protocol", protocol_id=self.value.protocol.id), self.value.protocol.get_identifier()),
Table.link(url_for("show_protocol", protocol_id=self.value.protocol.id), self.value.protocol.get_short_identifier()),
self.value.action,
self.value.name,
datetime_filter(self.value.datetime)
......@@ -335,7 +335,7 @@ class TodosTable(Table):
Markup("<br>").join(mobile_parts),
Table.link(url_for("show_todo", todo_id=todo.id), todo.get_id()),
todo.get_state(),
Table.link(url_for("show_protocol", protocol_id=protocol.id), protocol.get_identifier())
Table.link(url_for("show_protocol", protocol_id=protocol.id), protocol.get_short_identifier())
if protocol is not None
else Table.link(url_for("list_protocols", protocoltype_id=todo.protocoltype.id), todo.protocoltype.short_name),
todo.who,
......@@ -364,7 +364,7 @@ class TodoTable(SingleValueTable):
self.value.get_id(),
self.value.get_state_plain(),
Table.concat([
Table.link(url_for("show_protocol", protocol_id=protocol.id), protocol.get_identifier())
Table.link(url_for("show_protocol", protocol_id=protocol.id), protocol.get_short_identifier())
for protocol in self.value.protocols
]),
self.value.who,
......@@ -398,7 +398,7 @@ class DecisionsTable(Table):
def row(self, decision):
user = current_user()
content_part = [
Table.link(url_for("show_protocol", protocol_id=decision.protocol.id), decision.protocol.get_identifier()),
Table.link(url_for("show_protocol", protocol_id=decision.protocol.id), decision.protocol.get_short_identifier()),
decision.content
]
category_part = [decision.category.name if decision.category is not None else ""]
......
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