1
1

ListFiles.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from flask import abort, jsonify
  2. from flask.views import View
  3. from pycs.database.Database import Database
  4. class ListFiles(View):
  5. """
  6. return a list of files for a given project
  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, project_id: int, start: int, length: int, collection_id: int = None):
  14. # find project
  15. project = self.db.project(project_id)
  16. if project is None:
  17. return abort(404)
  18. # get count and files
  19. if collection_id is not None:
  20. if collection_id == 0:
  21. count = project.count_files_without_collection()
  22. files = list(project.files_without_collection(start, length))
  23. else:
  24. collection = project.collection(collection_id)
  25. if collection is None:
  26. return abort(404)
  27. count = collection.count_files()
  28. files = list(collection.files(start, length))
  29. else:
  30. count = project.count_files()
  31. files = list(project.files(start, length))
  32. # return files
  33. return jsonify({
  34. 'count': count,
  35. 'files': files
  36. })