Quellcode durchsuchen

Add insert method

Yann Weber vor 9 Jahren
Ursprung
Commit
a53f647810
2 geänderte Dateien mit 23 neuen und 8 gelöschten Zeilen
  1. 14
    1
      leobject/leobject.py
  2. 9
    7
      leobject/letype.py

+ 14
- 1
leobject/leobject.py Datei anzeigen

@@ -43,7 +43,20 @@ class _LeObject(object):
43 43
         if uid not in cls._me_uid:
44 44
             raise KeyError("No LeType or LeClass child classes with uid '%d'"%uid)
45 45
         return cls._me_uid[uid]
46
-        
46
+    
47
+    ## @brief Creates new entries in the datasource
48
+    # @param datas list : A list a dict with fieldname as key
49
+    # @param cls
50
+    # @return a list of inserted lodel_id
51
+    # @see leobject.datasources.dummy.DummyDatasource.insert(), leobject.letype.LeType.insert()
52
+    @classmethod
53
+    def insert(cls, letype, datas):
54
+        if cls == _LeObject:
55
+            raise NotImplementedError("Abstract method")
56
+        letype,leclass = cls._prepare_targets(letype)
57
+        if letype is None:
58
+            raise ValueError("letype argument cannot be None")
59
+        return cls._datasource.insert(letype, leclass, datas)
47 60
 
48 61
     ## @brief update an existing LeObject
49 62
     # @param lodel_id int | (int): lodel_id of the object(s) where to apply changes

+ 9
- 7
leobject/letype.py Datei anzeigen

@@ -71,17 +71,18 @@ class LeType(object):
71 71
     # @note equivalent to LeType::delete(this.lodel_id)
72 72
     @classinstancemethod
73 73
     def delete(self):
74
-        pass
74
+        return self.__class__.delete(('lodel_id','=',self.lodel_id))
75 75
     
76 76
     ## @brief Delete a LeType from the datasource
77
-    # @param lodel_id_l list : List of lodel_id to be deleted
77
+    # @param filters list : List of filters
78 78
     # @param cls
79 79
     # @return True if deleted False if not existing
80 80
     # @throw InvalidArgumentError if invalid parameters
81 81
     # @throw Leo exception if the lodel_id identify an object from another type
82 82
     @delete.classmethod
83
-    def delete(cls, lodel_id_l):
83
+    def delete(cls, filters):
84 84
         pass
85
+        
85 86
 
86 87
     @classinstancemethod
87 88
     ## @brief Update a LeType in db
@@ -96,14 +97,15 @@ class LeType(object):
96 97
         pass
97 98
 
98 99
     ## @brief Insert a new LeType in the datasource
99
-    # @param **datas : A dict containing the datas
100
+    # @param **datas list : A list of dict containing the datas
100 101
     # @return The lodel id of the new LeType or False
101 102
     # @thorw A leo exception if invalid stuff
102 103
     # @throw InvalidArgumentError if invalid argument
103 104
     @classmethod
104
-    def insert(cls, **datas):
105
-        cls.check_datas_or_raise(datas, complete=True)
106
-        super(LeType, cls).insert(typename=cls.__name__, **datas)
105
+    def insert(cls, datas):
106
+        for data in datas:
107
+            cls.check_datas_or_raise(data, complete=True)
108
+        super(LeType, cls).insert(letype=cls, datas=datas)
107 109
         pass
108 110
     
109 111
     ## @brief Check that datas are valid for this type

Laden…
Abbrechen
Speichern