forked from ScoDoc/ScoDoc
L'admin peut cacher/montrer des départements
This commit is contained in:
parent
9b9b2f270b
commit
be2227f8a3
@ -245,7 +245,7 @@ class DeptForm(FlaskForm):
|
|||||||
|
|
||||||
|
|
||||||
def _make_dept_id_name():
|
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)
|
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)... ]"""
|
-> [ (None, None), (dept_id, dept_name)... ]"""
|
||||||
depts = [(None, GLOBAL)]
|
depts = [(None, GLOBAL)]
|
||||||
|
@ -31,16 +31,10 @@ Formulaires création département
|
|||||||
|
|
||||||
from flask import flash, url_for, redirect, render_template
|
from flask import flash, url_for, redirect, render_template
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import SelectField, SubmitField, FormField, validators, FieldList
|
from wtforms import SubmitField, validators
|
||||||
from wtforms.fields.simple import StringField, HiddenField
|
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.models import SHORT_STR_LEN
|
||||||
from app.scodoc import sco_utils as scu
|
|
||||||
|
|
||||||
from flask_login import current_user
|
|
||||||
|
|
||||||
|
|
||||||
class CreateDeptForm(FlaskForm):
|
class CreateDeptForm(FlaskForm):
|
||||||
@ -60,5 +54,9 @@ class CreateDeptForm(FlaskForm):
|
|||||||
validators.DataRequired("acronyme du département requis"),
|
validators.DataRequired("acronyme du département requis"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
visible = BooleanField(
|
||||||
|
"Visible sur page d'accueil",
|
||||||
|
default=True,
|
||||||
|
)
|
||||||
submit = SubmitField("Valider")
|
submit = SubmitField("Valider")
|
||||||
cancel = SubmitField("Annuler", render_kw={"formnovalidate": True})
|
cancel = SubmitField("Annuler", render_kw={"formnovalidate": True})
|
||||||
|
@ -49,11 +49,11 @@ class Departement(db.Model):
|
|||||||
return dept
|
return dept
|
||||||
|
|
||||||
|
|
||||||
def create_dept(acronym: str) -> Departement:
|
def create_dept(acronym: str, visible=True) -> Departement:
|
||||||
"Create new departement"
|
"Create new departement"
|
||||||
from app.models import ScoPreference
|
from app.models import ScoPreference
|
||||||
|
|
||||||
departement = Departement(acronym=acronym)
|
departement = Departement(acronym=acronym, visible=visible)
|
||||||
p1 = ScoPreference(name="DeptName", value=acronym, departement=departement)
|
p1 = ScoPreference(name="DeptName", value=acronym, departement=departement)
|
||||||
db.session.add(p1)
|
db.session.add(p1)
|
||||||
db.session.add(departement)
|
db.session.add(departement)
|
||||||
|
@ -12,11 +12,21 @@
|
|||||||
|
|
||||||
<ul class="main">
|
<ul class="main">
|
||||||
{% for dept in depts %}
|
{% for dept in depts %}
|
||||||
|
{% if dept.visible or current_user.is_administrator() %}
|
||||||
<li>
|
<li>
|
||||||
<a class="stdlink {{'link_accessible' if current_user.has_permission(Permission.ScoView, dept=dept.acronym) else 'link_unauthorized'}}"
|
<a class="stdlink {{'link_accessible' if current_user.has_permission(Permission.ScoView, dept=dept.acronym) else 'link_unauthorized'}}"
|
||||||
href="{{url_for('scolar.index_html', scodoc_dept=dept.acronym)}}">Département
|
href="{{url_for('scolar.index_html', scodoc_dept=dept.acronym)}}">Département
|
||||||
{{dept.preferences.filter_by(name="DeptName").first().value}}</a>
|
{{dept.preferences.filter_by(name="DeptName").first().value}}</a>
|
||||||
|
{% if current_user.is_administrator() %}
|
||||||
|
<span class="dept_visibility">
|
||||||
|
{% if dept.visible %}visible{% else %}caché aux utilisateurs{% endif %}
|
||||||
|
<a href="{{ url_for('scodoc.toggle_dept_vis', dept_id=dept.id) }}">
|
||||||
|
{% if dept.visible %}cacher{% else %}rendre visible{% endif %}
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<li>
|
<li>
|
||||||
<b>Aucun département défini !</b>
|
<b>Aucun département défini !</b>
|
||||||
|
@ -53,6 +53,7 @@ from wtforms.fields.simple import BooleanField, StringField, TextAreaField, Hidd
|
|||||||
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo
|
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo
|
||||||
|
|
||||||
import app
|
import app
|
||||||
|
from app import db
|
||||||
from app.forms.main import config_forms
|
from app.forms.main import config_forms
|
||||||
from app.forms.main.create_dept import CreateDeptForm
|
from app.forms.main.create_dept import CreateDeptForm
|
||||||
from app.models import Departement, Identite
|
from app.models import Departement, Identite
|
||||||
@ -82,9 +83,7 @@ from PIL import Image as PILImage
|
|||||||
@bp.route("/ScoDoc/index")
|
@bp.route("/ScoDoc/index")
|
||||||
def index():
|
def index():
|
||||||
"Page d'accueil: liste des départements"
|
"Page d'accueil: liste des départements"
|
||||||
depts = (
|
depts = Departement.query.filter_by().order_by(Departement.acronym).all()
|
||||||
Departement.query.filter_by(visible=True).order_by(Departement.acronym).all()
|
|
||||||
)
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"scodoc.html",
|
"scodoc.html",
|
||||||
title=sco_version.SCONAME,
|
title=sco_version.SCONAME,
|
||||||
@ -108,7 +107,7 @@ def create_dept():
|
|||||||
if request.method == "POST" and form.cancel.data: # cancel button
|
if request.method == "POST" and form.cancel.data: # cancel button
|
||||||
return redirect(url_for("scodoc.index"))
|
return redirect(url_for("scodoc.index"))
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
departements.create_dept(form.acronym.data)
|
departements.create_dept(form.acronym.data, visible=form.visible.data)
|
||||||
flash(f"Département {form.acronym.data} créé.")
|
flash(f"Département {form.acronym.data} créé.")
|
||||||
return redirect(url_for("scodoc.index"))
|
return redirect(url_for("scodoc.index"))
|
||||||
return render_template(
|
return render_template(
|
||||||
@ -118,6 +117,17 @@ def create_dept():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/ScoDoc/toggle_dept_vis/<dept_id>", methods=["GET", "POST"])
|
||||||
|
@admin_required
|
||||||
|
def toggle_dept_vis(dept_id):
|
||||||
|
"""Cache ou rend visible un dept"""
|
||||||
|
dept = Departement.query.get_or_404(dept_id)
|
||||||
|
dept.visible = not dept.visible
|
||||||
|
db.session.add(dept)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for("scodoc.index"))
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/ScoDoc/table_etud_in_accessible_depts", methods=["POST"])
|
@bp.route("/ScoDoc/table_etud_in_accessible_depts", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def table_etud_in_accessible_depts():
|
def table_etud_in_accessible_depts():
|
||||||
|
Loading…
Reference in New Issue
Block a user