Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # @name: tool.py
  2. # @creation_date: 2021-10-20
  3. # @license: The MIT License <https://opensource.org/licenses/MIT>
  4. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  5. # @purpose: tool route for tool-related functions and pages
  6. # @acknowledgements:
  7. # https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3
  8. from flask import Blueprint, render_template, request, flash, redirect, url_for
  9. from flask_login import login_required, current_user
  10. from .models import Resource
  11. from .resources import *
  12. from werkzeug.exceptions import abort
  13. from . import db
  14. tool = Blueprint('tool', __name__)
  15. # route for displaying all tools in database
  16. @tool.route('/tools')
  17. def get_tools():
  18. tools = Resource.query.filter_by(type='tool')
  19. return render_template('tools.html', tools=tools)
  20. # route for displaying a single tool based on the ID in the database
  21. @tool.route('/tools/<int:tool_id>')
  22. def show_tool(tool_id):
  23. tool = get_resource(tool_id)
  24. resources = get_linked_resources(tool_id)
  25. return render_template('tool.html', tool=tool, resources=resources)
  26. # route for editing a single tool based on the ID in the database
  27. @tool.route('/tools/<int:tool_id>/edit', methods=('GET', 'POST'))
  28. @login_required
  29. def edit_tool(tool_id):
  30. tool = get_resource(tool_id)
  31. if request.method == 'POST':
  32. name = request.form['name']
  33. description = request.form['description']
  34. projectUrl = request.form.get('projectUrl')
  35. repositoryUrl = request.form.get('repositoryUrl')
  36. expertiseToUse = request.form.get('expertiseToUse')
  37. expertiseToHost = request.form.get('expertiseToHost')
  38. dependencies = request.form.get('dependencies')
  39. ingestFormats = request.form.get('ingestFormats')
  40. outputFormats = request.form.get('outputFormats')
  41. status = request.form.get('status')
  42. if not name:
  43. flash('Name is required!')
  44. else:
  45. tool = Resource.query.get(tool_id)
  46. tool.name = name
  47. tool.description = description
  48. tool.projectUrl = projectUrl
  49. tool.repositoryUrl = repositoryUrl
  50. tool.dependencies = dependencies
  51. tool.expertiseToUse = expertiseToUse
  52. tool.expertiseToHost = expertiseToHost
  53. tool.ingestFormats = ingestFormats
  54. tool.outputFormats = outputFormats
  55. tool.status = status
  56. db.session.commit()
  57. return redirect(url_for('tool.get_tools'))
  58. return render_template('edit.html', resource=tool)
  59. # route for function to delete a single tool from the edit page
  60. @tool.route('/tools/<int:tool_id>/delete', methods=('POST',))
  61. @login_required
  62. def delete_tool(tool_id):
  63. delete_resource(tool_id)
  64. return redirect(url_for('tool.get_tools'))