You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 line
828B

  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!')