Kaynağa Gözat

breaking up scriptingLanguage filter

joel
Simon Bowie 2 yıl önce
ebeveyn
işleme
6e3b66bc3d
3 değiştirilmiş dosya ile 13 ekleme ve 0 silme
  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 Dosyayı Görüntüle

@@ -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

+ 3
- 0
web/app/templates/resources.html Dosyayı Görüntüle

@@ -1,6 +1,9 @@
{% extends 'base.html' %}

{% block content %}

{{ languages_filter }}

<div class="row">
<div class="col-12 text-center">
<h1>{% block title %}

+ 3
- 0
web/app/tool.py Dosyayı Görüntüle

@@ -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)

Yükleniyor…
İptal
Kaydet