diff --git a/decorators.py b/decorators.py new file mode 100644 index 0000000000000000000000000000000000000000..a51c2141700396d82150c28b1d5ce5519cf797cc --- /dev/null +++ b/decorators.py @@ -0,0 +1,33 @@ +from flask import redirect, flash, request + +from functools import wraps + +ID_KEY = "id" +KEY_NOT_PRESENT_MESSAGE = "Missing {}_id." +OBJECT_DOES_NOT_EXIST_MESSAGE = "There is no {} with id {}." + +def default_redirect(): + return redirect(request.args.get("next") or url_for("index")) + +def db_lookup(*models, check_exists=True): + def _decorator(function): + @wraps(function) + def _decorated_function(*args, **kwargs): + for model in models: + key = model.__object_name__ + id_key = "{}_{}".format(key, ID_KEY) + if id_key not in kwargs: + flash(KEY_NOT_PRESENT_MESSAGE.format(key), "alert-error") + return default_redirect() + obj_id = kwargs[id_key] + obj = model.query.filter_by(id=obj_id).first() + if check_exists and obj is None: + model_name = model.__class__.__name__ + flash(OBJECT_DOES_NOT_EXIST_MESSAGE.format(model_name, obj_id), + "alert-error") + return default_redirect() + kwargs[key] = obj + kwargs.pop(id_key) + return function(*args, **kwargs) + return _decorated_function + return _decorator diff --git a/models/database.py b/models/database.py index 1399dadbac158d03918dccd87b5bf52e6fdc8240..a2b89b6a138b9d115bf48449e88e1f2e7b330286 100644 --- a/models/database.py +++ b/models/database.py @@ -20,6 +20,7 @@ from todostates import make_states class ProtocolType(db.Model): __tablename__ = "protocoltypes" + __object_name__ = "protocoltype" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, unique=True) short_name = db.Column(db.String, unique=True) @@ -139,6 +140,7 @@ class ProtocolType(db.Model): class Protocol(db.Model): __tablename__ = "protocols" + __object_name__ = "protocol" id = db.Column(db.Integer, primary_key=True) protocoltype_id = db.Column(db.Integer, db.ForeignKey("protocoltypes.id")) source = db.Column(db.String) @@ -303,6 +305,7 @@ def on_protocol_delete(mapper, connection, protocol): class DefaultTOP(db.Model): __tablename__ = "defaulttops" + __object_name__ = "defaulttop" id = db.Column(db.Integer, primary_key=True) protocoltype_id = db.Column(db.Integer, db.ForeignKey("protocoltypes.id")) name = db.Column(db.String) @@ -322,6 +325,7 @@ class DefaultTOP(db.Model): class TOP(db.Model): __tablename__ = "tops" + __object_name__ = "top" id = db.Column(db.Integer, primary_key=True) protocol_id = db.Column(db.Integer, db.ForeignKey("protocols.id")) name = db.Column(db.String) @@ -342,6 +346,7 @@ class TOP(db.Model): class Document(db.Model): __tablename__ = "documents" + __object_name__ = "document" id = db.Column(db.Integer, primary_key=True) protocol_id = db.Column(db.Integer, db.ForeignKey("protocols.id")) name = db.Column(db.String) @@ -376,6 +381,7 @@ def on_document_delete(mapper, connection, document): class DecisionDocument(db.Model): __tablename__ = "decisiondocuments" + __object_name__ = "decisiondocument" id = db.Column(db.Integer, primary_key=True) decision_id = db.Column(db.Integer, db.ForeignKey("decisions.id")) name = db.Column(db.String) @@ -483,6 +489,7 @@ class TodoState(Enum): class Todo(db.Model): __tablename__ = "todos" + __object_name__ = "todo" id = db.Column(db.Integer, primary_key=True) protocoltype_id = db.Column(db.Integer, db.ForeignKey("protocoltypes.id")) number = db.Column(db.Integer) @@ -582,6 +589,7 @@ class TodoProtocolAssociation(db.Model): class Decision(db.Model): __tablename__ = "decisions" + __object_name__ = "decision" id = db.Column(db.Integer, primary_key=True) protocol_id = db.Column(db.Integer, db.ForeignKey("protocols.id")) content = db.Column(db.String) @@ -598,6 +606,7 @@ class Decision(db.Model): class MeetingReminder(db.Model): __tablename__ = "meetingreminders" + __object_name__ = "meetingreminder" id = db.Column(db.Integer, primary_key=True) protocoltype_id = db.Column(db.Integer, db.ForeignKey("protocoltypes.id")) days_before = db.Column(db.Integer) @@ -618,6 +627,7 @@ class MeetingReminder(db.Model): class Error(db.Model): __tablename__ = "errors" + __object_name__ = "error" id = db.Column(db.Integer, primary_key=True) protocol_id = db.Column(db.Integer, db.ForeignKey("protocols.id")) action = db.Column(db.String) @@ -644,6 +654,7 @@ class Error(db.Model): class TodoMail(db.Model): __tablename__ = "todomails" + __object_name__ = "todomail" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, unique=True) mail = db.Column(db.String) @@ -661,6 +672,7 @@ class TodoMail(db.Model): class OldTodo(db.Model): __tablename__ = "oldtodos" + __object_name__ = "oldtodo" id = db.Column(db.Integer, primary_key=True) old_id = db.Column(db.Integer) who = db.Column(db.String) @@ -680,6 +692,7 @@ class OldTodo(db.Model): class DefaultMeta(db.Model): __tablename__ = "defaultmetas" + __object_name__ = "defaultmeta" id = db.Column(db.Integer, primary_key=True) protocoltype_id = db.Column(db.Integer, db.ForeignKey("protocoltypes.id")) key = db.Column(db.String) @@ -696,6 +709,7 @@ class DefaultMeta(db.Model): class Meta(db.Model): __tablename__ = "metas" + __object_name__ = "meta" id = db.Column(db.Integer, primary_key=True) protocol_id = db.Column(db.Integer, db.ForeignKey("protocols.id")) name = db.Column(db.String) diff --git a/server.py b/server.py index 84559ee4f0d5bcfa94834671a72aeae3e7531246..22fd908c94d8773dd64ab8ea890ea81f6acedf89 100755 --- a/server.py +++ b/server.py @@ -22,6 +22,7 @@ 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 from utils import is_past, mail_manager, url_manager, get_first_unused_int, set_etherpad_text, get_etherpad_text, split_terms, optional_int_arg +from decorators import db_lookup 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 @@ -185,13 +186,10 @@ def new_type(): return redirect(request.args.get("next") or url_for("list_types")) return render_template("type-new.html", form=form) -@app.route("/type/edit/<int:type_id>", methods=["GET", "POST"]) +@app.route("/type/edit/<int:protocoltype_id>", methods=["GET", "POST"]) @login_required -def edit_type(type_id): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(ProtocolType) +def edit_type(protocoltype): user = current_user() if not protocoltype.has_private_view_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") @@ -203,16 +201,13 @@ def edit_type(type_id): else: form.populate_obj(protocoltype) db.session.commit() - return redirect(request.args.get("next") or url_for("show_type", type_id=protocoltype.id)) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=protocoltype.id)) return render_template("type-edit.html", form=form, protocoltype=protocoltype) -@app.route("/type/show/<int:type_id>") +@app.route("/type/show/<int:protocoltype_id>") @login_required -def show_type(type_id): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(ProtocolType) +def show_type(protocoltype): user = current_user() if not protocoltype.has_private_view_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") @@ -223,164 +218,123 @@ def show_type(type_id): metas_table = DefaultMetasTable(protocoltype.metas, protocoltype) return render_template("type-show.html", protocoltype=protocoltype, protocoltype_table=protocoltype_table, default_tops_table=default_tops_table, metas_table=metas_table, reminders_table=reminders_table, mail_active=config.MAIL_ACTIVE) -@app.route("/type/delete/<int:type_id>") +@app.route("/type/delete/<int:protocoltype_id>") @login_required @group_required(config.ADMIN_GROUP) -def delete_type(type_id): +@db_lookup(ProtocolType) +def delete_type(protocoltype): user = current_user() - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None or not protocoltype.has_modify_right(user): - flash("Invalider Protokolltyp oder fehlende Zugriffsrechte.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) + if not protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") + return redirect(reqeust.args.get("next") or url_for("index")) name = protocoltype.name db.session.delete(protocoltype) db.session.commit() flash("Der Protokolltype {} wurde gelöscht.".format(name), "alert-success") return redirect(request.args.get("next") or url_for("list_types")) -@app.route("/type/reminders/new/<int:type_id>", methods=["GET", "POST"]) +@app.route("/type/reminders/new/<int:protocoltype_id>", methods=["GET", "POST"]) @login_required -def new_reminder(type_id): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(ProtocolType) +def new_reminder(protocoltype): user = current_user() if not protocoltype.has_modify_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) form = MeetingReminderForm() if form.validate_on_submit(): - reminder = MeetingReminder(protocoltype.id, form.days_before.data, form.send_public.data, form.send_private.data, form.additional_text.data) - db.session.add(reminder) + meetingreminder = MeetingReminder(protocoltype.id, form.days_before.data, form.send_public.data, form.send_private.data, form.additional_text.data) + db.session.add(meetingreminder) db.session.commit() - return redirect(request.args.get("next") or url_for("show_type", type_id=protocoltype.id)) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=protocoltype.id)) return render_template("reminder-new.html", form=form, protocoltype=protocoltype) -@app.route("/type/reminder/edit/<int:type_id>/<int:reminder_id>", methods=["GET", "POST"]) +@app.route("/type/reminder/edit/<int:meetingreminder_id>", methods=["GET", "POST"]) @login_required -def edit_reminder(type_id, reminder_id): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(MeetingReminder) +def edit_reminder(meetingreminder): user = current_user() - if not protocoltype.has_modify_right(user): + if not meetingreminder.protocoltype.has_modify_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) - reminder = MeetingReminder.query.filter_by(id=reminder_id).first() - if reminder is None or reminder.protocoltype != protocoltype: - flash("Invalide Erinnerung.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) - form = MeetingReminderForm(obj=reminder) + form = MeetingReminderForm(obj=meetingreminder) if form.validate_on_submit(): - form.populate_obj(reminder) + form.populate_obj(meetingreminder) db.session.commit() - return redirect(request.args.get("next") or url_for("show_type", type_id=protocoltype.id)) - return render_template("reminder-edit.html", form=form, protocoltype=protocoltype, reminder=reminder) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=protocoltype.id)) + return render_template("reminder-edit.html", form=form, protocoltype=protocoltype, meetingreminder=meetingreminder) -@app.route("/type/reminder/delete/<int:type_id>/<int:reminder_id>") +@app.route("/type/reminder/delete/<int:meetingreminder_id>") @login_required -def delete_reminder(type_id, reminder_id): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(MeetingReminder) +def delete_reminder(meetingreminder): user = current_user() - if not protocoltype.has_modify_right(user): + if not meetingreminder.protocoltype.has_modify_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) - reminder = MeetingReminder.query.filter_by(id=reminder_id).first() - if reminder is None or reminder.protocoltype != protocoltype: - flash("Invalide Erinnerung.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) - db.session.delete(reminder) + protocoltype = meetingreminder.protocoltype + db.session.delete(meetingreminder) db.session.commit() - return redirect(request.args.get("next") or url_for("show_type", type_id=protocoltype.id)) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=protocoltype.id)) -@app.route("/type/tops/new/<int:type_id>", methods=["GET", "POST"]) +@app.route("/type/tops/new/<int:protocoltype_id>", methods=["GET", "POST"]) @login_required -def new_default_top(type_id): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(ProtocolType) +def new_default_top(protocoltype): user = current_user() if not protocoltype.has_modify_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) form = DefaultTopForm() if form.validate_on_submit(): - default_top = DefaultTOP(protocoltype.id, form.name.data, form.number.data) - db.session.add(default_top) + defaulttop = DefaultTOP(protocoltype.id, form.name.data, form.number.data) + db.session.add(defaulttop) db.session.commit() - flash("Der Standard-TOP {} wurde für dem Protokolltyp {} hinzugefügt.".format(default_top.name, protocoltype.name), "alert-success") + flash("Der Standard-TOP {} wurde für dem Protokolltyp {} hinzugefügt.".format(defaulttop.name, protocoltype.name), "alert-success") return redirect(request.args.get("next") or url_for("index")) return render_template("default-top-new.html", form=form, protocoltype=protocoltype) -@app.route("/type/tops/edit/<int:type_id>/<int:top_id>", methods=["GET", "POST"]) +@app.route("/type/tops/edit/<int:protocoltype_id>/<int:defaulttop_id>", methods=["GET", "POST"]) @login_required -def edit_default_top(type_id, top_id): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(ProtocolType, DefaultTOP) +def edit_default_top(protocoltype, defaulttop): user = current_user() if not protocoltype.has_modify_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) - default_top = DefaultTOP.query.filter_by(id=top_id).first() - if default_top is None or default_top.protocoltype != protocoltype: - flash("Invalider Standard-TOP.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) - form = DefaultTopForm(obj=default_top) + form = DefaultTopForm(obj=defaulttop) if form.validate_on_submit(): - form.populate_obj(default_top) + form.populate_obj(defaulttop) db.session.commit() - return redirect(request.args.get("next") or url_for("show_type", type_id=protocoltype.id)) - return render_template("default-top-edit.html", form=form, protocoltype=protocoltype, default_top=default_top) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=protocoltype.id)) + return render_template("default-top-edit.html", form=form, protocoltype=protocoltype, defaulttop=defaulttop) -@app.route("/type/tops/delete/<int:type_id>/<int:top_id>") +@app.route("/type/tops/delete/<int:defaulttop_id>") @login_required -def delete_default_top(type_id, top_id): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(DefaultTOP) +def delete_default_top(defaulttop): user = current_user() - if not protocoltype.has_modify_right(user): + if not defaulttop.protocoltype.has_modify_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) - default_top = DefaultTOP.query.filter_by(id=top_id).first() - if default_top is None or default_top.protocoltype != protocoltype: - flash("Invalider Standard-TOP.", "alert-error") - return redirect(request.args.get("nexT") or url_for("index")) - db.session.delete(default_top) + db.session.delete(defaulttop) db.session.commit() - return redirect(request.args.get("next") or url_for("show_type", type_id=protocoltype.id)) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=protocoltype.id)) -@app.route("/type/tops/move/<int:type_id>/<int:top_id>/<diff>/") +@app.route("/type/tops/move/<int:defaulttop_id>/<diff>/") @login_required -def move_default_top(type_id, top_id, diff): - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None: - flash("Dieser Protokolltyp existiert nicht.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) +@db_lookup(DefaultTOP) +def move_default_top(defaulttop, diff): user = current_user() - if not protocoltype.has_modify_right(user): + if not defaulttop.protocoltype.has_modify_right(user): flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) - default_top = DefaultTOP.query.filter_by(id=top_id).first() - if default_top is None or default_top.protocoltype != protocoltype: - flash("Invalider Standard-TOP.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) try: - default_top.number += int(diff) + defaulttop.number += int(diff) db.session.commit() except ValueError: flash("Die angegebene Differenz ist keine Zahl.", "alert-error") - return redirect(request.args.get("next") or url_for("show_type", type_id=protocoltype.id)) - + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=defaulttop.protocoltype.id)) @app.route("/protocols/list") def list_protocols(): @@ -504,11 +458,11 @@ def new_protocol(): return render_template("protocol-new.html", form=form, upload_form=upload_form, file_upload_form=file_upload_form, protocoltypes=protocoltypes) @app.route("/protocol/show/<int:protocol_id>") -def show_protocol(protocol_id): +@db_lookup(Protocol) +def show_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_public_view_right(user): - flash("Invalides Protokoll oder fehlende Zugriffsrechte.", "alert-error") + if not protocol.protocoltype.has_public_view_right(user): + flash("Die fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) errors_table = ErrorsTable(protocol.errors) visible_documents = [ @@ -524,11 +478,11 @@ def show_protocol(protocol_id): @app.route("/protocol/delete/<int:protocol_id>") @login_required @group_required(config.ADMIN_GROUP) -def delete_protocol(protocol_id): +@db_lookup(Protocol) +def delete_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) name = protocol.get_identifier() protocol.delete_orphan_todos() @@ -539,11 +493,11 @@ def delete_protocol(protocol_id): @app.route("/protocol/etherpull/<int:protocol_id>") @login_required -def etherpull_protocol(protocol_id): +@db_lookup(Protocol) +def etherpull_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Die fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) if not config.ETHERPAD_ACTIVE: flash("Die Etherpadfunktion ist nicht aktiviert.", "alert-error") @@ -556,11 +510,11 @@ def etherpull_protocol(protocol_id): @app.route("/protocol/upload/known/<int:protocol_id>", methods=["POST"]) @login_required -def upload_source_to_known_protocol(protocol_id): +@db_lookup(Protocol) +def upload_source_to_known_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) form = KnownProtocolSourceUploadForm() if form.validate_on_submit(): @@ -640,43 +594,43 @@ def upload_new_protocol_by_file(): @app.route("/protocol/recompile/<int:protocol_id>") @login_required @group_required(config.ADMIN_GROUP) -def recompile_protocol(protocol_id): +@db_lookup(Protocol) +def recompile_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Die fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) tasks.parse_protocol(protocol) return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id)) @app.route("/protocol/source/<int:protocol_id>") @login_required -def get_protocol_source(protocol_id): +@db_lookup(Protocol) +def get_protocol_source(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) 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())) @app.route("/protocol/template/<int:protocol_id>") @login_required -def get_protocol_template(protocol_id): +@db_lookup(Protocol) +def get_protocol_template(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) 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())) @app.route("/protocol/etherpush/<int:protocol_id>") @login_required -def etherpush_protocol(protocol_id): +@db_lookup(Protocol) +def etherpush_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): + if not protocol.protocoltype.has_modify_right(user): flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") return redirect(request.args.get("next") or url_for("index")) if not config.ETHERPAD_ACTIVE: @@ -688,11 +642,11 @@ def etherpush_protocol(protocol_id): @app.route("/protocol/update/<int:protocol_id>", methods=["GET", "POST"]) @login_required -def update_protocol(protocol_id): +@db_lookup(Protocol) +def update_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) upload_form = KnownProtocolSourceUploadForm() edit_form = ProtocolForm(obj=protocol) @@ -705,24 +659,23 @@ def update_protocol(protocol_id): @app.route("/protocol/publish/<int:protocol_id>") @login_required -def publish_protocol(protocol_id): +@db_lookup(Protocol) +def publish_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) protocol.public = True 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>") @login_required -def send_protocol(protocol_id): +@db_lookup(Protocol) +def send_protocol(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) if not config.MAIL_ACTIVE: flash("Die Mailfunktion ist nicht aktiviert.", "alert-error") @@ -730,15 +683,14 @@ def send_protocol(protocol_id): tasks.send_protocol(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("/protocol/tops/new/<int:protocol_id>", methods=["GET", "POST"]) @login_required -def new_top(protocol_id): +@db_lookup(Protocol) +def new_top(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen dir nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) form = TopForm() if form.validate_on_submit(): @@ -755,11 +707,11 @@ def new_top(protocol_id): @app.route("/protocol/top/edit/<int:top_id>", methods=["GET", "POST"]) @login_required -def edit_top(top_id): +@db_lookup(TOP) +def edit_top(top): user = current_user() - top = TOP.query.filter_by(id=top_id).first() - if top is None or not top.protocol.protocoltype.has_modify_right(user): - flash("Invalider TOP oder keine Berechtigung.", "alert-error") + if not top.protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) form = TopForm(obj=top) if form.validate_on_submit(): @@ -771,11 +723,11 @@ def edit_top(top_id): @app.route("/protocol/top/delete/<int:top_id>") @login_required -def delete_top(top_id): +@db_lookup(TOP) +def delete_top(top): user = current_user() - top = TOP.query.filter_by(id=top_id).first() - if top is None or not top.protocol.protocoltype.has_modify_right(user): - flash("Invalider TOP oder keine Berechtigung.", "alert-error") + if not top.protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) name = top.name protocol = top.protocol @@ -787,11 +739,11 @@ def delete_top(top_id): @app.route("/protocol/top/move/<int:top_id>/<diff>") @login_required -def move_top(top_id, diff): +@db_lookup(TOP) +def move_top(top, diff): user = current_user() - top = TOP.query.filter_by(id=top_id).first() - if top is None or not top.protocol.protocoltype.has_modify_right(user): - flash("Invalider TOP oder keine Berechtigung.", "alert-error") + if not top.protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) try: top.number += int(diff) @@ -897,10 +849,10 @@ def new_todo(): @app.route("/todo/edit/<int:todo_id>", methods=["GET", "POST"]) @login_required -def edit_todo(todo_id): +@db_lookup(Todo) +def edit_todo(todo): user = current_user() - todo = Todo.query.filter_by(id=todo_id).first() - if todo is None or not todo.protocoltype.has_modify_right(user): + if not todo.protocoltype.has_modify_right(user): flash("Invalides Todo oder unzureichende Berechtigung.", "alert-error") return redirect(request.args.get("next") or url_for("index")) form = TodoForm(obj=todo) @@ -912,22 +864,22 @@ def edit_todo(todo_id): @app.route("/todo/show/<int:todo_id>") @login_required -def show_todo(todo_id): +@db_lookup(Todo) +def show_todo(todo): user = current_user() - todo = Todo.query.filter_by(id=todo_id).first() - if todo is None or not todo.protocoltype.has_private_view_right(user): - flash("Invalides Todo oder unzureichende Berechtigung.", "alert-error") + if not todo.protocoltype.has_private_view_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) todo_table = TodoTable(todo) return render_template("todo-show.html", todo=todo, todo_table=todo_table) @app.route("/todo/delete/<int:todo_id>") @login_required -def delete_todo(todo_id): +@db_lookup(Todo) +def delete_todo(todo): user = current_user() - todo = Todo.query.filter_by(id=todo_id).first() - if todo is None or not todo.protocoltype.has_private_view_right(user): - flash("Invalides Todo oder unzureichende Berechtigung.", "alert-error") + if not todo.protocoltype.has_private_view_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) type_id = todo.protocoltype.id db.session.delete(todo) @@ -979,29 +931,25 @@ def list_decisions(): decisions_table = DecisionsTable(decisions) return render_template("decisions-list.html", decisions=decisions, decisions_table=decisions_table, search_form=search_form, page=page, page_count=page_count, page_diff=config.PAGE_DIFF, protocoltype_id=protocoltype_id, search_term=search_term) - @app.route("/document/download/<int:document_id>") -def download_document(document_id): +@db_lookup(Document) +def download_document(document): user = current_user() - document = Document.query.filter_by(id=document_id).first() - if document is None: - flash("Invalides Dokument.", "alert-error") - return redirect(request.args.get("next") or url_for("index")) if ((document.is_private and not document.protocol.protocoltype.has_private_view_right(user)) or (not document.is_private and not document.protocol.has_public_view_right(user))): - flash("Keine Berechtigung.", "alert-error") + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) return send_file(document.as_file_like(), cache_timeout=1, as_attachment=True, attachment_filename=document.name) @app.route("/document/upload/<int:protocol_id>", methods=["POST"]) @login_required -def upload_document(protocol_id): +@db_lookup(Protocol) +def upload_document(protocol): user = current_user() - protocol = Protocol.query.filter_by(id=protocol_id).first() - if protocol is None or not protocol.protocoltype.has_modify_right(user): - flash("Unzureichende Berechtigung.", "alert-error") + if not protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) form = DocumentUploadForm() if form.document.data is None: @@ -1028,11 +976,11 @@ def upload_document(protocol_id): @app.route("/document/delete/<int:document_id>") @login_required @group_required(config.ADMIN_GROUP) -def delete_document(document_id): +@db_lookup(Document) +def delete_document(document): user = current_user() - document = Document.query.filter_by(id=document_id).first() - if document is None or not document.protocol.protocoltype.has_modify_right(user): - flash("Unzureichende Berechtigung.", "alert-error") + if not document.protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) name = document.name protocol = document.protocol @@ -1043,11 +991,11 @@ def delete_document(document_id): @app.route("/document/print/<int:document_id>") @login_required -def print_document(document_id): +@db_lookup(Document) +def print_document(document): user = current_user() - document = Document.query.filter_by(id=document_id).first() - if document is None or not document.protocol.protocoltype.has_modify_right(user): - flash("Invalides Protokoll oder keine Berechtigung.", "alert-error") + if not document.protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) if not config.PRINTING_ACTIVE: flash("Die Druckfunktion ist nicht aktiviert.", "alert-error") @@ -1056,20 +1004,20 @@ def print_document(document_id): flash("Das Dokument {} wird gedruckt.".format(document.name), "alert-success") return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=document.protocol.id)) -@app.route("/decision/print/<int:document_id>") +@app.route("/decision/print/<int:decisiondocument_id>") @login_required -def print_decision(document_id): +@db_lookup(DecisionDocument) +def print_decision(decisiondocument): user = current_user() - document = DecisionDocument.query.filter_by(id=document_id).first() - if document is None or not document.decision.protocol.protocoltype.has_modify_right(user): - flash("Invalides Dokument oder keine Berechtigung.", "alert-error") + if not decisiondocument.decision.protocol.protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) if not config.PRINTING_ACTIVE: flash("Die Druckfunktion ist nicht aktiviert.", "alert-error") - return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=document.decision.protocol.id)) - tasks.print_file(document.get_filename(), document.decision.protocol) - flash("Das Dokument {} wird gedruckt.".format(document.name), "alert-success") - return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=document.decision.protocol.id)) + return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=decisiondocument.decision.protocol.id)) + tasks.print_file(decisiondocument.get_filename(), decisiondocument.decision.protocol) + flash("Das Dokument {} wird gedruckt.".format(decisiondocument.name), "alert-success") + return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=decisiondocument.decision.protocol.id)) @app.route("/errors/list") @login_required @@ -1084,21 +1032,21 @@ def list_errors(): @app.route("/error/show/<int:error_id>") @login_required -def show_error(error_id): +@db_lookup(Error) +def show_error(error): user = current_user() - error = Error.query.filter_by(id=error_id).first() - if error is None or not error.protocol.protocoltype.has_modify_right(user): - flash("Invalider Fehler oder fehlende Zugriffsrechte.", "alert-error") + if not error.protocol.protocoltype.has_modify_right(user): + flash("Die fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) error_table = ErrorTable(error) return render_template("error-show.html", error=error, error_table=error_table) @app.route("/error/delete/<int:error_id>") @login_required -def delete_error(error_id): +@db_lookup(Error) +def delete_error(error): user = current_user() - error = Error.query.filter_by(id=error_id).first() - if error is None or not error.protocol.protocoltype.has_modify_right(user): + if not error.protocol.protocoltype.has_modify_right(user): flash("Invalider Fehler oder fehlende Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) name = error.name @@ -1128,11 +1076,8 @@ def new_todomail(): @app.route("/todomail/edit/<int:todomail_id>", methods=["GET", "POST"]) @login_required -def edit_todomail(todomail_id): - todomail = TodoMail.query.filter_by(id=todomail_id).first() - if todomail is None: - flash("Invalide Todo-Mail-Zuordnung.", "alert-error") - return redirect(request.args.get("next") or url_for("list_todomails")) +@db_lookup(TodoMail) +def edit_todomail(todomail): form = TodoMailForm(obj=todomail) if form.validate_on_submit(): form.populate_obj(todomail) @@ -1143,65 +1088,62 @@ def edit_todomail(todomail_id): @app.route("/todomail/delete/<int:todomail_id>") @login_required -def delete_todomail(todomail_id): - todomail = TodoMail.query.filter_by(id=todomail_id).first() - if todomail is None: - flash("Invalide Todomailzuordnung.", "alert-error") - return redirect(request.args.get("next") or url_for("list_todomails")) +@db_lookup(TodoMail) +def delete_todomail(todomail): name = todomail.name db.session.delete(todomail) db.session.commit() flash("Die Todo-Mail-Zuordnung für {} wurde gelöscht.".format(name), "alert-success") return redirect(request.args.get("next") or url_for("list_todomails")) -@app.route("/defaultmeta/new/<int:type_id>", methods=["GET", "POST"]) +@app.route("/defaultmeta/new/<int:protocoltype_id>", methods=["GET", "POST"]) @login_required -def new_defaultmeta(type_id): +@db_lookup(ProtocolType) +def new_defaultmeta(protocoltype): user = current_user() - protocoltype = ProtocolType.query.filter_by(id=type_id).first() - if protocoltype is None or not protocoltype.has_modify_right(user): - flash("Invalider Protokolltyp oder unzureichende Rechte.", "alert-error") + if not protocoltype.has_modify_right(user): + flash("Dir fehlen die nötigen Zugriffsrechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) form = DefaultMetaForm() if form.validate_on_submit(): - meta = DefaultMeta(protocoltype_id=type_id, key=form.key.data, + meta = DefaultMeta(protocoltype_id=protocoltype.id, key=form.key.data, name=form.name.data) db.session.add(meta) db.session.commit() flash("Metadatenfeld hinzugefügt.", "alert-success") - return redirect(request.args.get("next") or url_for("show_type", type_id=type_id)) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=protocoltype.id)) return render_template("defaultmeta-new.html", form=form, protocoltype=protocoltype) -@app.route("/defaultmeta/edit/<int:meta_id>", methods=["GET", "POST"]) +@app.route("/defaultmeta/edit/<int:defaultmeta_id>", methods=["GET", "POST"]) @login_required -def edit_defaultmeta(meta_id): +@db_lookup(DefaultMeta) +def edit_defaultmeta(defaultmeta): user = current_user() - meta = DefaultMeta.query.filter_by(id=meta_id).first() - if meta is None or not meta.protocoltype.has_modify_right(user): + if not defaultmeta.protocoltype.has_modify_right(user): flash("Invalider Protokolltyp oder unzureichende Rechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) - form = DefaultMetaForm(obj=meta) + form = DefaultMetaForm(obj=defaultmeta) if form.validate_on_submit(): - form.populate_obj(meta) + form.populate_obj(defaultmeta) db.session.commit() - return redirect(request.args.get("next") or url_for("show_type", type_id=meta.protocoltype.id)) - return render_template("defaultmeta-edit.html", form=form, meta=meta) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=defaultmeta.protocoltype.id)) + return render_template("defaultmeta-edit.html", form=form, defaultmeta=defaultmeta) -@app.route("/defaultmeta/delete/<int:meta_id>") +@app.route("/defaultmeta/delete/<int:defaultmeta_id>") @login_required @group_required(config.ADMIN_GROUP) -def delete_defaultmeta(meta_id): +@db_lookup(DefaultMeta) +def delete_defaultmeta(defaultmeta): user = current_user() - meta = DefaultMeta.query.filter_by(id=meta_id).first() - if meta is None or not meta.protocoltype.has_modify_right(user): + if not meta.protocoltype.has_modify_right(user): flash("Invalider Protokolltyp oder unzureichende Rechte.", "alert-error") return redirect(request.args.get("next") or url_for("index")) - name = meta.name - type_id = meta.protocoltype.id + name = defaultmeta.name + type_id = defaultmeta.protocoltype.id db.session.delete(meta) db.session.commit() flash("Metadatenfeld '{}' gelöscht.".format(name), "alert-error") - return redirect(request.args.get("next") or url_for("show_type", type_id=type_id)) + return redirect(request.args.get("next") or url_for("show_type", protocoltype_id=type_id)) @app.route("/login", methods=["GET", "POST"]) def login(): diff --git a/templates/default-top-edit.html b/templates/default-top-edit.html index 8dee99e010794716cc80a35e1058bc1b65d82750..fa90f218726998b7ca33f6e44b12e3f0351bf163 100644 --- a/templates/default-top-edit.html +++ b/templates/default-top-edit.html @@ -4,6 +4,6 @@ {% block content %} <div class="container"> - {{render_form(form, action_url=url_for("edit_default_top", type_id=protocoltype.id, top_id=default_top.id, next=url_for("show_type", type_id=protocoltype.id)), action_text="Ändern")}} + {{render_form(form, action_url=url_for("edit_default_top", type_id=protocoltype.id, defaulttop_id=defaulttop.id, next=url_for("show_type", protocoltype_id=protocoltype.id)), action_text="Ändern")}} </div> {% endblock %} diff --git a/templates/default-top-new.html b/templates/default-top-new.html index d65a6213d69389f4b10a3c100f18d97c9fe2a5b4..be99948f73f23dbf276eacc3f350a0bfa4f82686 100644 --- a/templates/default-top-new.html +++ b/templates/default-top-new.html @@ -4,6 +4,6 @@ {% block content %} <div class="container"> - {{render_form(form, action_url=url_for("new_default_top", type_id=protocoltype.id, next=url_for("show_type", type_id=protocoltype.id)), action_text="Anlegen")}} + {{render_form(form, action_url=url_for("new_default_top", type_id=protocoltype.id, next=url_for("show_type", protocoltype_id=protocoltype.id)), action_text="Anlegen")}} </div> {% endblock %} diff --git a/templates/defaultmeta-edit.html b/templates/defaultmeta-edit.html index 941899227e77b53f9060523e827a0d4c9687be5e..14385be6aac943e80b5348f15709adeb65976502 100644 --- a/templates/defaultmeta-edit.html +++ b/templates/defaultmeta-edit.html @@ -4,6 +4,6 @@ {% block content %} <div class="container"> - {{render_form(form, action_url=url_for("edit_defaultmeta", meta_id=meta.id, next=url_for("show_type", type_id=meta.protocoltype.id)), action_text="Ändern")}} + {{render_form(form, action_url=url_for("edit_defaultmeta", meta_id=meta.id, next=url_for("show_type", protocoltype_id=meta.protocoltype.id)), action_text="Ändern")}} </div> {% endblock %} diff --git a/templates/defaultmeta-new.html b/templates/defaultmeta-new.html index 8a7c0cc20446dbf337ab83274c480ddd6c94b4dd..ca9d9ebea78524947c0c23cbaca5a469b09beaba 100644 --- a/templates/defaultmeta-new.html +++ b/templates/defaultmeta-new.html @@ -4,6 +4,6 @@ {% block content %} <div class="container"> - {{render_form(form, action_url=url_for("new_defaultmeta", type_id=protocoltype.id, next=url_for("show_type", type_id=protocoltype.id)), action_text="Anlegen")}} + {{render_form(form, action_url=url_for("new_defaultmeta", protocoltype_id=protocoltype.id, next=url_for("show_type", protocoltype_id=protocoltype.id)), action_text="Anlegen")}} </div> {% endblock %} diff --git a/templates/protocol-show.html b/templates/protocol-show.html index b840e2bab725daf630e3a9826d998bbba0286564..1821308f1e84232511f57beb1b26c7f0baa628eb 100644 --- a/templates/protocol-show.html +++ b/templates/protocol-show.html @@ -35,7 +35,7 @@ <a class="btn btn-default" href="{{url_for("publish_protocol", protocol_id=protocol.id)}}">Veröffentlichen</a> {% endif %} {% endif %} - <a class="btn btn-default" href="{{url_for("show_type", type_id=protocol.protocoltype.id)}}">Typ</a> + <a class="btn btn-default" href="{{url_for("show_type", protocoltype_id=protocol.protocoltype.id)}}">Typ</a> {% if protocol.has_compiled_document() %} <a class="btn btn-success" href="{{url_for("download_document", document_id=protocol.get_compiled_document().id)}}">Download</a> {% endif %} diff --git a/templates/reminder-edit.html b/templates/reminder-edit.html index a954dbf33698a39e540b2ebd04638affafa870d8..08fcb2f6d8b64f6408f2c81eed3f010c3a248951 100644 --- a/templates/reminder-edit.html +++ b/templates/reminder-edit.html @@ -4,6 +4,6 @@ {% block content %} <div class="container"> - {{render_form(form, action_url=url_for("edit_reminder", type_id=protocoltype.id, reminder_id=reminder.id, next=url_for("show_type", type_id=protocoltype.id)), action_text="Ändern")}} + {{render_form(form, action_url=url_for("edit_reminder", protocoltype_id=protocoltype.id, meetingreminder_id=meetingreminder.id, next=url_for("show_type", protocoltype_id=protocoltype.id)), action_text="Ändern")}} </div> {% endblock %} diff --git a/templates/reminder-new.html b/templates/reminder-new.html index 7045c3ea547639b1a5e7a20cda87923ba12f1000..971fef808a0c0a133892bef101c826fdc3e5b745 100644 --- a/templates/reminder-new.html +++ b/templates/reminder-new.html @@ -4,6 +4,6 @@ {% block content %} <div class="container"> - {{render_form(form, action_url=url_for("new_reminder", type_id=protocoltype.id, next=url_for("show_type", type_id=protocoltype.id)), action_text="Anlegen")}} + {{render_form(form, action_url=url_for("new_reminder", protocoltype_id=protocoltype.id, next=url_for("show_type", protocoltype_id=protocoltype.id)), action_text="Anlegen")}} </div> {% endblock %} diff --git a/templates/type-edit.html b/templates/type-edit.html index 1bb548aaacbea1dce24803ffcba46e28f77c5d7c..249ebfaffd5256f81517b53f08adc6c006f95968 100644 --- a/templates/type-edit.html +++ b/templates/type-edit.html @@ -4,6 +4,6 @@ {% block content %} <div class="container"> - {{render_form(form, action_url=url_for("edit_type", type_id=protocoltype.id), action_text="Ändern")}} + {{render_form(form, action_url=url_for("edit_type", protocoltype_id=protocoltype.id), action_text="Ändern")}} </div> {% endblock %} diff --git a/views/tables.py b/views/tables.py index 9ac653db4170bc49006d2da802b26ed322e8ab11..11e6ad38d740aabecf4d4ffce04381b3f2e4ad1b 100644 --- a/views/tables.py +++ b/views/tables.py @@ -80,7 +80,7 @@ class ProtocolsTable(Table): result.append(Markup(self.search_results[protocol])) if check_login(): if user is not None and protocol.protocoltype.has_private_view_right(user): - result.append(Table.link(url_for("show_type", type_id=protocol.protocoltype.id), protocol.protocoltype.short_name)) + 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()))) else: @@ -99,7 +99,7 @@ class ProtocolTypesTable(Table): user = current_user() has_modify_right = protocoltype.has_modify_right(user) return [ - Table.link(url_for("show_type", type_id=protocoltype.id), protocoltype.short_name) if has_modify_right else protocoltype.short_name, + Table.link(url_for("show_type", protocoltype_id=protocoltype.id), protocoltype.short_name) if has_modify_right else protocoltype.short_name, protocoltype.name, Table.link(url_for("show_protocol", protocol_id=protocol.id), protocol.get_identifier()) if protocol is not None else "Noch kein Protokoll", Table.link(url_for("new_protocol", type_id=protocoltype.id), "Neues Protokoll") if has_modify_right else "" @@ -108,7 +108,7 @@ class ProtocolTypesTable(Table): class ProtocolTypeTable(SingleValueTable): def __init__(self, protocoltype): - super().__init__(protocoltype.name, protocoltype, newlink=url_for("edit_type", type_id=protocoltype.id)) + super().__init__(protocoltype.name, protocoltype, newlink=url_for("edit_type", protocoltype_id=protocoltype.id)) def headers(self): general_headers = ["Name", "Abkürzung", "Organisation", "Beginn", @@ -166,7 +166,7 @@ class ProtocolTypeTable(SingleValueTable): Table.bool(self.value.restrict_networks), self.value.allowed_networks ] - action_part = [Table.link(url_for("delete_type", type_id=self.value.id), "Löschen", confirm="Bist du dir sicher, dass du den Protokolltype {} löschen möchtest?".format(self.value.name))] + action_part = [Table.link(url_for("delete_type", protocoltype_id=self.value.id), "Löschen", confirm="Bist du dir sicher, dass du den Protokolltype {} löschen möchtest?".format(self.value.name))] if not self.value.has_admin_right(user): action_part = [""] return (general_part + mail_part + printing_part + wiki_part + @@ -194,7 +194,7 @@ class DefaultTOPsTable(Table): class MeetingRemindersTable(Table): def __init__(self, reminders, protocoltype=None): - super().__init__("Einladungsmails", reminders, newlink=url_for("new_reminder", type_id=protocoltype.id) if protocoltype is not None else None) + super().__init__("Einladungsmails", reminders, newlink=url_for("new_reminder", protocoltype_id=protocoltype.id) if protocoltype is not None else None) self.protocoltype = protocoltype def headers(self): @@ -208,8 +208,8 @@ class MeetingRemindersTable(Table): reminder.additional_text or "" ] action_links = [ - Table.link(url_for("edit_reminder", type_id=self.protocoltype.id, reminder_id=reminder.id), "Ändern"), - Table.link(url_for("delete_reminder", type_id=self.protocoltype.id, reminder_id=reminder.id), "Löschen", confirm="Bist du dir sicher, dass du die Einladungsmail {} Tage vor der Sitzung löschen willst?".format(reminder.days_before)) + Table.link(url_for("edit_reminder", protocoltype_id=self.protocoltype.id, meetingreminder_id=reminder.id), "Ändern"), + Table.link(url_for("delete_reminder", protocoltype_id=self.protocoltype.id, meetingreminder_id=reminder.id), "Löschen", confirm="Bist du dir sicher, dass du die Einladungsmail {} Tage vor der Sitzung löschen willst?".format(reminder.days_before)) ] action_part = [Table.concat(action_links)] return general_part + action_part @@ -373,7 +373,7 @@ class DefaultMetasTable(Table): super().__init__( "Metadatenfelder", metas, - url_for("new_defaultmeta", type_id=protocoltype.id) + url_for("new_defaultmeta", protocoltype_id=protocoltype.id) ) def headers(self):