6
0

ListCollections.py 894 B

123456789101112131415161718192021222324252627282930313233
  1. from flask import abort
  2. from flask import jsonify
  3. from flask.views import View
  4. from pycs.database.Collection import Collection
  5. class ListCollections(View):
  6. """
  7. return a list of collections for a given project
  8. """
  9. # pylint: disable=arguments-differ
  10. methods = ['GET']
  11. def dispatch_request(self, project_id: int):
  12. # get collection list
  13. collections = Collections.query.filter_by(project_id=project_id).all()
  14. # disable autoselect if there are no elements in the collection
  15. found = False
  16. for collection in collections:
  17. if collection.autoselect:
  18. if found:
  19. collection.autoselect = False
  20. elif collection.count_files() == 0:
  21. collection.autoselect = False
  22. found = True
  23. # return files
  24. return jsonify(collections)