瀏覽代碼

resolving issue with empty filter parameters

joel
Simon Bowie 1 年之前
父節點
當前提交
08fcdb830c
共有 3 個文件被更改,包括 17 次插入17 次删除
  1. +2
    -2
      web/app/book.py
  2. +12
    -12
      web/app/templates/resources.html
  3. +3
    -3
      web/app/tool.py

+ 2
- 2
web/app/book.py 查看文件

@@ -24,11 +24,11 @@ def get_books():
books_query = Resource.query.filter_by(type=resource_type)
for key in request.args.keys():
if key != 'view':
if key == 'practice':
if (key == 'practice' and request.args.get(key) != ''):
books_1 = books_query.join(Relationship, Relationship.first_resource_id == Resource.id, isouter=True).filter(Relationship.second_resource_id==request.args.get(key))
books_2 = books_query.join(Relationship, Relationship.second_resource_id == Resource.id, isouter=True).filter(Relationship.first_resource_id==request.args.get(key))
books_query = books_1.union(books_2)
if key != 'practice':
if (key != 'practice' and request.args.get(key) != ''):
kwargs = {key: request.args.get(key)}
books_query = books_query.filter_by(**kwargs)
# finalise the query

+ 12
- 12
web/app/templates/resources.html 查看文件

@@ -93,22 +93,22 @@
{{ view_switch() }}
{% if practices_filter%}
{{ filter_dropdown('practice', practices_filter, 'Practices') }}
{{ filter_dropdown('practice', practices_filter, 'Practices') }}
{% endif %}
{% if year_filter %}
{{ filter_dropdown_nokey('year', year_filter, 'Year') }}
{{ filter_dropdown_nokey('year', year_filter, 'Year') }}
{% endif %}
{% if typology_filter %}
{{ filter_dropdown_nokey('typology', typology_filter, 'Typologies') }}
{{ filter_dropdown_nokey('typology', typology_filter, 'Typologies') }}
{% endif %}
{% if languages_filter %}
{{ filter_dropdown_nokey('scriptingLanguage', languages_filter, 'Scripting languages') }}
{{ filter_dropdown_nokey('scriptingLanguage', languages_filter, 'Scripting languages') }}
{% endif %}
{% if licenses_filter %}
{{ filter_dropdown_nokey('license', licenses_filter, 'Licenses') }}
{{ filter_dropdown_nokey('license', licenses_filter, 'Licenses') }}
{% endif %}
{% if status_filter %}
{{ filter_dropdown_nokey('status', status_filter, 'Maintenance status') }}
{{ filter_dropdown_nokey('status', status_filter, 'Maintenance status') }}
{% endif %}
<a href="{{ request.base_url }}?view={{ view }}">Reset</a>
@@ -117,13 +117,13 @@
<div>
{% if view == 'list' %}
{% for resource in resources %}
{{ resource_list(resource, loop) }}
{% endfor %}
{% for resource in resources %}
{{ resource_list(resource, loop) }}
{% endfor %}
{% else %}
{% for resource in resources %}
{{ resource_with_related(resource, loop) }}
{% endfor %}
{% for resource in resources %}
{{ resource_with_related(resource, loop) }}
{% endfor %}
{% endif %}
</div>


+ 3
- 3
web/app/tool.py 查看文件

@@ -24,14 +24,14 @@ def get_tools():
tools_query = Resource.query.filter_by(type=resource_type)
for key in request.args.keys():
if key != 'view':
if key == 'practice':
if (key == 'practice' and request.args.get(key) != ''):
tools_1 = tools_query.join(Relationship, Relationship.first_resource_id == Resource.id, isouter=True).filter(Relationship.second_resource_id==request.args.get(key))
tools_2 = tools_query.join(Relationship, Relationship.second_resource_id == Resource.id, isouter=True).filter(Relationship.first_resource_id==request.args.get(key))
tools_query = tools_1.union(tools_2)
if key == 'scriptingLanguage':
if (key == 'scriptingLanguage' and request.args.get(key) != ''):
regex = request.args.get(key) + "$|" + request.args.get(key) + "\s\/"
tools_query = tools_query.filter(Resource.scriptingLanguage.regexp_match(regex))
if key != 'practice' and key != 'scriptingLanguage':
if ((key != 'practice' and key != 'scriptingLanguage') and request.args.get(key) != ''):
kwargs = {key: request.args.get(key)}
tools_query = tools_query.filter_by(**kwargs)
# finalise the query

Loading…
取消
儲存