1
0
forked from ScoDoc/ScoDoc

Form création dept + déplace form logos

This commit is contained in:
Emmanuel Viennet 2021-12-23 16:03:30 +01:00
parent 429820b786
commit 2d2b2b2f39
8 changed files with 121 additions and 11 deletions

View File

@ -89,7 +89,8 @@ CSSSTYLES = html_sco_header.BOOTSTRAP_MULTISELECT_CSS
# - only one operation found: execute and go to main page
# - more than 1 operation found. asked form confirmation (and execution if confirmed)
#
# Someday we'll have time to refactor as abstract classes but Abstract FieldList makes this a bit complicated
# Someday we'll have time to refactor as abstract classes but Abstract FieldList makes this
# a bit complicated
# """
# Terminology:

View File

@ -0,0 +1,64 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# ScoDoc
#
# Copyright (c) 1999 - 2021 Emmanuel Viennet. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Emmanuel Viennet emmanuel.viennet@viennet.net
#
##############################################################################
"""
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 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):
"""Formulaire permettant l'ajout d'un département"""
acronym = StringField(
label="Acronyme",
validators=[
validators.regexp(
r"^[a-zA-Z0-9_\-]*$",
message="Ne doit comporter que lettres, chiffres ou -",
),
validators.Length(
max=SHORT_STR_LEN,
message=f"L'acronyme ne doit pas dépasser {SHORT_STR_LEN} caractères",
),
validators.DataRequired("acronyme du département requis"),
],
)
submit = SubmitField("Valider")
cancel = SubmitField("Annuler", render_kw={"formnovalidate": True})

View File

@ -47,3 +47,15 @@ class Departement(db.Model):
def from_acronym(cls, acronym):
dept = cls.query.filter_by(acronym=acronym).first_or_404()
return dept
def create_dept(acronym: str) -> Departement:
"Create new departement"
from app.models import ScoPreference
departement = Departement(acronym=acronym)
p1 = ScoPreference(name="DeptName", value=acronym, departement=departement)
db.session.add(p1)
db.session.add(departement)
db.session.commit()
return departement

View File

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %}
<h1>Créer un département</h1>
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}

View File

@ -22,6 +22,9 @@
<b>Aucun département défini !</b>
</li>
{% endfor %}
{% if current_user.is_administrator() %}
<li><a href="{{ url_for('scodoc.create_dept') }}">créer un nouveau département</a></li>
{% endif %}
</ul>

View File

@ -53,11 +53,13 @@ from wtforms.fields.simple import BooleanField, StringField, TextAreaField, Hidd
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo
import app
from app.forms.main import config_forms
from app.forms.main.create_dept import CreateDeptForm
from app.models import Departement, Identite
from app.models import departements
from app.models import FormSemestre, FormSemestreInscription
from app.models import ScoDocSiteConfig
import sco_version
from app.scodoc import sco_logos, sco_config_form
from app.scodoc import sco_logos
from app.scodoc import sco_find_etud
from app.scodoc import sco_utils as scu
from app.decorators import (
@ -67,7 +69,6 @@ from app.decorators import (
permission_required_compat_scodoc7,
permission_required,
)
from app.scodoc.sco_config_form import configuration
from app.scodoc.sco_exceptions import AccessDenied
from app.scodoc.sco_logos import find_logo
from app.scodoc.sco_permissions import Permission
@ -99,6 +100,24 @@ def index_dept(scodoc_dept):
return redirect(url_for("scolar.index_html", scodoc_dept=scodoc_dept))
@bp.route("/ScoDoc/create_dept", methods=["GET", "POST"])
@admin_required
def create_dept():
"""Form création département"""
form = CreateDeptForm()
if request.method == "POST" and form.cancel.data: # cancel button
return redirect(url_for("scodoc.index"))
if form.validate_on_submit():
departements.create_dept(form.acronym.data)
flash(f"Département {form.acronym.data} créé.")
return redirect(url_for("scodoc.index"))
return render_template(
"create_dept.html",
form=form,
title="Création d'un nouveau département",
)
@bp.route("/ScoDoc/table_etud_in_accessible_depts", methods=["POST"])
@login_required
def table_etud_in_accessible_depts():
@ -207,7 +226,7 @@ def configuration():
auth_name = str(current_user)
if not current_user.is_administrator():
raise AccessDenied("invalid user (%s) must be SuperAdmin" % auth_name)
return sco_config_form.configuration()
return config_forms.configuration()
SMALL_SIZE = (200, 200)

View File

@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.1.15"
SCOVERSION = "9.1.16"
SCONAME = "ScoDoc"

View File

@ -27,6 +27,7 @@ from app.models import Formation, UniteEns, Module
from app.models import FormSemestre, FormSemestreInscription
from app.models import ModuleImpl, ModuleImplInscription
from app.models import Identite
from app.models import departements
from app.models.evaluations import Evaluation
from app.scodoc.sco_etud import identite_create
from app.scodoc.sco_permissions import Permission
@ -306,11 +307,7 @@ def delete_dept(dept): # delete-dept
@click.argument("dept")
def create_dept(dept): # create-dept
"Create new departement"
d = models.Departement(acronym=dept)
p1 = ScoPreference(name="DeptName", value=dept, departement=d)
db.session.add(p1)
db.session.add(d)
db.session.commit()
_ = departements.create_dept(dept)
return 0