6
0

GetPreviousAndNextFile.py 709 B

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