1
0
forked from ScoDoc/ScoDoc

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: ModuleImpl = None
if moduleimpl_id not in [False, None]:
if moduleimpl_id not in [False, None, "", "-1"]:
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:
errors.append("param 'moduleimpl_id': invalide")
else:
@ -810,7 +813,7 @@ def _edit_singular(assiduite_unique, data):
moduleimpl: ModuleImpl = None
if moduleimpl_id is not False:
if moduleimpl_id is not None:
if moduleimpl_id not in [None, "", "-1"]:
if moduleimpl_id == "autre":
assiduite_unique.moduleimpl_id = None
external_data = (
@ -823,7 +826,13 @@ def _edit_singular(assiduite_unique, data):
assiduite_unique.external_data = external_data
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:
errors.append("param 'moduleimpl_id': invalide")
else:
@ -834,7 +843,7 @@ def _edit_singular(assiduite_unique, data):
else:
assiduite_unique.moduleimpl_id = moduleimpl_id
else:
assiduite_unique.moduleimpl_id = moduleimpl_id
assiduite_unique.moduleimpl_id = None
# Cas 3 : desc
desc = data.get("desc", False)

View File

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

View File

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