# function to get filters for a specific field | # function to get filters for a specific field | ||||
def get_filter_values(field): | def get_filter_values(field): | ||||
# get field values for filter | |||||
field_filter = Resource.query.filter_by(type='tool').with_entities(getattr(Resource, field)) | 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] | 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)) | field_filter = list(dict.fromkeys(field_filter)) | ||||
# filter None values from list | |||||
field_filter = filter(None, field_filter) | field_filter = filter(None, field_filter) | ||||
# sort list by alphabetical order | |||||
field_filter = sorted(field_filter) | field_filter = sorted(field_filter) | ||||
return field_filter | return field_filter |
{% extends 'base.html' %} | {% extends 'base.html' %} | ||||
{% block content %} | {% block content %} | ||||
{{ languages_filter }} | |||||
<div class="row"> | <div class="row"> | ||||
<div class="col-12 text-center"> | <div class="col-12 text-center"> | ||||
<h1>{% block title %} | <h1>{% block title %} |
if key == 'practice': | 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) + ';' | 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) | 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: | else: | ||||
kwargs = {'type': 'tool', key: request.args.get(key)} | kwargs = {'type': 'tool', key: request.args.get(key)} | ||||
tools = Resource.query.filter_by(**kwargs) | tools = Resource.query.filter_by(**kwargs) |