1
0
forked from ScoDoc/ScoDoc

improved our shell: reload context and admin user

This commit is contained in:
Emmanuel Viennet 2021-08-01 10:52:28 +03:00
parent 37e7667eeb
commit 56f935b2a8
3 changed files with 17 additions and 66 deletions

View File

@ -32,6 +32,14 @@ cli.register(app)
def make_shell_context():
from app.scodoc import notesdb as ndb
from app.scodoc import sco_utils as scu
from flask_login import login_user, logout_user, current_user
admin_role = Role.query.filter_by(name="SuperAdmin").first()
admin = (
User.query.join(UserRole)
.filter((UserRole.user_id == User.id) & (UserRole.role_id == admin_role.id))
.first()
)
return {
"db": db,
@ -45,9 +53,18 @@ def make_shell_context():
"pp": pp,
"flask": flask,
"current_app": flask.current_app,
"current_user": current_user,
"login_user": login_user,
"logout_user": logout_user,
"admin": admin,
"ctx": app.test_request_context(),
}
# ctx.push()
# login_user(admin)
@app.cli.command()
def user_db_init(): # user-db-init
"""Initialize the users database."""

View File

@ -1,66 +0,0 @@
# -*- mode: python -*-
# -*- coding: utf-8 -
""" Création d'une absence et utilisation de AnnuleAbsenceDatesNoJust """
import random
# La variable context est définie par le script de lancement
# l'affecte ainsi pour évietr les warnins pylint:
context = context # pylint: disable=undefined-variable
REQUEST = REQUEST # pylint: disable=undefined-variable
import scotests.sco_fake_gen as sco_fake_gen # pylint: disable=import-error
import sco_abs_views
G = sco_fake_gen.ScoFake(context.Notes)
G.verbose = False
# --- Création d'une formation
f = G.create_formation(acronyme="")
ue = G.create_ue(formation_id=f["formation_id"], acronyme="TST1", titre="ue test")
mat = G.create_matiere(ue_id=ue["ue_id"], titre="matière test")
mod = G.create_module(
matiere_id=mat["matiere_id"],
code="TSM1",
coefficient=1.0,
titre="module test",
ue_id=ue["ue_id"], # faiblesse de l'API
formation_id=f["formation_id"], # faiblesse de l'API
)
# --- Mise place d'un semestre
sem = G.create_formsemestre(
formation_id=f["formation_id"],
semestre_id=1,
date_debut="01/01/2021",
date_fin="30/06/2021",
)
mi = G.create_moduleimpl(
module_id=mod["module_id"],
formsemestre_id=sem["formsemestre_id"],
responsable_id="bach",
)
# --- Création d'un étudiant
etud = G.create_etud(code_nip=None)
G.inscrit_etudiant(sem, etud)
etudid = etud["etudid"]
# --- Création d'une absence
sco_abs_views.doSignaleAbsence(
context.Absences,
datedebut="22/01/2021",
datefin="22/01/2021",
demijournee=2,
etudid=etudid,
REQUEST=REQUEST,
)
# --- Annulation d'absence
context.Absences.AnnuleAbsencesDatesNoJust(etudid, dates="22/01/2021")
""" Erreur : File "/opt/scodoc/Products/ScoDoc/ZAbsences.py", line 323, in AnnuleAbsencesDatesNoJust
vars(),
psycopg2.DataError: invalid input syntax for type date: "2"
LINE 1: ...es where etudid='EID1' and (not estjust) and jour='2' and mo... """