Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
protokollsystem
proto3
Commits
a4f71391
Commit
a4f71391
authored
Feb 25, 2017
by
Robin Sonnabend
Browse files
GET forms for search and pagination
parent
f62d577e
Changes
4
Hide whitespace changes
Inline
Side-by-side
models/database.py
View file @
a4f71391
...
@@ -259,7 +259,6 @@ class Todo(db.Model):
...
@@ -259,7 +259,6 @@ class Todo(db.Model):
description
=
db
.
Column
(
db
.
String
)
description
=
db
.
Column
(
db
.
String
)
tags
=
db
.
Column
(
db
.
String
)
tags
=
db
.
Column
(
db
.
String
)
done
=
db
.
Column
(
db
.
Boolean
)
done
=
db
.
Column
(
db
.
Boolean
)
is_id_fixed
=
db
.
Column
(
db
.
Boolean
,
default
=
False
)
protocols
=
relationship
(
"Protocol"
,
secondary
=
"todoprotocolassociations"
,
backref
=
"todos"
)
protocols
=
relationship
(
"Protocol"
,
secondary
=
"todoprotocolassociations"
,
backref
=
"todos"
)
...
...
server.py
View file @
a4f71391
...
@@ -538,35 +538,28 @@ def _get_page():
...
@@ -538,35 +538,28 @@ def _get_page():
except
ValueError
:
except
ValueError
:
return
0
return
0
@
app
.
route
(
"/todos/list"
,
methods
=
[
"GET"
,
"POST"
]
)
@
app
.
route
(
"/todos/list"
)
def
list_todos
():
def
list_todos
():
is_logged_in
=
check_login
()
is_logged_in
=
check_login
()
user
=
current_user
()
user
=
current_user
()
protocoltype
=
None
protocoltype
=
None
protocoltype_id
=
None
protocoltype_id
=
None
try
:
try
:
protocoltype_id
=
int
(
request
.
args
.
get
(
"type
_id
"
))
protocoltype_id
=
int
(
request
.
args
.
get
(
"
protocol
type"
))
except
(
ValueError
,
TypeError
):
except
(
ValueError
,
TypeError
):
pass
pass
search_term
=
request
.
args
.
get
(
"search"
)
search_term
=
request
.
args
.
get
(
"search"
)
protocoltypes
=
ProtocolType
.
get_available_protocoltypes
(
user
)
protocoltypes
=
ProtocolType
.
get_available_protocoltypes
(
user
)
search_form
=
SearchForm
(
protocoltypes
)
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
:
if
protocoltype_id
is
not
None
:
print
(
protocoltype_id
)
search_form
.
protocoltype
.
data
=
protocoltype_id
protocoltype
=
ProtocolType
.
query
.
filter_by
(
id
=
protocoltype_id
).
first
()
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
:
if
protocoltype_id
is
not
None
and
protocoltype_id
!=
-
1
:
base_query
=
base_query
.
filter
(
ProtocolType
.
id
==
protocoltype_id
)
base_query
=
base_query
.
filter
(
ProtocolType
.
id
==
protocoltype_id
)
print
(
search_term
)
if
search_term
is
not
None
and
len
(
search_term
.
strip
())
>
0
:
if
search_term
is
not
None
and
len
(
search_term
.
strip
())
>
0
:
base_query
=
base_query
.
filter
(
Todo
.
description
.
match
(
"%{}%"
.
format
(
search_term
)))
base_query
=
base_query
.
filter
(
Todo
.
description
.
match
(
"%{}%"
.
format
(
search_term
)))
page
=
_get_page
()
page
=
_get_page
()
...
...
templates/macros.html
View file @
a4f71391
...
@@ -87,10 +87,10 @@ to not render a label for the CRSFTokenField -->
...
@@ -87,10 +87,10 @@ to not render a label for the CRSFTokenField -->
action_text - text of submit button
action_text - text of submit button
class_ - sets a class for form
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
method=
"
{{method}}
"
action=
"{{ action_url }}"
role=
"form"
class=
"{{ class_ }}"
{%
if
enctype
is
not
none
%}
enctype=
"{{enctype}}"
{%
endif
%}
>
{{ form.hidden_tag() if form.hidden_tag }}
{#
{{ form.hidden_tag() if form.hidden_tag }}
#}
{% if caller %}
{% if caller %}
{{ caller() }}
{{ caller() }}
{% else %}
{% else %}
...
@@ -104,7 +104,7 @@ to not render a label for the CRSFTokenField -->
...
@@ -104,7 +104,7 @@ to not render a label for the CRSFTokenField -->
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
{% endif %}
<button
type=
"submit"
class=
"{{
btn_class
}}"
>
{{
action_text
}}
</button>
<button
type=
"submit"
class=
"{{btn_class}}"
>
{{action_text}}
</button>
</form>
</form>
{%- endmacro %}
{%- endmacro %}
...
...
templates/todos-list.html
View file @
a4f71391
...
@@ -3,12 +3,12 @@
...
@@ -3,12 +3,12 @@
{% block title %}Todos{% endblock %}
{% block title %}Todos{% endblock %}
{% macro page_link(page, text) %}
{% 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,
protocol
type=protocoltype_id, search=search_term)}}"
>
{{text}}
</a>
{% endmacro %}
{% endmacro %}
{% block content %}
{% block content %}
<div
class=
"container"
>
<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)}}
{{render_table(todos_table)}}
<div
class=
"centered"
>
<div
class=
"centered"
>
{% if page > page_diff %}
{% if page > page_diff %}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment