intro_text = markdown.markdown(intro_text) | intro_text = markdown.markdown(intro_text) | ||||
# DATABASE QUERY | # DATABASE QUERY | ||||
books_query = Resource.query.filter_by(type=resource_type) | |||||
books_query = Resource.query.filter_by(type=resource_type).filter_by(published=True) | |||||
# FILTERING | # FILTERING | ||||
for key in request.args.keys(): | for key in request.args.keys(): | ||||
# FILTERS MENU | # FILTERS MENU | ||||
# get values for filter menu dropdowns | # get values for filter menu dropdowns | ||||
# practices | # practices | ||||
practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name).all() | |||||
practices_filter = Resource.query.filter_by(type='practice').filter_by(published=True).with_entities(Resource.id, Resource.name).all() | |||||
# year | # year | ||||
year_filter = get_filter_values('year', resource_type) | year_filter = get_filter_values('year', resource_type) | ||||
# typology | # typology |
# all resource types | # all resource types | ||||
id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy | id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy | ||||
created = db.Column(db.DateTime, default=datetime.utcnow) | created = db.Column(db.DateTime, default=datetime.utcnow) | ||||
published = db.Column(db.Boolean) | |||||
type = db.Column(db.Text) | type = db.Column(db.Text) | ||||
name = db.Column(db.Text) | name = db.Column(db.Text) | ||||
description = db.Column(db.Text) | description = db.Column(db.Text) |
intro_text = markdown.markdown(intro_text) | intro_text = markdown.markdown(intro_text) | ||||
# DATABASE QUERY | # DATABASE QUERY | ||||
practices_query = Resource.query.filter_by(type=resource_type) | |||||
practices_query = Resource.query.filter_by(type=resource_type).filter_by(published=True) | |||||
# temporarily removing incomplete practices from main list | # temporarily removing incomplete practices from main list | ||||
practices_query = practices_query.filter( | practices_query = practices_query.filter( |
links = [] | links = [] | ||||
for relationship in primary_relationships: | for relationship in primary_relationships: | ||||
secondary_id = relationship.second_resource_id | secondary_id = relationship.second_resource_id | ||||
links.extend(Resource.query.filter_by(id=secondary_id).all()) | |||||
links.extend(Resource.query.filter_by(id=secondary_id).filter_by(published=True).all()) | |||||
secondary_relationships = Relationship.query.filter_by(second_resource_id=primary_id).all() | secondary_relationships = Relationship.query.filter_by(second_resource_id=primary_id).all() | ||||
if secondary_relationships: | if secondary_relationships: | ||||
for relationship in secondary_relationships: | for relationship in secondary_relationships: | ||||
primary_id = relationship.first_resource_id | primary_id = relationship.first_resource_id | ||||
links.extend(Resource.query.filter_by(id=primary_id).all()) | |||||
links.extend(Resource.query.filter_by(id=primary_id).filter_by(published=True).all()) | |||||
return links | return links | ||||
else: | else: | ||||
secondary_relationships = Relationship.query.filter_by(second_resource_id=primary_id).all() | secondary_relationships = Relationship.query.filter_by(second_resource_id=primary_id).all() | ||||
links = [] | links = [] | ||||
for relationship in secondary_relationships: | for relationship in secondary_relationships: | ||||
primary_id = relationship.first_resource_id | primary_id = relationship.first_resource_id | ||||
links.extend(Resource.query.filter_by(id=primary_id).all()) | |||||
links.extend(Resource.query.filter_by(id=primary_id).filter_by(published=True).all()) | |||||
return links | return links | ||||
# function to append relationships to a resource object | # function to append relationships to a resource object |
# function to retrieve data about a curated list of resources | # function to retrieve data about a curated list of resources | ||||
def get_curated_resources(resource_ids): | def get_curated_resources(resource_ids): | ||||
resources = Resource.query.filter(Resource.id.in_(resource_ids)).order_by(func.random()).all() | |||||
resources = Resource.query.filter(Resource.id.in_(resource_ids)).filter_by(published=True).order_by(func.random()).all() | |||||
# append relationships to each resource | # append relationships to each resource | ||||
append_relationships_multiple(resources) | append_relationships_multiple(resources) | ||||
return resources | return resources |
intro_text = markdown.markdown(intro_text) | intro_text = markdown.markdown(intro_text) | ||||
# DATABASE QUERY | # DATABASE QUERY | ||||
tools_query = Resource.query.filter_by(type=resource_type) | |||||
tools_query = Resource.query.filter_by(type=resource_type).filter_by(published=True) | |||||
# FILTERING | # FILTERING | ||||
for key in request.args.keys(): | for key in request.args.keys(): | ||||
# FILTERS MENU | # FILTERS MENU | ||||
# get values for filter menu dropdowns | # get values for filter menu dropdowns | ||||
# practices | # practices | ||||
practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name).all() | |||||
practices_filter = Resource.query.filter_by(type='practice').filter_by(published=True).with_entities(Resource.id, Resource.name).all() | |||||
# license | # license | ||||
licenses_filter = get_filter_values('license', resource_type) | licenses_filter = get_filter_values('license', resource_type) | ||||
# language | # language |
requests | requests | ||||
marshmallow | marshmallow | ||||
flask-marshmallow | flask-marshmallow | ||||
marshmallow-sqlalchemy | |||||
pandas | pandas |