From 8b11e3a5ee1ae81a0e86cae3bcf11fe56856068c Mon Sep 17 00:00:00 2001 From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de> Date: Wed, 15 Mar 2017 04:08:32 +0100 Subject: [PATCH] Filter todos by state --- server.py | 23 ++++++++++++++++++----- templates/decisions-list.html | 2 +- templates/protocols-list.html | 2 +- templates/todos-list.html | 2 +- views/forms.py | 3 +++ 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/server.py b/server.py index 640a19d..6a16991 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 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, Document, Todo, Decision, MeetingReminder, Error, TodoMail, DecisionDocument, TodoState, Meta, DefaultMeta, DecisionCategory -from views.forms import LoginForm, ProtocolTypeForm, DefaultTopForm, MeetingReminderForm, NewProtocolForm, DocumentUploadForm, KnownProtocolSourceUploadForm, NewProtocolSourceUploadForm, ProtocolForm, TopForm, SearchForm, DecisionSearchForm, ProtocolSearchForm, NewProtocolFileUploadForm, NewTodoForm, TodoForm, TodoMailForm, DefaultMetaForm, MetaForm, MergeTodosForm, DecisionCategoryForm +from views.forms import LoginForm, ProtocolTypeForm, DefaultTopForm, MeetingReminderForm, NewProtocolForm, DocumentUploadForm, KnownProtocolSourceUploadForm, NewProtocolSourceUploadForm, ProtocolForm, TopForm, SearchForm, DecisionSearchForm, ProtocolSearchForm, TodoSearchForm, NewProtocolFileUploadForm, NewTodoForm, TodoForm, TodoMailForm, DefaultMetaForm, MetaForm, MergeTodosForm, DecisionCategoryForm 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 @@ -447,7 +447,7 @@ def list_protocols(): end_index = (page + 1) * config.PAGE_LENGTH protocols = protocols[begin_index:end_index] protocols_table = ProtocolsTable(protocols, search_results=search_results) - return render_template("protocols-list.html", protocols=protocols, protocols_table=protocols_table, search_form=search_form, page=page, page_count=page_count, page_diff=config.PAGE_DIFF, protocoltype_id=protocoltype_id, search_term=search_term) + return render_template("protocols-list.html", protocols=protocols, protocols_table=protocols_table, search_form=search_form, page=page, page_count=page_count, page_diff=config.PAGE_DIFF, protocoltype_id=protocoltype_id, search_term=search_term, open=open) @app.route("/protocol/new", methods=["GET", "POST"]) @login_required @@ -779,12 +779,19 @@ def list_todos(): protocoltype_id = int(request.args.get("protocoltype_id")) except (ValueError, TypeError): pass + open = -1 + try: + open = int(request.args.get("open")) + except (ValueError, TypeError): + pass search_term = request.args.get("search") protocoltypes = ProtocolType.get_public_protocoltypes(user) - search_form = SearchForm(protocoltypes) + search_form = TodoSearchForm(protocoltypes) if protocoltype_id is not None: search_form.protocoltype_id.data = protocoltype_id protocoltype = ProtocolType.query.filter_by(id=protocoltype_id).first() + if open is not None: + search_form.open.data = open if search_term is not None: search_form.search.data = search_term todos = [ @@ -796,6 +803,12 @@ def list_todos(): todo for todo in todos if todo.protocoltype.id == protocoltype_id ] + if open is not None and open != -1: + todo_done = bool(open) + todos = [ + todo for todo in todos + if todo.is_done() == todo_done + ] if search_term is not None and len(search_term.strip()) > 0: todos = [ todo for todo in todos @@ -813,7 +826,7 @@ def list_todos(): end_index = (page + 1) * config.PAGE_LENGTH todos = todos[begin_index:end_index] todos_table = TodosTable(todos) - return render_template("todos-list.html", todos=todos, todos_table=todos_table, search_form=search_form, page=page, page_count=page_count, page_diff=config.PAGE_DIFF, protocoltype_id=protocoltype_id, search_term=search_term) + return render_template("todos-list.html", todos=todos, todos_table=todos_table, search_form=search_form, page=page, page_count=page_count, page_diff=config.PAGE_DIFF, protocoltype_id=protocoltype_id, search_term=search_term, open=open) @app.route("/todo/new", methods=["GET", "POST"]) @login_required @@ -970,7 +983,7 @@ def list_decisions(): end_index = (page + 1) * config.PAGE_LENGTH decisions = decisions[begin_index:end_index] 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) + 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, decisioncategory_id=decisioncategory_id) @app.route("/document/download/<int:document_id>") @db_lookup(Document) diff --git a/templates/decisions-list.html b/templates/decisions-list.html index c62a083..42e6712 100644 --- a/templates/decisions-list.html +++ b/templates/decisions-list.html @@ -3,7 +3,7 @@ {% block title %}Beschlüsse{% endblock %} {% macro page_link(page, text) %} - <a href="{{url_for(request.endpoint, page=page, protocoltype=protocoltype_id, search=search_term)}}">{{text}}</a> + <a href="{{url_for(request.endpoint, page=page, protocoltype=protocoltype_id, search=search_term, decisioncategory_id=decisioncategory_id)}}">{{text}}</a> {% endmacro %} {% block content %} diff --git a/templates/protocols-list.html b/templates/protocols-list.html index 3f8e842..99f7d37 100644 --- a/templates/protocols-list.html +++ b/templates/protocols-list.html @@ -3,7 +3,7 @@ {% block title %}Protokolle{% endblock %} {% macro page_link(page, text) %} - <a href="{{url_for(request.endpoint, page=page, protocoltype=protocoltype_id, search=search_term)}}">{{text}}</a> + <a href="{{url_for(request.endpoint, page=page, protocoltype=protocoltype_id, search=search_term, open=open)}}">{{text}}</a> {% endmacro %} {% block content %} diff --git a/templates/todos-list.html b/templates/todos-list.html index fefb0c6..a1816bb 100644 --- a/templates/todos-list.html +++ b/templates/todos-list.html @@ -3,7 +3,7 @@ {% block title %}Todos{% endblock %} {% macro page_link(page, text) %} - <a href="{{url_for(request.endpoint, page=page, protocoltype=protocoltype_id, search=search_term)}}">{{text}}</a> + <a href="{{url_for(request.endpoint, page=page, protocoltype=protocoltype_id, search=search_term, open=open)}}">{{text}}</a> {% endmacro %} {% block content %} diff --git a/views/forms.py b/views/forms.py index cd5b55f..f499d52 100644 --- a/views/forms.py +++ b/views/forms.py @@ -208,6 +208,9 @@ class DecisionSearchForm(SearchForm): class ProtocolSearchForm(SearchForm): open = SelectField("Offen", choices=[(-1, "Alle"), (0, "Geplant"), (1, "Fertig")], coerce=int) +class TodoSearchForm(SearchForm): + open = SelectField("Offen", choices=[(-1, "Alle"), (0, "Offen"), (1, "Erledigt")], coerce=int) + class NewTodoForm(FlaskForm): protocoltype_id = SelectField("Typ", choices=[], coerce=int) who = StringField("Person", validators=[InputRequired("Bitte gib an, wer das Todo erledigen soll.")]) -- GitLab