@@ -26,9 +26,16 @@ def delete_resource(resource_id): | |||
# function to get filters for a specific field | |||
def get_filter_values(field): | |||
# get field values for filter | |||
field_filter = Resource.query.filter_by(type='tool').with_entities(getattr(Resource, field)) | |||
# turn SQLAlchemy object into list | |||
field_filter = [i for i, in field_filter] | |||
# split each element on '/' (useful for scriptingLanguage only) | |||
field_filter = [y for x in field_filter for y in x.split(' / ')] | |||
# consolidate duplicate values | |||
field_filter = list(dict.fromkeys(field_filter)) | |||
# filter None values from list | |||
field_filter = filter(None, field_filter) | |||
# sort list by alphabetical order | |||
field_filter = sorted(field_filter) | |||
return field_filter |
@@ -1,6 +1,9 @@ | |||
{% extends 'base.html' %} | |||
{% block content %} | |||
{{ languages_filter }} | |||
<div class="row"> | |||
<div class="col-12 text-center"> | |||
<h1>{% block title %} |
@@ -25,6 +25,9 @@ def get_tools(): | |||
if key == 'practice': | |||
query = 'SELECT Resource.* FROM Resource LEFT JOIN Relationship ON Resource.id=Relationship.first_resource_id WHERE Relationship.second_resource_id=' + request.args.get(key) + ';' | |||
tools = db.engine.execute(query) | |||
elif key == 'scriptingLanguage': | |||
regex = request.args.get(key) + "$|" + request.args.get(key) + "\s\/" | |||
tools = Resource.query.filter(Resource.scriptingLanguage.regexp_match(regex)) | |||
else: | |||
kwargs = {'type': 'tool', key: request.args.get(key)} | |||
tools = Resource.query.filter_by(**kwargs) |