| from .api import api as api_blueprint | from .api import api as api_blueprint | ||||
| app.register_blueprint(api_blueprint) | app.register_blueprint(api_blueprint) | ||||
| # blueprint for search parts of app | |||||
| from .search import search as search_blueprint | |||||
| app.register_blueprint(search_blueprint) | |||||
| return app | return app |
| from .resources import * | from .resources import * | ||||
| from .relationships import * | from .relationships import * | ||||
| from . import db | from . import db | ||||
| from sqlalchemy import text | |||||
| import os | import os | ||||
| book = Blueprint('book', __name__) | book = Blueprint('book', __name__) |
| # @name: search.py | |||||
| # @creation_date: 2023-04-04 | |||||
| # @license: The MIT License <https://opensource.org/licenses/MIT> | |||||
| # @author: Simon Bowie <ad7588@coventry.ac.uk> | |||||
| # @purpose: Search route for search results | |||||
| # @acknowledgements: | |||||
| # https://medium.com/@joseortizcosta/search-utility-with-flask-and-mysql-60bb8ee83dad | |||||
| from flask import Blueprint, render_template, request, flash, redirect, url_for | |||||
| from .models import Resource | |||||
| from sqlalchemy import or_ | |||||
| search = Blueprint('search', __name__) | |||||
| #endpoint for search | |||||
| @search.route('/search', methods=['GET']) | |||||
| def basic_search(): | |||||
| if request.args.get('query') is not None: | |||||
| query = request.args.get('query') | |||||
| results = Resource.query.filter( | |||||
| or_( | |||||
| Resource.name.ilike('%' + query + '%'), | |||||
| Resource.description.ilike('%' + query + '%'), | |||||
| Resource.developer.ilike('%' + query + '%'), | |||||
| Resource.longDescription.ilike('%' + query + '%'), | |||||
| Resource.experimental.ilike('%' + query + '%'), | |||||
| Resource.considerations.ilike('%' + query + '%'), | |||||
| Resource.references.ilike('%' + query + '%'), | |||||
| Resource.author.ilike('%' + query + '%'), | |||||
| Resource.isbn.ilike('%' + query + '%'), | |||||
| Resource.typology.ilike('%' + query + '%'), | |||||
| )).all() | |||||
| return render_template('search.html', results=results) | |||||
| else: | |||||
| return redirect(url_for('main.index')) |
| {% endif %} | {% endif %} | ||||
| </div> --> | </div> --> | ||||
| <input class=" text-center text-base border-l-2 border-black pl-1 " type="text" placeholder="Search"> | |||||
| <form action="{{ url_for('search.basic_search') }}"> | |||||
| <input type="text" name="query" class="text-center text-base border-l-2 border-black pl-1" placeholder="Search"> | |||||
| <input type="submit" hidden /> | |||||
| </form> | |||||
| </nav> | </nav> | ||||
| </header> | </header> |
| {% extends 'base.html' %} | |||||
| {% block content %} | |||||
| {% for result in results %} | |||||
| {{ result.name }} | |||||
| {% endfor %} | |||||
| {% endblock %} |
| from .resources import * | from .resources import * | ||||
| from .relationships import * | from .relationships import * | ||||
| from . import db | from . import db | ||||
| from sqlalchemy import text | |||||
| import os | import os | ||||
| tool = Blueprint('tool', __name__) | tool = Blueprint('tool', __name__) |