6
0

ListFiles.py 993 B

12345678910111213141516171819202122232425262728293031323334
  1. from flask import abort
  2. from flask import jsonify
  3. from flask.views import View
  4. from pycs.database.File import File
  5. from pycs.frontend.endpoints.base import ListView
  6. class ListFiles(ListView):
  7. """
  8. return a list of files for a given project
  9. with offset and limit parameters
  10. """
  11. # pylint: disable=arguments-differ
  12. methods = ['GET']
  13. model = File
  14. def get_objects(self, project_id: int, start: int, length: int, collection_id: int = None):
  15. # find project files
  16. files = File.query.filter_by(project_id=project_id)
  17. if collection_id == 0:
  18. # files without a collection
  19. files = files.filter(File.collection_id == None)
  20. elif collection_id is not None:
  21. # files of a collection
  22. files = files.filter(File.collection_id == collection_id)
  23. count = files.count()
  24. files = files.order_by(File.id).offset(start).limit(length).all()
  25. return dict(count=count, files=files)