| @@ -21,15 +21,17 @@ book = Blueprint('book', __name__) | |||
| @book.route('/books') | |||
| def get_books(): | |||
| type = 'book' | |||
| books = Resource.query.filter_by(type=type) | |||
| books = Resource.query.filter_by(type=type).all() | |||
| for key in request.args.keys(): | |||
| 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) + ' AND Resource.type="' + type + '";' | |||
| with db.engine.connect() as conn: | |||
| books = conn.execute(text(query)) | |||
| books = Resource.query.join(Relationship, Relationship.first_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.second_resource_id==request.args.get(key)).all() | |||
| also_books = Resource.query.join(Relationship, Relationship.second_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.first_resource_id==request.args.get(key)).all() | |||
| books = books + also_books | |||
| else: | |||
| kwargs = {'type': type, key: request.args.get(key)} | |||
| books = Resource.query.filter_by(**kwargs) | |||
| books = Resource.query.filter_by(**kwargs).all() | |||
| # append relationships to each book | |||
| append_relationships_multiple(books) | |||
| # get filters | |||
| # practices | |||
| practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name) | |||
| @@ -20,7 +20,11 @@ main = Blueprint('main', __name__) | |||
| @main.route('/') | |||
| def index(): | |||
| tools = Resource.query.filter_by(type='tool').order_by(func.random()).limit(6).all() | |||
| # append relationships to each tool | |||
| append_relationships_multiple(tools) | |||
| books = Resource.query.filter_by(type='book').order_by(func.random()).limit(6).all() | |||
| # append relationships to each book | |||
| append_relationships_multiple(books) | |||
| with open('content/home.md', 'r') as f: | |||
| text = f.read() | |||
| text = markdown.markdown(text) | |||
| @@ -36,9 +40,7 @@ def profile(): | |||
| # route for test page | |||
| @main.route('/test') | |||
| def test(): | |||
| tool_id = '69' | |||
| tool = get_full_resource(tool_id) | |||
| return render_template('test.html', resource=tool) | |||
| return render_template('test.html') | |||
| # route for about page | |||
| @main.route('/about') | |||
| @@ -19,7 +19,9 @@ practice = Blueprint('practice', __name__) | |||
| # route for displaying all practices in database | |||
| @practice.route('/practices') | |||
| def get_practices(): | |||
| practices = Resource.query.filter_by(type='practice') | |||
| practices = Resource.query.filter_by(type='practice').all() | |||
| # append relationships to each practice | |||
| append_relationships_multiple(practices) | |||
| return render_template('resources.html', resources=practices, type='practice') | |||
| # route for displaying a single practice based on the ID in the database | |||
| @@ -40,29 +40,32 @@ def append_relationships(resource): | |||
| for relationship in relationships: | |||
| if relationship.type == 'tool': | |||
| if 'tools' not in resource.__dict__.keys(): | |||
| resource.__dict__['tools'] = relationship | |||
| elif type(resource.__dict__['tools']) == list: | |||
| resource.__dict__['tools'] = [] | |||
| resource.__dict__['tools'].append(relationship) | |||
| else: | |||
| resource.__dict__['tools'] = [resource.__dict__['tools'], relationship] | |||
| resource.__dict__['tools'].append(relationship) | |||
| elif relationship.type == 'practice': | |||
| if 'practices' not in resource.__dict__.keys(): | |||
| resource.__dict__['practices'] = relationship | |||
| elif type(resource.__dict__['practices']) == list: | |||
| resource.__dict__['practices'] = [] | |||
| resource.__dict__['practices'].append(relationship) | |||
| else: | |||
| resource.__dict__['practices'] = [resource.__dict__['practices'], relationship] | |||
| resource.__dict__['practices'].append(relationship) | |||
| elif relationship.type == 'book': | |||
| if 'books' not in resource.__dict__.keys(): | |||
| resource.__dict__['books'] = relationship | |||
| elif type(resource.__dict__['books']) == list: | |||
| resource.__dict__['books'] = [] | |||
| resource.__dict__['books'].append(relationship) | |||
| else: | |||
| resource.__dict__['books'] = [resource.__dict__['books'], relationship] | |||
| resource.__dict__['books'].append(relationship) | |||
| return resource | |||
| else: | |||
| return resource | |||
| # function to append relationships to a dictionary of resources | |||
| def append_relationships_multiple(resources): | |||
| for index, resource in enumerate(resources): | |||
| resources[index] = append_relationships(resource) | |||
| return resources | |||
| # function to add a relationship to a linked resource | |||
| def add_relationship(resource_id, linked_resource_id): | |||
| first_resource_id = resource_id | |||
| @@ -122,6 +122,24 @@ | |||
| <div class="right lg:mt-16 max-w-[30rem] mx-auto p-4"> | |||
| {{ relationships_links(relationships) }} | |||
| {% if resource.tools %} | |||
| TOOLS: | |||
| {% for tool in resource.tools %} | |||
| {{ tool.name }}; | |||
| {% endfor %} | |||
| {% endif %} | |||
| {% if resource.practices %} | |||
| PRACTICES: | |||
| {% for practice in resource.practices %} | |||
| {{ practice.name }}; | |||
| {% endfor %} | |||
| {% endif %} | |||
| {% if resource.books %} | |||
| BOOKS: | |||
| {% for book in resource.books %} | |||
| {{ book.name }}; | |||
| {% endfor %} | |||
| {% endif %} | |||
| </div> | |||
| </div> | |||
| @@ -1,7 +1,6 @@ | |||
| {% extends 'base.html' %} | |||
| {% block content %} | |||
| <!-- <div class="cell-margin"> | |||
| <div class="mb-8"> | |||
| <h2> | |||
| @@ -96,7 +95,25 @@ | |||
| <div> | |||
| {% for resource in resources %} | |||
| {{ resource_with_related(resource) }} | |||
| {% if resource.tools %} | |||
| TOOLS: | |||
| {% for tool in resource.tools %} | |||
| {{ tool.name }}; | |||
| {% endfor %} | |||
| {% endif %} | |||
| {% if resource.practices %} | |||
| PRACTICES: | |||
| {% for practice in resource.practices %} | |||
| {{ practice.name }}; | |||
| {% endfor %} | |||
| {% endif %} | |||
| {% if resource.books %} | |||
| BOOKS: | |||
| {% for book in resource.books %} | |||
| {{ book.name }}; | |||
| {% endfor %} | |||
| {% endif %} | |||
| {{ resource_with_related(resource) }} | |||
| {% endfor %} | |||
| </div> | |||
| </div> | |||
| @@ -21,18 +21,20 @@ tool = Blueprint('tool', __name__) | |||
| @tool.route('/tools') | |||
| def get_tools(): | |||
| type = 'tool' | |||
| tools = Resource.query.filter_by(type=type) | |||
| tools = Resource.query.filter_by(type=type).all() | |||
| for key in request.args.keys(): | |||
| 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) + ' AND Resource.type="' + type + '";' | |||
| with db.engine.connect() as conn: | |||
| tools = conn.execute(text(query)) | |||
| tools = Resource.query.join(Relationship, Relationship.first_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.second_resource_id==request.args.get(key)).all() | |||
| also_tools = Resource.query.join(Relationship, Relationship.second_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.first_resource_id==request.args.get(key)).all() | |||
| tools = tools + also_tools | |||
| elif key == 'scriptingLanguage': | |||
| regex = request.args.get(key) + "$|" + request.args.get(key) + "\s\/" | |||
| tools = Resource.query.filter_by(type=type).filter(Resource.scriptingLanguage.regexp_match(regex)) | |||
| tools = Resource.query.filter_by(type=type).filter(Resource.scriptingLanguage.regexp_match(regex)).all() | |||
| else: | |||
| kwargs = {'type': type, key: request.args.get(key)} | |||
| tools = Resource.query.filter_by(**kwargs) | |||
| tools = Resource.query.filter_by(**kwargs).all() | |||
| # append relationships to each tool | |||
| append_relationships_multiple(tools) | |||
| # get filters | |||
| # practices | |||
| practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name) | |||