|
@@ -399,41 +399,17 @@ class MultipleRef(Reference):
|
399
|
399
|
new_val.append(v)
|
400
|
400
|
except (FieldValidationError) as f:
|
401
|
401
|
error_list.append(repr(v))
|
402
|
|
- logger.warning("Provisoire pour faire les tests, à fixer")
|
403
|
|
- if (len(error_list) > 0):
|
|
402
|
+ if len(error_list) > 0:
|
404
|
403
|
raise FieldValidationError("MultipleRef have for invalid values [%s] :" % (",".join(error_list)))
|
405
|
404
|
return new_val
|
406
|
|
-
|
|
405
|
+
|
|
406
|
+ ##@brief Construct a multiple ref data
|
407
|
407
|
def construct_data(self, emcomponent, fname, datas, cur_value):
|
408
|
408
|
cur_value = super().construct_data(emcomponent, fname, datas, cur_value)
|
409
|
|
- if cur_value == 'None' or cur_value is None or cur_value == '':
|
410
|
|
- return None
|
411
|
|
- emcomponent_fields = emcomponent.fields()
|
412
|
|
- data_handler = None
|
413
|
|
- if fname in emcomponent_fields:
|
414
|
|
- data_handler = emcomponent_fields[fname]
|
415
|
|
- u_fname = emcomponent.uid_fieldname()
|
416
|
|
- uidtype = emcomponent.field(u_fname[0]) if isinstance(u_fname, list) else emcomponent.field(u_fname)
|
417
|
|
-
|
418
|
|
- if isinstance(cur_value, str):
|
419
|
|
- value = cur_value.split(',')
|
420
|
|
- l_value = [uidtype.cast_type(uid) for uid in value]
|
421
|
|
- elif isinstance(cur_value, list):
|
422
|
|
- l_value = list()
|
423
|
|
- for value in cur_value:
|
424
|
|
- if isinstance(value,str):
|
425
|
|
- l_value.append(uidtype.cast_type(value))
|
426
|
|
- elif isinstance(value,uidtype.cast_type):
|
427
|
|
- l_value.append(value)
|
428
|
|
- else:
|
429
|
|
- raise ValueError("The items must be of the same type, string or %s" % (emcomponent.__name__))
|
430
|
|
- else:
|
431
|
|
- l_value = None
|
432
|
|
-
|
433
|
|
- if l_value is not None:
|
|
409
|
+ if cur_value is not None:
|
434
|
410
|
if self.back_reference is not None:
|
435
|
411
|
br_class = self.back_reference[0]
|
436
|
|
- for br_id in l_value:
|
|
412
|
+ for br_id in cur_value:
|
437
|
413
|
query_filters = list()
|
438
|
414
|
query_filters.append((br_class.uid_fieldname()[0], '=', br_id))
|
439
|
415
|
br_obj = br_class.get(query_filters)
|
|
@@ -443,7 +419,7 @@ class MultipleRef(Reference):
|
443
|
419
|
br_list = list()
|
444
|
420
|
if br_id not in br_list:
|
445
|
421
|
br_list.append(br_id)
|
446
|
|
- return l_value
|
|
422
|
+ return cur_value
|
447
|
423
|
|
448
|
424
|
## @brief Checks the backreference, updates it if it is not complete
|
449
|
425
|
# @param emcomponent EmComponent : An EmComponent child class instance
|