6
0

GetPreviousAndNextFile.py 746 B

123456789101112131415161718192021222324252627282930
  1. from flask import abort, jsonify
  2. from flask.views import View
  3. from pycs.database.File import File
  4. class GetPreviousAndNextFile(View):
  5. """
  6. return the previous and the next file
  7. """
  8. # pylint: disable=arguments-differ
  9. methods = ['GET']
  10. def dispatch_request(self, file_id: int):
  11. # get file from database
  12. file = File.query.get(file_id)
  13. if file is None:
  14. return abort(404)
  15. # get previous and next
  16. result = {
  17. 'previous': file.previous(),
  18. 'next': file.next(),
  19. 'previousInCollection': file.previous_in_collection(),
  20. 'nextInCollection': file.next_in_collection()
  21. }
  22. # return data
  23. return jsonify(result)