Browse Source

breaking up scriptingLanguage filter

joel
Simon Bowie 2 years ago
parent
commit
6e3b66bc3d
3 changed files with 13 additions and 0 deletions
  1. +7
    -0
      web/app/resources.py
  2. +3
    -0
      web/app/templates/resources.html
  3. +3
    -0
      web/app/tool.py

+ 7
- 0
web/app/resources.py View File



# 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

+ 3
- 0
web/app/templates/resources.html View File

{% 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 %}

+ 3
- 0
web/app/tool.py View File

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)

Loading…
Cancel
Save