12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- from flask import abort
- from flask import jsonify
- from flask.views import View
- from pycs.database.Project import Project
- class ListProjectFiles(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.get_or_404(project_id)
- # get count and files
- if collection_id is not None:
- if collection_id == 0:
- count = project.count_files_without_collection()
- files = project.files_without_collection(start, length)
- else:
- collection = project.collection(collection_id)
- if collection is None:
- abort(404)
- count = collection.files.count()
- files = collection.get_files(start, length).all()
- else:
- count = project.files.count()
- files = project.get_files(start, length).all()
- # return files
- return jsonify({
- 'count': count,
- 'files': files
- })
|