diff --git a/models/database.py b/models/database.py index 5c529f3dbfa61895013d3df6247a77f25a4299b1..c731dfa94949621b6947af4540d08a5b4ce71b2a 100644 --- a/models/database.py +++ b/models/database.py @@ -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")) diff --git a/server.py b/server.py index f26a0700d5ac97f2647cd0b70603efb8726ebae7..9bb9361c3dee6d69a152dac8788df87c5e442409 100755 --- a/server.py +++ b/server.py @@ -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 diff --git a/templates/protocol-show.html b/templates/protocol-show.html index c0cf3d55aa50665ddc23d8eba574317167e7b825..c0609488731a91a3a8c66774be94598367fc8610 100644 --- a/templates/protocol-show.html +++ b/templates/protocol-show.html @@ -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> diff --git a/views/tables.py b/views/tables.py index 209531cf80484e13b3585c4a160fb00463b58ce0..763409a254e6412cf3fb4c3aabc7fdab6e57f6d8 100644 --- a/views/tables.py +++ b/views/tables.py @@ -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 ""]