| else: | else: | ||||
| kwargs = {'type': type, key: request.args.get(key)} | kwargs = {'type': type, key: request.args.get(key)} | ||||
| books = Resource.query.filter_by(**kwargs).all() | books = Resource.query.filter_by(**kwargs).all() | ||||
| # get number of books | |||||
| count = len(books) | |||||
| # append relationships to each book | # append relationships to each book | ||||
| append_relationships_multiple(books) | append_relationships_multiple(books) | ||||
| # get filters | # get filters | ||||
| 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) | |||||
| return render_template('resources.html', resources=books, type=type, practices_filter=practices_filter, year_filter=year_filter, typology_filter=typology_filter, count=count) | |||||
| # 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>') |
| @practice.route('/practices') | @practice.route('/practices') | ||||
| def get_practices(): | def get_practices(): | ||||
| practices = Resource.query.filter_by(type='practice').all() | practices = Resource.query.filter_by(type='practice').all() | ||||
| # get number of practices | |||||
| count = len(practices) | |||||
| # append relationships to each practice | # append relationships to each practice | ||||
| append_relationships_multiple(practices) | append_relationships_multiple(practices) | ||||
| return render_template('resources.html', resources=practices, type='practice') | |||||
| return render_template('resources.html', resources=practices, type='practice', count=count) | |||||
| # 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>') |
| pass | pass | ||||
| # function to get full metadata for a book and combine into one object | # function to get full metadata for a book and combine into one object | ||||
| # TO BE DELETED | |||||
| def get_book(resource_id): | def get_book(resource_id): | ||||
| book = get_resource(resource_id) | book = get_resource(resource_id) | ||||
| book_data = get_book_data(book.isbn) | book_data = get_book_data(book.isbn) |
| {% endif %} | {% endif %} | ||||
| {% endmacro %} | {% endmacro %} | ||||
| {% macro book_with_related(resource, relationships, pre_title='', post_title='Related') %} | |||||
| {% macro book_with_related(resource, loop, relationships, pre_title='', post_title='Related') %} | |||||
| <div class="w-full overflow-x-scroll my-8 pb-12 border-b-2 border-black"> | <div class="w-full overflow-x-scroll my-8 pb-12 border-b-2 border-black"> | ||||
| <div class="grid lg:grid-rows-[auto,auto,auto] grid-flow-col" > | <div class="grid lg:grid-rows-[auto,auto,auto] grid-flow-col" > | ||||
| <div class=" w-40 pl-16 pt-4 row-start-1 "> | <div class=" w-40 pl-16 pt-4 row-start-1 "> | ||||
| {% if pre_title == '' %} | {% if pre_title == '' %} | ||||
| <p>1 / 34</p> | |||||
| <p>{{loop.index}} / {{count}}</p> | |||||
| {% else %} | {% else %} | ||||
| <p>{{ pre_title }}</p> | <p>{{ pre_title }}</p> | ||||
| {% endif %} | {% endif %} | ||||
| </div> | </div> | ||||
| {% endmacro %} | {% endmacro %} | ||||
| {% macro resource_with_related(resource, pre_title='', post_title='Related') %} | |||||
| {% macro resource_with_related(resource, loop, pre_title='', post_title='Related') %} | |||||
| <div class="w-full overflow-x-scroll my-8 pb-12 border-b-2 border-black"> | <div class="w-full overflow-x-scroll my-8 pb-12 border-b-2 border-black"> | ||||
| <div class="grid lg:grid-rows-[auto,auto,auto] grid-flow-col" > | <div class="grid lg:grid-rows-[auto,auto,auto] grid-flow-col" > | ||||
| <div class=" w-40 pl-16 pt-4 row-start-1 "> | <div class=" w-40 pl-16 pt-4 row-start-1 "> | ||||
| {% if pre_title == '' %} | {% if pre_title == '' %} | ||||
| <p>1 / 34</p> | |||||
| <p>{{loop.index}} / {{count}}</p> | |||||
| {% else %} | {% else %} | ||||
| <p>{{ pre_title }}</p> | <p>{{ pre_title }}</p> | ||||
| {% endif %} | {% endif %} |
| <div class="right lg:mt-16 max-w-[30rem] mx-auto p-4"> | <div class="right lg:mt-16 max-w-[30rem] mx-auto p-4"> | ||||
| {{ relationships_links(relationships) }} | {{ relationships_links(relationships) }} | ||||
| {% if resource.tools %} | {% if resource.tools %} | ||||
| TOOLS: | TOOLS: | ||||
| {% for tool in resource.tools %} | {% for tool in resource.tools %} |
| <div> | <div> | ||||
| {% for resource in resources %} | {% for resource in resources %} | ||||
| {% if resource.tools %} | |||||
| {% if resource.tools %} | |||||
| TOOLS: | TOOLS: | ||||
| {% for tool in resource.tools %} | {% for tool in resource.tools %} | ||||
| {{ tool.name }}; | {{ tool.name }}; | ||||
| {{ book.name }}; | {{ book.name }}; | ||||
| {% endfor %} | {% endfor %} | ||||
| {% endif %} | {% endif %} | ||||
| {{ resource_with_related(resource) }} | |||||
| {{ resource_with_related(resource, loop) }} | |||||
| {% endfor %} | {% endfor %} | ||||
| </div> | </div> | ||||
| </div> | </div> |
| else: | else: | ||||
| kwargs = {'type': type, key: request.args.get(key)} | kwargs = {'type': type, key: request.args.get(key)} | ||||
| tools = Resource.query.filter_by(**kwargs).all() | tools = Resource.query.filter_by(**kwargs).all() | ||||
| # get number of tools | |||||
| count = len(tools) | |||||
| # append relationships to each tool | # append relationships to each tool | ||||
| append_relationships_multiple(tools) | append_relationships_multiple(tools) | ||||
| # get filters | # get filters | ||||
| 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) | |||||
| return render_template('resources.html', resources=tools, type=type, practices_filter=practices_filter, licenses_filter=licenses_filter, languages_filter=languages_filter, count=count) | |||||
| # 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>') |