Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

36 lines
1.2KB

  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 .models import Relationship
  11. from werkzeug.exceptions import abort
  12. from . import db
  13. # function to retrieve data about a single resource from the database
  14. def get_resource(resource_id):
  15. resource = Resource.query.filter_by(id=resource_id).first()
  16. if resource is None:
  17. abort(404)
  18. return resource
  19. # function to retrieve linked resources
  20. def get_linked_resources(resource_id):
  21. relationships = Relationship.query.filter_by(first_resource_id=resource_id).first()
  22. if relationships:
  23. resource_id = relationships.second_resource_id
  24. resources = Resource.query.filter_by(id=resource_id).all()
  25. return resources
  26. # function to delete a single resource
  27. def delete_resource(resource_id):
  28. deletion = Resource.query.get(resource_id)
  29. db.session.delete(deletion)
  30. db.session.commit()
  31. flash('Successfully deleted!')