Commit 6936e129 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Added editing protocols

parent dabb0158
......@@ -152,7 +152,6 @@ class Protocol(db.Model):
if document.is_compiled
and (private is None or document.is_private == private)
]
print(candidates)
private_candidates = [document for document in candidates if document.is_private]
public_candidates = [document for document in candidates if not document.is_private]
if len(private_candidates) > 0:
......@@ -164,7 +163,7 @@ class Protocol(db.Model):
def delete_orphan_todos(self):
orphan_todos = [
todo for todo in self.todos
if len(todo.protocols) == 1
if len(todo.protocols) <= 1
]
for todo in orphan_todos:
self.todos.remove(todo)
......
......@@ -17,7 +17,7 @@ import config
from shared import db, date_filter, datetime_filter, date_filter_long, time_filter, ldap_manager, security_manager, current_user, check_login, login_required, group_required
from utils import is_past, mail_manager, url_manager
from models.database import ProtocolType, Protocol, DefaultTOP, TOP, Document, Todo, Decision, MeetingReminder, Error
from views.forms import LoginForm, ProtocolTypeForm, DefaultTopForm, MeetingReminderForm, NewProtocolForm, DocumentUploadForm, KnownProtocolSourceUploadForm, NewProtocolSourceUploadForm
from views.forms import LoginForm, ProtocolTypeForm, DefaultTopForm, MeetingReminderForm, NewProtocolForm, DocumentUploadForm, KnownProtocolSourceUploadForm, NewProtocolSourceUploadForm, ProtocolForm
from views.tables import ProtocolsTable, ProtocolTypesTable, ProtocolTypeTable, DefaultTOPsTable, MeetingRemindersTable, ErrorsTable, TodosTable, DocumentsTable
app = Flask(__name__)
......@@ -308,6 +308,21 @@ def new_protocol():
form.protocoltype.data = type_id
return render_template("protocol-new.html", form=form, upload_form=upload_form, protocoltypes=protocoltypes)
@app.route("/protocol/edit/<int:protocol_id>", methods=["POST"])
@login_required
def edit_protocol(protocol_id):
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 fehlende Zugriffsrechte.", "alert-error")
return redirect(request.args.get("next") or url_for("list_protocols"))
form = ProtocolForm(obj=protocol)
if form.validate_on_submit():
form.populate_obj(protocol)
db.session.commit()
return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id))
return redirect(request.args.get("fail") or url_for("update_protocol", protocol_id=protocol.id))
@app.route("/protocol/show/<int:protocol_id>")
def show_protocol(protocol_id):
user = current_user()
......@@ -335,6 +350,7 @@ def delete_protocol(protocol_id):
flash("Invalides Protokoll oder keine Berechtigung.", "alert-error")
return redirect(request.args.get("next") or url_for("index"))
name = protocol.get_identifier()
protocol.delete_orphan_todos()
db.session.delete(protocol)
db.session.commit()
flash("Protokoll {} ist gelöscht.".format(name), "alert-success")
......@@ -394,7 +410,6 @@ def upload_new_protocol():
if form.source.data is None:
flash("Es wurde keine Datei ausgewählt.", "alert-error")
else:
print(form.source.data)
file = form.source.data
if file.filename == "":
flash("Es wurde keine Datei ausgewählt.", "alert-error")
......@@ -434,7 +449,8 @@ def update_protocol(protocol_id):
flash("Invalides Protokoll oder keine Berechtigung.", "alert-error")
return redirect(request.args.get("next") or url_for("index"))
upload_form = KnownProtocolSourceUploadForm()
return render_template("protocol-update.html", upload_form=upload_form, protocol=protocol)
edit_form = ProtocolForm(obj=protocol)
return render_template("protocol-update.html", upload_form=upload_form, edit_form=edit_form, protocol=protocol)
@app.route("/todos/list")
def list_todos():
......
......@@ -74,7 +74,7 @@ def date_filter_long(date):
def date_filter_short(date):
return date.strftime("%d.%m.%Y")
def time_filter(time):
return time.strftime("%H:%m")
return time.strftime("%H:%M")
def class_filter(obj):
return obj.__class__.__name__
......
......@@ -27,6 +27,9 @@
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{{url_for("index")}}">Zuhause</a></li>
{% if check_login() %}
<li><a href="{{url_for("new_protocol")}}">Neues Protokoll</a></li>
{% endif %}
<li><a href="{{url_for("list_protocols")}}">Protokolle</a></li>
<li><a href="{{url_for("list_todos")}}">Todos</a></li>
{% if check_login() %}
......
......@@ -10,9 +10,7 @@
{% if protocol.source is not none %}
<a class="btn btn-primary" href="{{url_for("get_protocol_source", protocol_id=protocol.id)}}">Download Quelltext</a>
{% endif %}
{% if protocol.is_done() %}
<a class="btn btn-success" href="{{url_for("update_protocol", protocol_id=protocol.id)}}">Protokoll editieren</a>
{% endif %}
<a class="btn {% if protocol.is_done() %}btn-success{% else %}btn-default{% endif %}" href="{{url_for("update_protocol", protocol_id=protocol.id)}}">Protokoll editieren</a>
<a class="btn btn-default" href="{{protocol.get_etherpad_link()}}" target="_blank">Etherpad</a>
<a class="btn btn-default" href="{{url_for("show_type", type_id=protocol.protocoltype.id)}}">Typ</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>
......@@ -20,7 +18,7 @@
</div>
<div class="row">
<div id="left-column" class="col-lg-6">
<h2>Protokoll: {{protocol.protocoltype.name}} vom {{protocol.date|datify}}</h2>
<h2>Protokoll: {{protocol.protocoltype.name}} {% if protocol.date is not none %}vom {{protocol.date|datify}}{% endif %}</h2>
{% if protocol.is_done() %}
{% if protocol.date is not none %}
<p><strong>Datum:</strong> {{protocol.date|datify_long}}</p>
......@@ -38,7 +36,7 @@
<p><strong>Anwesende:</strong> {{protocol.participants}}</p>
{% endif %}
{% else %}
<p><strong>Geplant:</strong> {{protocol.date|datify_long}}</p>
{% if protocol.date is not none %}<p><strong>Geplant:</strong> {{protocol.date|datify_long}}{% endif %}</p>
{% endif %}
<h3>Tagesordnung</h3>
......
......@@ -6,6 +6,9 @@
<div class="container">
<div class="row">
<div id="left-column" class="col-lg-6">
{{render_form(edit_form, action_url=url_for("edit_protocol", protocol_id=protocol.id), action_text="Ändern")}}
</div>
<div id="right-column" class="col-lg-6">
<h3>Protokoll herunterladen</h3>
<div class="btn-group">
{% if protocol.source is not none %}
......@@ -16,8 +19,6 @@
<a class="btn btn-success" href="{{url_for("download_document", document_id=protocol.get_compiled_document().id)}}">Download PDF</a>
{% endif %}
</div>
</div>
<div id="right-column" class="col-lg-6">
<h3>Neue Version hochladen</h3>
{{render_form(upload_form, action_url=url_for("upload_source_to_known_protocol", protocol_id=protocol.id), action_text="Hochladen", enctype="multipart/form-data")}}
</div>
......
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, DateField, HiddenField, IntegerField, SelectField, FileField
from wtforms import StringField, PasswordField, BooleanField, DateField, HiddenField, IntegerField, SelectField, FileField, DateTimeField
from wtforms.validators import InputRequired
class LoginForm(FlaskForm):
......@@ -47,3 +47,13 @@ class NewProtocolSourceUploadForm(FlaskForm):
def __init__(self, protocoltypes, **kwargs):
super().__init__(**kwargs)
self.protocoltype.choices = [(protocoltype.id, protocoltype.short_name) for protocoltype in protocoltypes]
class ProtocolForm(FlaskForm):
date = DateField("Datum", validators=[InputRequired("Bitte gib das Datum des Protkolls an.")], format="%d.%m.%Y")
start_time = DateTimeField("Beginn", format="%H:%M")
end_time = DateTimeField("Ende", format="%H:%M")
location = StringField("Ort")
author = StringField("Protokollant")
participants = StringField("Anwesende")
done = BooleanField("Fertig")
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