|
@@ -55,8 +55,41 @@ class _LeCrud(object):
|
55
|
55
|
## @brief Stores Query filters operators
|
56
|
56
|
_query_operators = ['=', '<=', '>=', '!=', '<', '>', ' in ', ' not in ', ' like ', ' not like ']
|
57
|
57
|
|
58
|
|
- def __init__(self):
|
59
|
|
- raise NotImplementedError("Abstract class")
|
|
58
|
+
|
|
59
|
+ ## @brief Asbtract constructor for every child classes
|
|
60
|
+ # @param uid int : lodel_id if LeObject, id_relation if its a LeRelation
|
|
61
|
+ # @param **kwargs : datas !
|
|
62
|
+ # @raise NotImplementedError if trying to instanciate a class that cannot be instanciated
|
|
63
|
+ def __init__(self, uid, **kwargs):
|
|
64
|
+ if not self.implements_leobject() and not self.implements_lerelation():
|
|
65
|
+ raise NotImplementedError("Abstract class !")
|
|
66
|
+ # Try to get the name of the uid field (lodel_id for objects, id_relation for relations)
|
|
67
|
+ try:
|
|
68
|
+ uid_name = self.uidname()
|
|
69
|
+ except NotImplementedError: #Should never append
|
|
70
|
+ raise NotImplementedError("Abstract class !")
|
|
71
|
+
|
|
72
|
+ # Checking uid value
|
|
73
|
+ uid, err = self._uid_fieldtype[uid_name].check_data_value(uid)
|
|
74
|
+ if isinstance(err, Exception):
|
|
75
|
+ raise err
|
|
76
|
+ setattr(self, uid_name, uid)
|
|
77
|
+
|
|
78
|
+ # Populating the object with given datas
|
|
79
|
+ errors = dict()
|
|
80
|
+ for name, value in kwargs.items():
|
|
81
|
+ if name not in self.fieldlist():
|
|
82
|
+ errors[name] = AttributeError("No such field '%s' for %s"%(name, self.__class__.__name__))
|
|
83
|
+ else:
|
|
84
|
+ cvalue, err = self.fieldtypes()[name].check_data_value(value)
|
|
85
|
+ if isinstance(err, Exception):
|
|
86
|
+ errors[name] = err
|
|
87
|
+ else:
|
|
88
|
+ setattr(self, name, cvalue)
|
|
89
|
+ if len(errors) > 0:
|
|
90
|
+ raise LeApiDataCheckError("Invalid arguments given to constructor", errors)
|
|
91
|
+
|
|
92
|
+
|
60
|
93
|
|
61
|
94
|
## @brief Given a dynamically generated class name return the corresponding python Class
|
62
|
95
|
# @param name str : a concrete class name
|