mirror of
https://github.com/yweber/lodel2.git
synced 2026-08-07 12:58:37 +02:00
Add insert method
This commit is contained in:
parent
8478fef37d
commit
a53f647810
2 changed files with 23 additions and 8 deletions
|
|
@ -44,6 +44,19 @@ class _LeObject(object):
|
|||
raise KeyError("No LeType or LeClass child classes with uid '%d'"%uid)
|
||||
return cls._me_uid[uid]
|
||||
|
||||
## @brief Creates new entries in the datasource
|
||||
# @param datas list : A list a dict with fieldname as key
|
||||
# @param cls
|
||||
# @return a list of inserted lodel_id
|
||||
# @see leobject.datasources.dummy.DummyDatasource.insert(), leobject.letype.LeType.insert()
|
||||
@classmethod
|
||||
def insert(cls, letype, datas):
|
||||
if cls == _LeObject:
|
||||
raise NotImplementedError("Abstract method")
|
||||
letype,leclass = cls._prepare_targets(letype)
|
||||
if letype is None:
|
||||
raise ValueError("letype argument cannot be None")
|
||||
return cls._datasource.insert(letype, leclass, datas)
|
||||
|
||||
## @brief update an existing LeObject
|
||||
# @param lodel_id int | (int): lodel_id of the object(s) where to apply changes
|
||||
|
|
|
|||
|
|
@ -71,18 +71,19 @@ class LeType(object):
|
|||
# @note equivalent to LeType::delete(this.lodel_id)
|
||||
@classinstancemethod
|
||||
def delete(self):
|
||||
pass
|
||||
return self.__class__.delete(('lodel_id','=',self.lodel_id))
|
||||
|
||||
## @brief Delete a LeType from the datasource
|
||||
# @param lodel_id_l list : List of lodel_id to be deleted
|
||||
# @param filters list : List of filters
|
||||
# @param cls
|
||||
# @return True if deleted False if not existing
|
||||
# @throw InvalidArgumentError if invalid parameters
|
||||
# @throw Leo exception if the lodel_id identify an object from another type
|
||||
@delete.classmethod
|
||||
def delete(cls, lodel_id_l):
|
||||
def delete(cls, filters):
|
||||
pass
|
||||
|
||||
|
||||
@classinstancemethod
|
||||
## @brief Update a LeType in db
|
||||
def update(self):
|
||||
|
|
@ -96,14 +97,15 @@ class LeType(object):
|
|||
pass
|
||||
|
||||
## @brief Insert a new LeType in the datasource
|
||||
# @param **datas : A dict containing the datas
|
||||
# @param **datas list : A list of dict containing the datas
|
||||
# @return The lodel id of the new LeType or False
|
||||
# @thorw A leo exception if invalid stuff
|
||||
# @throw InvalidArgumentError if invalid argument
|
||||
@classmethod
|
||||
def insert(cls, **datas):
|
||||
cls.check_datas_or_raise(datas, complete=True)
|
||||
super(LeType, cls).insert(typename=cls.__name__, **datas)
|
||||
def insert(cls, datas):
|
||||
for data in datas:
|
||||
cls.check_datas_or_raise(data, complete=True)
|
||||
super(LeType, cls).insert(letype=cls, datas=datas)
|
||||
pass
|
||||
|
||||
## @brief Check that datas are valid for this type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue