Commit a4f71391 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

GET forms for search and pagination

parent f62d577e
......@@ -259,7 +259,6 @@ class Todo(db.Model):
description = db.Column(db.String)
tags = db.Column(db.String)
done = db.Column(db.Boolean)
is_id_fixed = db.Column(db.Boolean, default=False)
protocols = relationship("Protocol", secondary="todoprotocolassociations", backref="todos")
......
......@@ -538,35 +538,28 @@ def _get_page():
except ValueError:
return 0
@app.route("/todos/list", methods=["GET", "POST"])
@app.route("/todos/list")
def list_todos():
is_logged_in = check_login()
user = current_user()
protocoltype = None
protocoltype_id = None
try:
protocoltype_id = int(request.args.get("type_id"))
protocoltype_id = int(request.args.get("protocoltype"))
except (ValueError, TypeError):
pass
search_term = request.args.get("search")
protocoltypes = ProtocolType.get_available_protocoltypes(user)
search_form = SearchForm(protocoltypes)
if search_form.validate_on_submit():
if search_form.search.data is not None:
search_term = search_form.search.data.strip()
if search_form.protocoltype.data is not None:
protocoltype_id = search_form.protocoltype.data
else:
if protocoltype_id is not None:
search_form.protocoltype.data = protocoltype_id
if search_term is not None:
search_form.search.data = search_term
if protocoltype_id is not None:
print(protocoltype_id)
search_form.protocoltype.data = protocoltype_id
protocoltype = ProtocolType.query.filter_by(id=protocoltype_id).first()
base_query = Todo.query
if search_term is not None:
search_form.search.data = search_term
base_query = Todo.query.order_by(Todo.done).order_by(Todo.number.desc())
if protocoltype_id is not None and protocoltype_id != -1:
base_query = base_query.filter(ProtocolType.id == protocoltype_id)
print(search_term)
if search_term is not None and len(search_term.strip()) > 0:
base_query = base_query.filter(Todo.description.match("%{}%".format(search_term)))
page = _get_page()
......
......@@ -87,10 +87,10 @@ to not render a label for the CRSFTokenField -->
action_text - text of submit button
class_ - sets a class for form
#}
{% macro render_form(form, action_url='', action_text='Submit', class_='', btn_class='btn btn-default', enctype=None, labels_visible=True) -%}
{% macro render_form(form, action_url='', action_text='Submit', class_='', btn_class='btn btn-default', enctype=None, labels_visible=True, method="POST") -%}
<form method="POST" action="{{ action_url }}" role="form" class="{{ class_ }}"{% if enctype is not none %}enctype="{{enctype}}"{% endif %}>
{{ form.hidden_tag() if form.hidden_tag }}
<form method="{{method}}" action="{{ action_url }}" role="form" class="{{ class_ }}"{% if enctype is not none %}enctype="{{enctype}}"{% endif %}>
{#{{ form.hidden_tag() if form.hidden_tag }}#}
{% if caller %}
{{ caller() }}
{% else %}
......@@ -104,7 +104,7 @@ to not render a label for the CRSFTokenField -->
{% endif %}
{% endfor %}
{% endif %}
<button type="submit" class="{{ btn_class }}">{{ action_text }} </button>
<button type="submit" class="{{btn_class}}">{{action_text}}</button>
</form>
{%- endmacro %}
......
......@@ -3,12 +3,12 @@
{% block title %}Todos{% endblock %}
{% macro page_link(page, text) %}
<a href="{{url_for(request.endpoint, page=page, type_id=protocoltype_id, search=search_term)}}">{{text}}</a>
<a href="{{url_for(request.endpoint, page=page, protocoltype=protocoltype_id, search=search_term)}}">{{text}}</a>
{% endmacro %}
{% block content %}
<div class="container">
{{render_form(search_form, class_="form-inline", labels_visible=False)}}
{{render_form(search_form, class_="form-inline", action_url=url_for("list_todos"), action_text="Suchen", labels_visible=False, method="GET")}}
{{render_table(todos_table)}}
<div class="centered">
{% if page > page_diff %}
......
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