| # route for displaying all books in database | # route for displaying all books in database | ||||
| @book.route('/books') | @book.route('/books') | ||||
| def get_books(): | def get_books(): | ||||
| view = request.args.get('view') | |||||
| type = 'book' | type = 'book' | ||||
| books = Resource.query.filter_by(type=type).all() | books = Resource.query.filter_by(type=type).all() | ||||
| for key in request.args.keys(): | for key in request.args.keys(): | ||||
| if key == 'practice': | |||||
| 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).all() | |||||
| if key != 'view': | |||||
| if key == 'practice': | |||||
| 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).all() | |||||
| # get number of books | # get number of books | ||||
| count = len(books) | count = len(books) | ||||
| # append relationships to each book | |||||
| append_relationships_multiple(books) | |||||
| if view != 'list': | |||||
| # append relationships to each book | |||||
| append_relationships_multiple(books) | |||||
| # get filters | # get filters | ||||
| # practices | # practices | ||||
| practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name) | practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name) | ||||
| year_filter = get_filter_values('year', type) | year_filter = get_filter_values('year', type) | ||||
| # typology | # typology | ||||
| typology_filter = get_filter_values('typology', type) | typology_filter = get_filter_values('typology', type) | ||||
| return render_template('resources.html', resources=books, type=type, practices_filter=practices_filter, year_filter=year_filter, typology_filter=typology_filter, count=count) | |||||
| return render_template('resources.html', resources=books, type=type, practices_filter=practices_filter, year_filter=year_filter, typology_filter=typology_filter, count=count, view=view) | |||||
| # route for displaying a single book based on the ID in the database | # route for displaying a single book based on the ID in the database | ||||
| @book.route('/books/<int:book_id>') | @book.route('/books/<int:book_id>') |
| # route for index page | # route for index page | ||||
| @main.route('/') | @main.route('/') | ||||
| def index(): | def index(): | ||||
| view = request.args.get('view') | |||||
| tools = Resource.query.filter_by(type='tool').order_by(func.random()).limit(6).all() | tools = Resource.query.filter_by(type='tool').order_by(func.random()).limit(6).all() | ||||
| # append relationships to each tool | |||||
| append_relationships_multiple(tools) | |||||
| if view != 'list': | |||||
| # append relationships to each tool | |||||
| append_relationships_multiple(tools) | |||||
| books = Resource.query.filter_by(type='book').order_by(func.random()).limit(6).all() | books = Resource.query.filter_by(type='book').order_by(func.random()).limit(6).all() | ||||
| # append relationships to each book | |||||
| append_relationships_multiple(books) | |||||
| if view != 'list': | |||||
| # append relationships to each book | |||||
| append_relationships_multiple(books) | |||||
| with open('content/home.md', 'r') as f: | with open('content/home.md', 'r') as f: | ||||
| text = f.read() | text = f.read() | ||||
| text = markdown.markdown(text) | text = markdown.markdown(text) | ||||
| book_showcase = get_full_resource('69') | book_showcase = get_full_resource('69') | ||||
| return render_template('index.html', text=text, tools=tools, books=books, book=book_showcase) | |||||
| return render_template('index.html', text=text, tools=tools, books=books, book=book_showcase, view=view) | |||||
| # route for profile page | # route for profile page | ||||
| @main.route('/profile') | @main.route('/profile') |
| # route for displaying all practices in database | # route for displaying all practices in database | ||||
| @practice.route('/practices') | @practice.route('/practices') | ||||
| def get_practices(): | def get_practices(): | ||||
| view = request.args.get('view') | |||||
| practices = Resource.query.filter_by(type='practice').all() | practices = Resource.query.filter_by(type='practice').all() | ||||
| # get number of practices | # get number of practices | ||||
| count = len(practices) | count = len(practices) | ||||
| # append relationships to each practice | |||||
| append_relationships_multiple(practices) | |||||
| return render_template('resources.html', resources=practices, type='practice', count=count) | |||||
| if view != 'list': | |||||
| # append relationships to each practice | |||||
| append_relationships_multiple(practices) | |||||
| return render_template('resources.html', resources=practices, type='practice', count=count, view=view) | |||||
| # route for displaying a single practice based on the ID in the database | # route for displaying a single practice based on the ID in the database | ||||
| @practice.route('/practices/<int:practice_id>') | @practice.route('/practices/<int:practice_id>') |
| <div class="ml-[13rem] text my-8 meta max-w-[30rem]"> | <div class="ml-[13rem] text my-8 meta max-w-[30rem]"> | ||||
| {{ text|safe }} | {{ text|safe }} | ||||
| <br/> | |||||
| <a href="{{ url_for(request.endpoint, view='list') }}">LIST VIEW</a> | |||||
| </div> | </div> | ||||
| <div class="h-full "> | <div class="h-full "> | ||||
| <div class="flex h-full gap-8 justify-start items-center "> | <div class="flex h-full gap-8 justify-start items-center "> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| {% for tool in tools %} | |||||
| {{ resource_with_related(tool, loop, false) }} | |||||
| {% if view == 'list' %} | |||||
| THIS IS LIST VIEW | |||||
| {% else %} | |||||
| {% for tool in tools %} | |||||
| {% endfor %} | |||||
| {{ resource_with_related(tool, loop, false) }} | |||||
| {% for book in books %} | |||||
| {% endfor %} | |||||
| {{ resource_with_related(book, loop, false) }} | |||||
| {% for book in books %} | |||||
| {% endfor %} | |||||
| {{ resource_with_related(book, loop, false) }} | |||||
| {% for tool in tools2 %} | |||||
| {% endfor %} | |||||
| {{ resource_with_related(tool, loop, false) }} | |||||
| {% for tool in tools2 %} | |||||
| {% endfor %} | |||||
| {{ resource_with_related(tool, loop, false) }} | |||||
| {% for book in books2 %} | |||||
| {% endfor %} | |||||
| {{ resource_with_related(book, loop, false) }} | |||||
| {% for book in books2 %} | |||||
| {% endfor %} | |||||
| {{ resource_with_related(book, loop, false) }} | |||||
| {% endfor %} | |||||
| {% endif %} | |||||
| </div> | </div> | ||||
| {% endblock %} | {% endblock %} |
| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ultricies egestas felis at dignissim. Morbi ut bibendum | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ultricies egestas felis at dignissim. Morbi ut bibendum | ||||
| nisl. Integer ac sollicitudin risus. Vivamus et est est. Ut vitae lacus nec justo tincidunt interdum. Fusce sapien odio, | nisl. Integer ac sollicitudin risus. Vivamus et est est. Ut vitae lacus nec justo tincidunt interdum. Fusce sapien odio, | ||||
| commodo nec est et, interdum varius risus. Curabitur vehicula consequat auctor. | commodo nec est et, interdum varius risus. Curabitur vehicula consequat auctor. | ||||
| <br/><br/> | |||||
| <a href="{{ url_for(request.endpoint, view='list') }}">LIST VIEW</a> | |||||
| </div> | </div> | ||||
| <div class="h-full "> | <div class="h-full "> | ||||
| <div class="flex h-full gap-8 justify-start items-center "> | <div class="flex h-full gap-8 justify-start items-center "> | ||||
| <div class="filter-options my-4" x-show="expandFilters"> | <div class="filter-options my-4" x-show="expandFilters"> | ||||
| {% for practice in practices_filter %} | {% for practice in practices_filter %} | ||||
| <div {% if request.args.get('practice')==practice[0]|string %} class="active" {% endif %}> | <div {% if request.args.get('practice')==practice[0]|string %} class="active" {% endif %}> | ||||
| <a href="/{{type + 's'}}?practice={{practice[0]}}" hx-target="#resources" hx-select="#resources">{{ practice[1] }}</a> | |||||
| <a href="{{ url_for(request.endpoint, practice=practice[0]) }}" hx-target="#resources" hx-select="#resources">{{ practice[1] }}</a> | |||||
| </div> | </div> | ||||
| {% endfor %} | {% endfor %} | ||||
| </div> | </div> | ||||
| <div class="filter-options my-4" x-show="expandFilters"> | <div class="filter-options my-4" x-show="expandFilters"> | ||||
| {% for year in year_filter %} | {% for year in year_filter %} | ||||
| <div {% if request.args.get('year')==year %} class="active" {% endif %}> | <div {% if request.args.get('year')==year %} class="active" {% endif %}> | ||||
| <a href="/books?year={{year}}" hx-target="#resources" hx-select="#resources">{{ year }}</a> | |||||
| <a href="{{ url_for(request.endpoint, year=year) }}" hx-target="#resources" hx-select="#resources">{{ year }}</a> | |||||
| </div> | </div> | ||||
| {% endfor %} | {% endfor %} | ||||
| </div> | </div> | ||||
| <div class="filter-options my-4" x-show="expandFilters"> | <div class="filter-options my-4" x-show="expandFilters"> | ||||
| {% for typology in typology_filter %} | {% for typology in typology_filter %} | ||||
| <div {% if request.args.get('typology')==typology %} class="active" {% endif %}> | <div {% if request.args.get('typology')==typology %} class="active" {% endif %}> | ||||
| <a href="/books?typology={{typology}}" hx-target="#resources" hx-select="#resources">{{ typology }}</a> | |||||
| <a href="{{ url_for(request.endpoint, typology=typology) }}" hx-target="#resources" hx-select="#resources">{{ typology }}</a> | |||||
| </div> | </div> | ||||
| {% endfor %} | {% endfor %} | ||||
| </div> | </div> | ||||
| <div class="filter-options my-4" x-show="expandFilters"> | <div class="filter-options my-4" x-show="expandFilters"> | ||||
| {% for language in languages_filter %} | {% for language in languages_filter %} | ||||
| <div {% if request.args.get('scriptingLanguage')==language %} class="active" {% endif %}> | <div {% if request.args.get('scriptingLanguage')==language %} class="active" {% endif %}> | ||||
| <a href="/tools?scriptingLanguage={{language}}" hx-target="#resources" hx-select="#resources">{{ language }}</a> | |||||
| <a href="{{ url_for(request.endpoint, scriptingLanguage=language) }}" hx-target="#resources" hx-select="#resources">{{ language }}</a> | |||||
| </div> | </div> | ||||
| {% endfor %} | {% endfor %} | ||||
| </div> | </div> | ||||
| <div class="filter-options my-4" x-show="expandFilters"> | <div class="filter-options my-4" x-show="expandFilters"> | ||||
| {% for license in licenses_filter %} | {% for license in licenses_filter %} | ||||
| <div {% if request.args.get('license')==license %} class="active" {% endif %}> | <div {% if request.args.get('license')==license %} class="active" {% endif %}> | ||||
| <a href="/tools?license={{license}}" hx-target="#resources" hx-select="#resources">{{ license }}</a> | |||||
| <a href="{{ url_for(request.endpoint, license=license) }}" hx-target="#resources" hx-select="#resources">{{ license }}</a> | |||||
| </div> | </div> | ||||
| {% endfor %} | {% endfor %} | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div> | <div> | ||||
| {% if view == 'list' %} | |||||
| THIS IS LIST VIEW | |||||
| {% else %} | |||||
| {% for resource in resources %} | {% for resource in resources %} | ||||
| {{ resource_with_related(resource, loop) }} | {{ resource_with_related(resource, loop) }} | ||||
| {% endfor %} | |||||
| {% endfor %} | |||||
| {% endif %} | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| </div> | </div> |
| # route for displaying all tools in database | # route for displaying all tools in database | ||||
| @tool.route('/tools') | @tool.route('/tools') | ||||
| def get_tools(): | def get_tools(): | ||||
| view = request.args.get('view') | |||||
| type = 'tool' | type = 'tool' | ||||
| tools = Resource.query.filter_by(type=type).all() | tools = Resource.query.filter_by(type=type).all() | ||||
| for key in request.args.keys(): | for key in request.args.keys(): | ||||
| if key == 'practice': | |||||
| 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)).all() | |||||
| else: | |||||
| kwargs = {'type': type, key: request.args.get(key)} | |||||
| tools = Resource.query.filter_by(**kwargs).all() | |||||
| if key != 'view': | |||||
| if key == 'practice': | |||||
| 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)).all() | |||||
| else: | |||||
| kwargs = {'type': type, key: request.args.get(key)} | |||||
| tools = Resource.query.filter_by(**kwargs).all() | |||||
| # get number of tools | # get number of tools | ||||
| count = len(tools) | count = len(tools) | ||||
| # append relationships to each tool | |||||
| append_relationships_multiple(tools) | |||||
| if view != 'list': | |||||
| # append relationships to each tool | |||||
| append_relationships_multiple(tools) | |||||
| # get filters | # get filters | ||||
| # practices | # practices | ||||
| practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name) | practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name) | ||||
| licenses_filter = get_filter_values('license', type) | licenses_filter = get_filter_values('license', type) | ||||
| # language | # language | ||||
| languages_filter = get_filter_values('scriptingLanguage', type) | languages_filter = get_filter_values('scriptingLanguage', type) | ||||
| return render_template('resources.html', resources=tools, type=type, practices_filter=practices_filter, licenses_filter=licenses_filter, languages_filter=languages_filter, count=count) | |||||
| return render_template('resources.html', resources=tools, type=type, practices_filter=practices_filter, licenses_filter=licenses_filter, languages_filter=languages_filter, count=count, view=view) | |||||
| # route for displaying a single tool based on the ID in the database | # route for displaying a single tool based on the ID in the database | ||||
| @tool.route('/tools/<int:tool_id>') | @tool.route('/tools/<int:tool_id>') |