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.

27 lines
881B

  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 flask_login import login_required, current_user
  9. from .models import Resource
  10. from werkzeug.exceptions import abort
  11. from . import db
  12. # function to retrieve data about a single resource from the database
  13. def get_resource(resource_id):
  14. resource = Resource.query.filter_by(id=resource_id).first()
  15. if resource is None:
  16. abort(404)
  17. return resource
  18. # function to delete a single resource
  19. def delete_resource(resource_id):
  20. deletion = Resource.query.get(resource_id)
  21. db.session.delete(deletion)
  22. db.session.commit()
  23. flash('Successfully deleted!')