您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425
  1. # @name: resources.py
  2. # @creation_date: 2022-02-23
  3. # @license: The MIT License <https://opensource.org/licenses/MIT>
  4. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  5. # @purpose: functions for resources
  6. # @acknowledgements:
  7. from flask import Blueprint, render_template, request, flash, redirect, url_for
  8. from .models import Resource
  9. from werkzeug.exceptions import abort
  10. from . import db
  11. # function to retrieve data about a single resource from the database
  12. def get_resource(resource_id):
  13. resource = Resource.query.filter_by(id=resource_id).first()
  14. if resource is None:
  15. abort(404)
  16. return resource
  17. # function to delete a single resource
  18. def delete_resource(resource_id):
  19. deletion = Resource.query.get(resource_id)
  20. db.session.delete(deletion)
  21. db.session.commit()
  22. flash('Successfully deleted!')