WIP améliore décorateur scodoc7 pour appels internes

This commit is contained in:
Emmanuel Viennet 2021-06-16 10:15:46 +02:00
parent e16b974761
commit 512c00b2e7
15 changed files with 66 additions and 51 deletions

View File

@ -124,17 +124,17 @@ def scodoc7func(context):
If called via a route, this decorator setups a REQUEST object (emulating Zope2 REQUEST)
and `g.scodoc_dept` if present in the argument (for routes like `/<scodoc_dept>/Scolarite/sco_exemple`).
"""
assert not args
# Détermine si on est appelé via une route ("toplevel")
# ou par un appel de fonction python normal.
top_level = not hasattr(g, "zrequest")
if top_level:
g.zrequest = None
if not top_level:
# ne "redécore" pas
return func(*args, **kwargs)
#
if "scodoc_dept" in kwargs:
g.scodoc_dept = kwargs["scodoc_dept"]
del kwargs["scodoc_dept"]
elif not hasattr(g, "scodoc_dept"): # if toplevel call
elif not hasattr(g, "scodoc_dept"):
g.scodoc_dept = None
# --- Emulate Zope's REQUEST
REQUEST = ZRequest()

View File

@ -66,7 +66,7 @@ def comp_nom_semestre_dans_parcours(context, sem):
"""Le nom a afficher pour titrer un semestre
par exemple: "semestre 2 FI 2015"
"""
F = context.Notes.formation_list(args={"formation_id": sem["formation_id"]})[0]
F = context.formation_list(args={"formation_id": sem["formation_id"]})[0]
parcours = sco_codes_parcours.get_parcours_from_code(F["type_parcours"])
return "%s %s %s %s" % (
parcours.SESSION_NAME, # eg "semestre"

View File

@ -245,7 +245,7 @@ def do_formation_create(context, args, REQUEST):
if args.has_key("formation_code") and not args["formation_code"]:
del args["formation_code"]
#
r = _formationEditor.create(cnx, args)
r = sco_formations._formationEditor.create(cnx, args)
sco_news.add(
context,

View File

@ -422,9 +422,7 @@ def module_list(context, formation_id, REQUEST=None):
% F,
'<ul class="notes_module_list">',
]
editable = REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoChangeFormation, context
)
editable = REQUEST.AUTHENTICATED_USER.has_permission(Permission.ScoChangeFormation)
for Mod in context.do_module_list(args={"formation_id": formation_id}):
H.append('<li class="notes_module_list">%s' % Mod)

View File

@ -62,7 +62,7 @@ def _build_results_table(context, start_date=None, end_date=None, types_parcours
semlist = [dpv["formsemestre"] for dpv in dpv_by_sem.values() if dpv]
semlist_parcours = []
for sem in semlist:
sem["formation"] = context.Notes.formation_list(
sem["formation"] = context.formation_list(
args={"formation_id": sem["formation_id"]}
)[0]
sem["parcours"] = sco_codes_parcours.get_parcours_from_code(

View File

@ -40,6 +40,7 @@ import sco_tag_module
from gen_tables import GenTable
from sco_exceptions import ScoValueError
from sco_permissions import ScoChangeFormation
from sco_permissions import Permission
import VERSION
_formationEditor = ndb.EditableTable(
@ -233,9 +234,7 @@ def formation_list_table(context, formation_id=None, args={}, REQUEST=None):
"edit_img", border="0", alt="modifier", title="Modifier titres et code"
)
editable = REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoChangeFormation, context
)
editable = REQUEST.AUTHENTICATED_USER.has_permission(Permission.ScoChangeFormation)
# Traduit/ajoute des champs à afficher:
for f in formations:

View File

@ -131,7 +131,7 @@ def formsemestre_enrich(context, sem):
import sco_formsemestre_edit
import scolars
F = context.Notes.formation_list(args={"formation_id": sem["formation_id"]})[0]
F = context.formation_list(args={"formation_id": sem["formation_id"]})[0]
parcours = sco_codes_parcours.get_parcours_from_code(F["type_parcours"])
# 'S1', 'S2', ... ou '' pour les monosemestres
if sem["semestre_id"] != NO_SEMESTRE_ID:

View File

@ -35,17 +35,18 @@ import sco_groups
from notes_log import log
from TrivialFormulator import TrivialFormulator, TF
import notes_table
import sco_portal_apogee
import scolars
import sco_parcours_dut
import sco_codes_parcours
import sco_compute_moy
import sco_modalites
import sco_formsemestre
import sco_moduleimpl
from sco_exceptions import AccessDenied, ScoValueError
from sco_formsemestre import ApoEtapeVDI
from sco_permissions import ScoImplement
from sco_exceptions import AccessDenied, ScoValueError
import sco_codes_parcours
import sco_compute_moy
import sco_formsemestre
import sco_modalites
import sco_moduleimpl
import sco_parcours_dut
import sco_portal_apogee
import sco_preferences
import scolars
def _default_sem_title(F):

View File

@ -563,7 +563,7 @@ def fill_formsemestre(context, sem, REQUEST=None):
)
else:
sem["eyelink"] = ""
F = context.Notes.formation_list(args={"formation_id": sem["formation_id"]})[0]
F = context.formation_list(args={"formation_id": sem["formation_id"]})[0]
sem["formation"] = F
parcours = sco_codes_parcours.get_parcours_from_code(F["type_parcours"])
if sem["semestre_id"] != -1:

View File

@ -720,7 +720,7 @@ def formsemestre_pvjury_pdf(
def descrform_pvjury(context, sem):
"""Définition de formulaire pour PV jury PDF"""
F = context.Notes.formation_list(formation_id=sem["formation_id"])[0]
F = context.formation_list(formation_id=sem["formation_id"])[0]
return [
(
"date_commission",

View File

@ -2,7 +2,7 @@
{% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %}
<h1>Protoype ScoDoc 8: accueil</h1>
<h1>Prototype ScoDoc 8: accueil</h1>
<div class="row">
<h2>Avec login requis</h2>
<ul>
@ -28,7 +28,10 @@
<li><a href="{{ url_for('notes.essai2' , scodoc_dept='RT') }}"><tt>Notes/essai2</tt></a> : permission
ScoImplement dans RT
</li>
</ul>
<h2>Essais décorateurs et appels</h2>
<ul>
<li><a href="{{ url_for('essais.sco_exemple', scodoc_dept='RT') }}">sco_exemple</a></li>
</ul>
</div>

View File

@ -8,4 +8,4 @@ notes_bp = Blueprint("notes", __name__)
absences_bp = Blueprint("absences", __name__)
essais_bp = Blueprint("essais", __name__)
from app.views import notes, scolar, absences
from app.views import notes, scolar, absences, essais

View File

@ -83,7 +83,7 @@ def sidebar(context, REQUEST):
% params,
]
if REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoEntrepriseChange, context
Permission.ScoEntrepriseChange
):
H.append(
"""<li class="insidebar"><a href="%(ScoURL)s/Entreprises/entreprise_create" class="sidebar">Nouvelle entreprise</a> </li>"""
@ -112,7 +112,7 @@ def sidebar(context, REQUEST):
% params
) # """
if REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoEntrepriseChange, context
Permission.ScoEntrepriseChange
):
H.append(
"""<li class="insidebar"><a href="%(ScoURL)s/Entreprises/entreprise_correspondant_create?entreprise_id=%(entreprise_id)s" class="sidebar">Nouveau Corresp.</a></li>"""
@ -123,7 +123,7 @@ def sidebar(context, REQUEST):
% params
)
if REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoEntrepriseChange, context
Permission.ScoEntrepriseChange
):
H.append(
"""<li class="insidebar"><a href="%(ScoURL)s/Entreprises/entreprise_contact_create?entreprise_id=%(entreprise_id)s" class="sidebar">Nouveau "contact"</a></li>"""
@ -134,7 +134,7 @@ def sidebar(context, REQUEST):
#
H.append("""<br/><br/>%s""" % scu.icontag("entreprise_side_img"))
if not REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoEntrepriseChange, context
Permission.ScoEntrepriseChange
):
H.append("""<br/><em>(Lecture seule)</em>""")
H.append("""</div> </div> <!-- end of sidebar -->""")
@ -316,7 +316,7 @@ def entreprise_contact_list(context, entreprise_id=None, format="html", REQUEST=
H.append(tab.html())
if REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoEntrepriseChange, context
Permission.ScoEntrepriseChange
):
if entreprise_id:
H.append(
@ -427,7 +427,7 @@ def entreprise_correspondant_list(
H.append(tab.html())
if REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoEntrepriseChange, context
Permission.ScoEntrepriseChange
):
H.append(
"""<p class="entreprise_create"><a class="entreprise_create" href="entreprise_correspondant_create?entreprise_id=%(entreprise_id)s">Ajouter un correspondant dans l'entreprise %(nom)s</a></p>
@ -537,21 +537,21 @@ def entreprise_contact_edit(context, entreprise_contact_id, REQUEST=None):
initvalues=c,
submitlabel="Modifier les valeurs",
readonly=not REQUEST.AUTHENTICATED_USER.has_permission(
ScoEntrepriseChange, context
ScoEntrepriseChange
),
)
if tf[0] == 0:
H.append(tf[1])
if REQUEST.AUTHENTICATED_USER.has_permission(
Permission.ScoEntrepriseChange, context
Permission.ScoEntrepriseChange,
):
H.append(
"""<p class="entreprise_descr"><a class="entreprise_delete" href="entreprise_contact_delete?entreprise_contact_id=%s">Supprimer ce contact</a> </p>"""
% entreprise_contact_id
)
elif tf[0] == -1:
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context, ))
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context))
else:
etudok = sco_entreprises.do_entreprise_check_etudiant(
context, tf[2]["etudiant"]
@ -665,7 +665,7 @@ def entreprise_correspondant_edit(context, entreprise_corresp_id, REQUEST=None):
initvalues=c,
submitlabel="Modifier les valeurs",
readonly=not REQUEST.AUTHENTICATED_USER.has_permission(
ScoEntrepriseChange, context
ScoEntrepriseChange
),
)
if tf[0] == 0:
@ -776,13 +776,13 @@ def entreprise_contact_create(context, entreprise_id, REQUEST=None):
cancelbutton="Annuler",
submitlabel="Ajouter ce contact",
readonly=not REQUEST.AUTHENTICATED_USER.has_permission(
ScoEntrepriseChange, context
ScoEntrepriseChange
),
)
if tf[0] == 0:
H.append(tf[1])
elif tf[0] == -1:
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context, ))
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context))
else:
etudok = sco_entreprises.do_entreprise_check_etudiant(
context, tf[2]["etudiant"]
@ -817,18 +817,18 @@ def entreprise_contact_delete(context, entreprise_contact_id, REQUEST=None):
submitlabel="Confirmer la suppression",
cancelbutton="Annuler",
readonly=not REQUEST.AUTHENTICATED_USER.has_permission(
ScoEntrepriseChange, context
ScoEntrepriseChange
),
)
if tf[0] == 0:
H.append(tf[1])
elif tf[0] == -1:
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context, ))
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context))
else:
sco_entreprises.do_entreprise_contact_delete(
context, c["entreprise_contact_id"]
)
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context, ))
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context))
H.append(entreprise_footer(context, REQUEST))
return "\n".join(H)
@ -926,16 +926,16 @@ def entreprise_correspondant_create(context, entreprise_id, REQUEST=None):
cancelbutton="Annuler",
submitlabel="Ajouter ce correspondant",
readonly=not REQUEST.AUTHENTICATED_USER.has_permission(
ScoEntrepriseChange, context
ScoEntrepriseChange
),
)
if tf[0] == 0:
H.append(tf[1])
elif tf[0] == -1:
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context, ))
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context))
else:
sco_entreprises.do_entreprise_correspondant_create(context, tf[2])
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context, ))
return REQUEST.RESPONSE.redirect(scu.EntreprisesURL(context))
H.append(entreprise_footer(context, REQUEST))
return "\n".join(H)
@ -960,7 +960,7 @@ def entreprise_correspondant_delete(context, entreprise_corresp_id, REQUEST=None
submitlabel="Confirmer la suppression",
cancelbutton="Annuler",
readonly=not REQUEST.AUTHENTICATED_USER.has_permission(
ScoEntrepriseChange, context
ScoEntrepriseChange
),
)
if tf[0] == 0:
@ -1020,7 +1020,7 @@ def entreprise_delete(context, entreprise_id, REQUEST=None):
submitlabel="Confirmer la suppression",
cancelbutton="Annuler",
readonly=not REQUEST.AUTHENTICATED_USER.has_permission(
ScoEntrepriseChange, context
ScoEntrepriseChange
),
)
if tf[0] == 0:
@ -1117,7 +1117,7 @@ def entreprise_create(context, REQUEST=None):
cancelbutton="Annuler",
submitlabel="Ajouter cette entreprise",
readonly=not REQUEST.AUTHENTICATED_USER.has_permission(
ScoEntrepriseChange, context
ScoEntrepriseChange
),
)
if tf[0] == 0:

View File

@ -17,7 +17,7 @@ from app.decorators import (
)
from app.auth.models import Permission
from app.views import notes_bp as bp
from app.views import essais_bp as bp
# import sco_core deviendra:
from app.scodoc import sco_core
@ -50,6 +50,20 @@ def sco_exemple2():
return "Exemple 2" + context.sco_exemple(etudid="deux")
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple3")
@login_required
@scodoc7func(context)
def sco_exemple3(toto):
return "Exemple 3: toto=" + toto
@bp.route("/<scodoc_dept>/Scolarite/sco_exemple4")
@login_required
@scodoc7func(context)
def sco_exemple4(toto):
return "Exemple 4: " + sco_exemple3(toto)
# Test avec un seul argument REQUEST positionnel
@bp.route("/<scodoc_dept>/Scolarite/sco_get_version")
@scodoc7func(context)

View File

@ -450,7 +450,7 @@ def formation_list(context, format=None, REQUEST=None, formation_id=None, args={
else:
args = {"formation_id": formation_id}
cnx = ndb.GetDBConnexion()
r = _formationEditor.list(cnx, args=args)
r = sco_formations._formationEditor.list(cnx, args=args)
# log('%d formations found' % len(r))
return scu.sendResult(REQUEST, r, name="formation", format=format)