|
@@ -32,11 +32,36 @@ class _LeObject(_LeCrud):
|
32
|
32
|
|
33
|
33
|
## @brief Stores the fields name associated with fieldtype of the fields that are common to every LeObject
|
34
|
34
|
_leo_fieldtypes = dict()
|
|
35
|
+
|
|
36
|
+ ## @brief Instanciate a partial LeObject with a lodel_id
|
|
37
|
+ # @note use the get_instance method to fetch datas and instanciate a concret LeObject
|
|
38
|
+ def __init__(self, lodel_id):
|
|
39
|
+ #Warning ! Handles only single pk
|
|
40
|
+ uid_fname, uid_ft = list(self._uid_fieldtype.items())[0]
|
|
41
|
+ new_id, err = uid_ft.check_data_value(lodel_id)
|
|
42
|
+ if not (err is None):
|
|
43
|
+ raise err
|
|
44
|
+ setattr(self, uid_fname, lodel_id)
|
|
45
|
+
|
|
46
|
+ ## @return Corresponding populated LeObject
|
|
47
|
+ def get_instance(self):
|
|
48
|
+ uid_fname = self.uidname()
|
|
49
|
+ qfilter = '{uid_fname} = {uid}'.format(uid_fname = uid_fname, uid = getattr(self, uid_fname))
|
|
50
|
+ return leobject.get([qfilter])[0]
|
|
51
|
+
|
|
52
|
+ ## @brief Dirty & quick comparison implementation
|
|
53
|
+ def __cmp__(self, other):
|
|
54
|
+ uid_fname = self.uidname()
|
|
55
|
+ if not hasattr(other, uid_fname):
|
|
56
|
+ return False
|
|
57
|
+ return getattr(self, uid_fname) == getattr(other, uid_fname)
|
|
58
|
+
|
|
59
|
+ ## @brief Quick str cast method implementation
|
|
60
|
+ def __str__(self):
|
|
61
|
+ return "<%s lodel_id=%d>"%(self.__class__, getattr(self, self.uidname()))
|
35
|
62
|
|
36
|
|
- ## @brief Instantiate with a Model and a DataSource
|
37
|
|
- # @param **kwargs dict : datas usefull to instanciate a _LeObject
|
38
|
|
- def __init__(self, **kwargs):
|
39
|
|
- raise NotImplementedError("Abstract constructor")
|
|
63
|
+ def __repr__(self):
|
|
64
|
+ return self.__str__()
|
40
|
65
|
|
41
|
66
|
## @brief Given a ME uid return the corresponding LeClass or LeType class
|
42
|
67
|
# @return a LeType or LeClass child class
|