from flask import abort from flask import jsonify from flask.views import View from pycs.database.Project import Project class ListFiles(View): """ return a list of files for a given project """ # pylint: disable=arguments-differ methods = ['GET'] def dispatch_request(self, project_id: int, start: int, length: int, collection_id: int = None): # find project project = Project.query.get(project_id) if project is None: return abort(404) # get count and files if collection_id is None: count = project.count_files() files = list(project.get_files(start, length)) elif collection_id == 0: count = project.count_files_without_collection() files = list(project.files_without_collection(start, length)) else: collection = project.collection(collection_id) if collection is None: return abort(404) count = collection.count_files() files = list(collection.files(start, length)) # return files return jsonify({ 'count': count, 'files': files })