add visible field to form

This commit is contained in:
Julien Aldon
2026-02-23 15:38:29 +01:00
parent 85a70da07d
commit 124b0700da
19 changed files with 119 additions and 15 deletions

View File

@@ -13,10 +13,20 @@ async def get_forms(
seasons: list[str] = Query([]),
productors: list[str] = Query([]),
current_season: bool = False,
session: Session = Depends(get_session)
session: Session = Depends(get_session),
):
return service.get_all(session, seasons, productors, current_season)
@router.get('/referents', response_model=list[models.FormPublic])
async def get_forms_filtered(
seasons: list[str] = Query([]),
productors: list[str] = Query([]),
current_season: bool = False,
session: Session = Depends(get_session),
user: models.User = Depends(get_current_user)
):
return service.get_all(session, seasons, productors, current_season, user)
@router.get('/{id}', response_model=models.FormPublic)
async def get_form(id: int, session: Session = Depends(get_session)):
result = service.get_one(session, id)

View File

@@ -7,12 +7,20 @@ def get_all(
seasons: list[str],
productors: list[str],
current_season: bool,
user: models.User = None
) -> list[models.FormPublic]:
statement = select(models.Form)
if user:
statement = statement\
.join(models.Productor, models.Form.productor_id == models.Productor.id)\
.where(models.Productor.type.in_([r.name for r in user.roles]))\
.distinct()
if len(seasons) > 0:
statement = statement.where(models.Form.season.in_(seasons))
if len(productors) > 0:
statement = statement.join(models.Productor).where(models.Productor.name.in_(productors))
if not user:
statement = statement.where(models.Form.visible == True)
if current_season:
subquery = (
select(
@@ -29,6 +37,8 @@ def get_all(
(models.Productor.type == subquery.c.type) &
(models.Form.start == subquery.c.max_start)
)
if not user:
statement = statement.where(models.Form.visible == True)
return session.exec(statement.order_by(models.Form.name)).all()
return session.exec(statement.order_by(models.Form.name)).all()