from flask import abort from flask import jsonify from flask.views import View from pycs.database.Collection import Collection class ListCollections(View): """ return a list of collections for a given project """ # pylint: disable=arguments-differ methods = ['GET'] def dispatch_request(self, project_id: int): # get collection list collections = Collections.query.filter_by(project_id=project_id).all() # disable autoselect if there are no elements in the collection found = False for collection in collections: if collection.autoselect: if found: collection.autoselect = False elif collection.count_files() == 0: collection.autoselect = False found = True # return files return jsonify(collections)