12345678910111213141516171819202122232425262728293031323334 |
- from flask import abort
- from flask import jsonify
- from flask.views import View
- from pycs.database.File import File
- from pycs.frontend.endpoints.base import ListView
- class ListFiles(ListView):
- """
- return a list of files for a given project
- with offset and limit parameters
- """
- # pylint: disable=arguments-differ
- methods = ['GET']
- model = File
- def get_objects(self, project_id: int, start: int, length: int, collection_id: int = None):
- # find project files
- files = File.query.filter_by(project_id=project_id)
- if collection_id == 0:
- # files without a collection
- files = files.filter(File.collection_id == None)
- elif collection_id is not None:
- # files of a collection
- files = files.filter(File.collection_id == collection_id)
- count = files.count()
- files = files.order_by(File.id).offset(start).limit(length).all()
- return dict(count=count, files=files)
|