Assiduité : Erreur module et external_data #711

This commit is contained in:
iziram 2023-09-05 09:25:51 +02:00
parent d3e3b48d17
commit 4387727d2f
3 changed files with 42 additions and 31 deletions

View File

@ -601,9 +601,12 @@ def _create_singular(
moduleimpl_id = data.get("moduleimpl_id", False) moduleimpl_id = data.get("moduleimpl_id", False)
moduleimpl: ModuleImpl = None moduleimpl: ModuleImpl = None
if moduleimpl_id not in [False, None]: if moduleimpl_id not in [False, None, "", "-1"]:
if moduleimpl_id != "autre": if moduleimpl_id != "autre":
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first() try:
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first()
except ValueError:
moduleimpl = None
if moduleimpl is None: if moduleimpl is None:
errors.append("param 'moduleimpl_id': invalide") errors.append("param 'moduleimpl_id': invalide")
else: else:
@ -810,7 +813,7 @@ def _edit_singular(assiduite_unique, data):
moduleimpl: ModuleImpl = None moduleimpl: ModuleImpl = None
if moduleimpl_id is not False: if moduleimpl_id is not False:
if moduleimpl_id is not None: if moduleimpl_id not in [None, "", "-1"]:
if moduleimpl_id == "autre": if moduleimpl_id == "autre":
assiduite_unique.moduleimpl_id = None assiduite_unique.moduleimpl_id = None
external_data = ( external_data = (
@ -823,7 +826,13 @@ def _edit_singular(assiduite_unique, data):
assiduite_unique.external_data = external_data assiduite_unique.external_data = external_data
else: else:
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first() try:
moduleimpl = ModuleImpl.query.filter_by(
id=int(moduleimpl_id)
).first()
except ValueError:
moduleimpl = None
if moduleimpl is None: if moduleimpl is None:
errors.append("param 'moduleimpl_id': invalide") errors.append("param 'moduleimpl_id': invalide")
else: else:
@ -834,7 +843,7 @@ def _edit_singular(assiduite_unique, data):
else: else:
assiduite_unique.moduleimpl_id = moduleimpl_id assiduite_unique.moduleimpl_id = moduleimpl_id
else: else:
assiduite_unique.moduleimpl_id = moduleimpl_id assiduite_unique.moduleimpl_id = None
# Cas 3 : desc # Cas 3 : desc
desc = data.get("desc", False) desc = data.get("desc", False)

View File

@ -921,14 +921,11 @@ function deleteAssiduite(assiduite_id) {
function hasModuleImpl(assiduite) { function hasModuleImpl(assiduite) {
if (assiduite.moduleimpl_id != null) return true; if (assiduite.moduleimpl_id != null) return true;
if ( return (
"external_data" in assiduite && assiduite.hasOwnProperty("external_data") &&
assiduite.external_data instanceof Object && assiduite.external_data != null &&
"module" in assiduite.external_data assiduite.external_data.hasOwnProperty("module")
) );
return true;
return false;
} }
/** /**
@ -1406,10 +1403,10 @@ function setModuleImplId(assiduite, module = null) {
const moduleimpl = module == null ? getModuleImplId() : module; const moduleimpl = module == null ? getModuleImplId() : module;
if (moduleimpl === "autre") { if (moduleimpl === "autre") {
if ( if (
"external_data" in assiduite && assiduite.hasOwnProperty("external_data") &&
assiduite.external_data instanceof Object assiduite.external_data != null
) { ) {
if ("module" in assiduite.external_data) { if (assiduite.external_data.hasOwnProperty("module")) {
assiduite.external_data.module = "Autre"; assiduite.external_data.module = "Autre";
} else { } else {
assiduite["external_data"] = { module: "Autre" }; assiduite["external_data"] = { module: "Autre" };
@ -1421,10 +1418,10 @@ function setModuleImplId(assiduite, module = null) {
} else { } else {
assiduite["moduleimpl_id"] = moduleimpl; assiduite["moduleimpl_id"] = moduleimpl;
if ( if (
"external_data" in assiduite && assiduite.hasOwnProperty("external_data") &&
assiduite.external_data instanceof Object assiduite.external_data != null
) { ) {
if ("module" in assiduite.external_data) { if (assiduite.external_data.hasOwnProperty("module")) {
delete assiduite.external_data.module; delete assiduite.external_data.module;
} }
} }
@ -1476,9 +1473,9 @@ function getCurrentAssiduiteModuleImplId() {
let mod = currentAssiduites[0].moduleimpl_id; let mod = currentAssiduites[0].moduleimpl_id;
if ( if (
mod == null && mod == null &&
"external_data" in currentAssiduites[0] && currentAssiduites[0].hasOwnProperty("external_data") &&
currentAssiduites[0].external_data instanceof Object && currentAssiduites[0].external_data != null &&
"module" in currentAssiduites[0].external_data currentAssiduites[0].external_data.hasOwnProperty("module")
) { ) {
mod = currentAssiduites[0].external_data.module; mod = currentAssiduites[0].external_data.module;
} }
@ -1690,9 +1687,9 @@ function getModuleImpl(assiduite) {
if (id == null || id == undefined) { if (id == null || id == undefined) {
if ( if (
"external_data" in assiduite && assiduite.hasOwnProperty("external_data") &&
assiduite.external_data instanceof Object && assiduite.external_data != null &&
"module" in assiduite.external_data assiduite.external_data.hasOwnProperty("module")
) { ) {
return assiduite.external_data.module; return assiduite.external_data.module;
} else { } else {
@ -1718,10 +1715,12 @@ function getModuleImpl(assiduite) {
} }
function getUser(obj) { function getUser(obj) {
if ("external_data" in obj && obj.external_data != null) { if (
if ("enseignant" in obj.external_data) { obj.hasOwnProperty("external_data") &&
return obj.external_data.enseignant; obj.external_data != null &&
} obj.external_data.hasOwnProperty("enseignant")
) {
return obj.external_data.enseignant;
} }
return obj.user_id; return obj.user_id;

View File

@ -184,8 +184,11 @@
path, path,
(data) => { (data) => {
let module = data.moduleimpl_id; let module = data.moduleimpl_id;
if (
if (module == null && "external_data" in data && "module" in data.external_data) { module == null && data.hasOwnProperty("external_data") &&
data.external_data != null &&
data.external_data.hasOwnProperty('module')
) {
module = data.external_data.module.toLowerCase(); module = data.external_data.module.toLowerCase();
} }