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.

resources.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. # @name: resources.py
  2. # @version: 0.1
  3. # @creation_date: 2022-02-23
  4. # @license: The MIT License <https://opensource.org/licenses/MIT>
  5. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  6. # @purpose: functions for resources
  7. # @acknowledgements:
  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 .models import Relationship
  12. from werkzeug.exceptions import abort
  13. from . import db
  14. # function to retrieve data about a single resource from the database
  15. def get_resource(resource_id):
  16. resource = Resource.query.filter_by(id=resource_id).first()
  17. if resource is None:
  18. abort(404)
  19. return resource
  20. # function to retrieve linked resources
  21. def get_linked_resources(resource_id):
  22. relationships = Relationship.query.filter_by(first_resource_id=resource_id).first()
  23. if relationships:
  24. resource_id = relationships.second_resource_id
  25. resources = Resource.query.filter_by(id=resource_id).all()
  26. return resources
  27. # function to delete a single resource
  28. def delete_resource(resource_id):
  29. deletion = Resource.query.get(resource_id)
  30. db.session.delete(deletion)
  31. db.session.commit()
  32. flash('Successfully deleted!')