mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
🎨 — Modify count_tasks behavior, improve its signature
This commit is contained in:
parent
7bfe676b5c
commit
be492ed2ee
2 changed files with 8 additions and 7 deletions
|
@ -51,7 +51,7 @@ def create_start_app_handler(appli):
|
||||||
|
|
||||||
db = await connect_to_db(appli)
|
db = await connect_to_db(appli)
|
||||||
|
|
||||||
tasks_count = await queries.count_tasks(db, all_tasks=True)
|
tasks_count = await queries.count_tasks(db)
|
||||||
if tasks_count == 0:
|
if tasks_count == 0:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"There is no tasks in the database. "
|
"There is no tasks in the database. "
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Functions to ease SQL queries management"""
|
"""Functions to ease SQL queries management"""
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
from sqlalchemy import desc, func
|
from sqlalchemy import desc, func
|
||||||
|
@ -48,12 +48,13 @@ async def create_result(db: Session, agent_result: schemas.AgentResult, agent_id
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def count_tasks(db: Session, selected=False, all_tasks=False):
|
async def count_tasks(db: Session, selected: Union[None, bool] = None):
|
||||||
query = db.query(Task)
|
query = db.query(Task)
|
||||||
if selected:
|
if selected is not None:
|
||||||
query = query.filter(Task.selected_by is not None)
|
if selected:
|
||||||
elif not all_tasks:
|
query = query.filter(Task.selected_by is not None)
|
||||||
query = query.filter(Task.selected_by is None)
|
else:
|
||||||
|
query = query.filter(Task.selected_by is None)
|
||||||
|
|
||||||
return query.count()
|
return query.count()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue