12345678910111213141516171819202122232425262728293031323334353637383940 |
- from flask import abort, jsonify
- from flask.views import View
- from pycs.database.Database import Database
- class ListCollections(View):
- """
- return a list of collections for a given project
- """
-
- methods = ['GET']
- def __init__(self, db: Database):
-
- self.db = db
- def dispatch_request(self, project_id: int):
-
- project = self.db.project(project_id)
- if project is None:
- return abort(404)
-
- collections = project.collections()
-
- 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 jsonify(collections)
|