6
0

GetPreviousAndNextFile.py 851 B

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