1234567891011121314151617181920212223242526272829303132 |
- from flask import abort, jsonify
- from flask.views import View
- from pycs.database.Database import Database
- class GetPreviousAndNextFile(View):
- """
- return the previous and the next file
- """
- # pylint: disable=arguments-differ
- methods = ['GET']
- def __init__(self, db: Database):
- # pylint: disable=invalid-name
- self.db = db
- def dispatch_request(self, file_id: int):
- # get file from database
- file = self.db.file(file_id)
- if file is None:
- return abort(404)
- # get previous and next
- result = {
- 'previous': file.previous(),
- 'next': file.next()
- }
- # return data
- return jsonify(result)
|