From 80b4f2f292763856ad6091c716aa62414472f013 Mon Sep 17 00:00:00 2001 From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de> Date: Tue, 18 Apr 2017 13:57:36 +0200 Subject: [PATCH] Enable renaming files /close #104 --- server.py | 14 +++++++++++++- templates/document-edit.html | 9 +++++++++ views/forms.py | 4 ++++ views/tables.py | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 templates/document-edit.html diff --git a/server.py b/server.py index b3facfa..eeb3fdb 100755 --- a/server.py +++ b/server.py @@ -24,7 +24,7 @@ from shared import db, date_filter, datetime_filter, date_filter_long, date_filt from utils import is_past, mail_manager, url_manager, get_first_unused_int, set_etherpad_text, get_etherpad_text, split_terms, optional_int_arg, fancy_join from decorators import db_lookup, require_public_view_right, require_private_view_right, require_modify_right, require_admin_right from models.database import ProtocolType, Protocol, DefaultTOP, TOP, LocalTOP, Document, Todo, Decision, MeetingReminder, Error, TodoMail, DecisionDocument, TodoState, Meta, DefaultMeta, DecisionCategory, Like -from views.forms import LoginForm, ProtocolTypeForm, DefaultTopForm, MeetingReminderForm, NewProtocolForm, DocumentUploadForm, KnownProtocolSourceUploadForm, NewProtocolSourceUploadForm, generate_protocol_form, TopForm, LocalTopForm, SearchForm, DecisionSearchForm, ProtocolSearchForm, TodoSearchForm, NewProtocolFileUploadForm, NewTodoForm, TodoForm, TodoMailForm, DefaultMetaForm, MetaForm, MergeTodosForm, DecisionCategoryForm +from views.forms import LoginForm, ProtocolTypeForm, DefaultTopForm, MeetingReminderForm, NewProtocolForm, DocumentUploadForm, KnownProtocolSourceUploadForm, NewProtocolSourceUploadForm, generate_protocol_form, TopForm, LocalTopForm, SearchForm, DecisionSearchForm, ProtocolSearchForm, TodoSearchForm, NewProtocolFileUploadForm, NewTodoForm, TodoForm, TodoMailForm, DefaultMetaForm, MetaForm, MergeTodosForm, DecisionCategoryForm, DocumentEditForm from views.tables import ProtocolsTable, ProtocolTypesTable, ProtocolTypeTable, DefaultTOPsTable, MeetingRemindersTable, ErrorsTable, TodosTable, DocumentsTable, DecisionsTable, TodoTable, ErrorTable, TodoMailsTable, DefaultMetasTable, DecisionCategoriesTable from legacy import import_old_todos, import_old_protocols, import_old_todomails @@ -1092,6 +1092,18 @@ def upload_document(protocol): db.session.commit() return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id)) +@app.route("/document/edit/<int:document_id>", methods=["GET", "POST"]) +@login_required +@db_lookup(Document) +@require_modify_right() +def edit_document(document): + form = DocumentEditForm(obj=document) + if form.validate_on_submit(): + form.populate_obj(document) + db.session.commit() + return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=document.protocol.id)) + return render_template("document-edit.html", document=document, form=form) + @app.route("/document/delete/<int:document_id>") @login_required @group_required(config.ADMIN_GROUP) diff --git a/templates/document-edit.html b/templates/document-edit.html new file mode 100644 index 0000000..7b1689e --- /dev/null +++ b/templates/document-edit.html @@ -0,0 +1,9 @@ +{% extends "layout.html" %} +{% from "macros.html" import render_form %} +{% block title %}Dokument bearbeiten{% endblock %} + +{% block content %} +<div class="container"> + {{render_form(form, action_url=url_for("edit_document", document_id=document.id, next=request.args.get("next") or url_for("show_protocol", protocol_id=document.protocol.id)), action_text="Ändern")}} +</div> +{% endblock %} diff --git a/views/forms.py b/views/forms.py index 1c20ba5..0fd10ee 100644 --- a/views/forms.py +++ b/views/forms.py @@ -153,6 +153,10 @@ class NewProtocolForm(FlaskForm): super().__init__(**kwargs) self.protocoltype_id.choices = get_protocoltype_choices(protocoltypes, add_all=False) +class DocumentEditForm(FlaskForm): + name = StringField("Dateiname") + is_private = BooleanField("Intern") + class DocumentUploadForm(FlaskForm): document = FileField("Datei") is_private = BooleanField("Intern") diff --git a/views/tables.py b/views/tables.py index c5682f2..02b71d9 100644 --- a/views/tables.py +++ b/views/tables.py @@ -439,6 +439,8 @@ class DocumentsTable(Table): def row(self, document): user = current_user() links = [] + if document.protocol.has_modify_right(user): + links.append(Table.link(url_for("edit_document", document_id=document.id), "Bearbeiten")) if config.PRINTING_ACTIVE and document.protocol.has_modify_right(user): links.append(Table.link(url_for("print_document", document_id=document.id), "Drucken")) if document.protocol.protocoltype.has_admin_right(user): -- GitLab