Add pagination to admin management tabs (cases/categories/sources/orgs)
This commit is contained in:
@@ -17,10 +17,11 @@ def list_tasks(
|
||||
topic_id: Optional[str] = None,
|
||||
stage: Optional[str] = None,
|
||||
limit: int = Query(50, le=200),
|
||||
offset: int = Query(0, ge=0),
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user)
|
||||
):
|
||||
query = db.query(ContentTask).join(Topic, ContentTask.topic_id == Topic.id, isouter=True)
|
||||
query = db.query(ContentTask, Topic.title.label("topic_title")).join(Topic, ContentTask.topic_id == Topic.id, isouter=True)
|
||||
of = org_filter(current_user, Topic)
|
||||
if of is not True:
|
||||
query = query.filter((ContentTask.topic_id.is_(None)) | (Topic.org_id == current_user.org_id))
|
||||
@@ -30,7 +31,13 @@ def list_tasks(
|
||||
query = query.filter(ContentTask.topic_id == topic_id)
|
||||
if stage:
|
||||
query = query.filter(ContentTask.stage == stage)
|
||||
return query.order_by(ContentTask.created_at.desc()).limit(limit).all()
|
||||
rows = query.order_by(ContentTask.created_at.desc()).offset(offset).limit(limit).all()
|
||||
result = []
|
||||
for r in rows:
|
||||
task = r.ContentTask
|
||||
task.topic_title = r.topic_title
|
||||
result.append(task)
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/active")
|
||||
|
||||
Reference in New Issue
Block a user