From be2227f8a353f9533db8d0a094b3dc23dcfb5505 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 4 Jan 2022 18:10:14 +0100 Subject: [PATCH] =?UTF-8?q?L'admin=20peut=20cacher/montrer=20des=20d=C3=A9?= =?UTF-8?q?partements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/main/config_forms.py | 2 +- app/forms/main/create_dept.py | 14 ++++++-------- app/models/departements.py | 4 ++-- app/templates/scodoc.html | 10 ++++++++++ app/views/scodoc.py | 18 ++++++++++++++---- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/forms/main/config_forms.py b/app/forms/main/config_forms.py index 03589795..16be8451 100644 --- a/app/forms/main/config_forms.py +++ b/app/forms/main/config_forms.py @@ -245,7 +245,7 @@ class DeptForm(FlaskForm): def _make_dept_id_name(): - """Cette section assute que tous les départements sont traités (y compris ceux qu'ont pas de logo au départ) + """Cette section assure que tous les départements sont traités (y compris ceux qu'ont pas de logo au départ) et détermine l'ordre d'affichage des DeptForm (GLOBAL d'abord, puis par ordre alpha de nom de département) -> [ (None, None), (dept_id, dept_name)... ]""" depts = [(None, GLOBAL)] diff --git a/app/forms/main/create_dept.py b/app/forms/main/create_dept.py index 7bc26b42..d1e143be 100644 --- a/app/forms/main/create_dept.py +++ b/app/forms/main/create_dept.py @@ -31,16 +31,10 @@ Formulaires création département from flask import flash, url_for, redirect, render_template from flask_wtf import FlaskForm -from wtforms import SelectField, SubmitField, FormField, validators, FieldList -from wtforms.fields.simple import StringField, HiddenField +from wtforms import SubmitField, validators +from wtforms.fields.simple import StringField, BooleanField -from app import AccessDenied -from app.models import Departement -from app.models import ScoPreference from app.models import SHORT_STR_LEN -from app.scodoc import sco_utils as scu - -from flask_login import current_user class CreateDeptForm(FlaskForm): @@ -60,5 +54,9 @@ class CreateDeptForm(FlaskForm): validators.DataRequired("acronyme du département requis"), ], ) + visible = BooleanField( + "Visible sur page d'accueil", + default=True, + ) submit = SubmitField("Valider") cancel = SubmitField("Annuler", render_kw={"formnovalidate": True}) diff --git a/app/models/departements.py b/app/models/departements.py index 0734e35b..d83ccfc2 100644 --- a/app/models/departements.py +++ b/app/models/departements.py @@ -49,11 +49,11 @@ class Departement(db.Model): return dept -def create_dept(acronym: str) -> Departement: +def create_dept(acronym: str, visible=True) -> Departement: "Create new departement" from app.models import ScoPreference - departement = Departement(acronym=acronym) + departement = Departement(acronym=acronym, visible=visible) p1 = ScoPreference(name="DeptName", value=acronym, departement=departement) db.session.add(p1) db.session.add(departement) diff --git a/app/templates/scodoc.html b/app/templates/scodoc.html index 2aaf9e22..23667c24 100644 --- a/app/templates/scodoc.html +++ b/app/templates/scodoc.html @@ -12,11 +12,21 @@