No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

leobject.py 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. #-*- coding: utf-8 -*-
  2. import importlib
  3. import warnings
  4. import copy
  5. from lodel import logger
  6. from lodel.settings import Settings
  7. from lodel.settings.utils import SettingsError
  8. from .query import LeInsertQuery, LeUpdateQuery, LeDeleteQuery, LeGetQuery
  9. from .exceptions import *
  10. from lodel.plugin.exceptions import *
  11. from lodel.plugin.hooks import LodelHook
  12. from lodel.plugin import Plugin, DatasourcePlugin
  13. from lodel.leapi.datahandlers.base_classes import DatasConstructor
  14. from lodel.leapi.datahandlers.base_classes import Reference
  15. ##@brief Stores the name of the field present in each LeObject that indicates
  16. #the name of LeObject subclass represented by this object
  17. CLASS_ID_FIELDNAME = "classname"
  18. ##@brief Wrapper class for LeObject getter & setter
  19. #
  20. # This class intend to provide easy & friendly access to LeObject fields values
  21. # without name collision problems
  22. # @note Wrapped methods are : LeObject.data() & LeObject.set_data()
  23. class LeObjectValues(object):
  24. ##@brief Construct a new LeObjectValues
  25. # @param set_callback method : The LeObject.set_datas() method of corresponding LeObject class
  26. # @param get_callback method : The LeObject.get_datas() method of corresponding LeObject class
  27. def __init__(self, fieldnames_callback, set_callback, get_callback):
  28. self._setter = set_callback
  29. self._getter = get_callback
  30. ##@brief Provide read access to datas values
  31. # @note Read access should be provided for all fields
  32. # @param fname str : Field name
  33. def __getattribute__(self, fname):
  34. getter = super().__getattribute__('_getter')
  35. return getter(fname)
  36. ##@brief Provide write access to datas values
  37. # @note Write acces shouldn't be provided for internal or immutable fields
  38. # @param fname str : Field name
  39. # @param fval * : the field value
  40. def __setattribute__(self, fname, fval):
  41. setter = super().__getattribute__('_setter')
  42. return setter(fname, fval)
  43. class LeObject(object):
  44. ##@brief boolean that tells if an object is abtract or not
  45. _abstract = None
  46. ##@brief A dict that stores DataHandler instances indexed by field name
  47. _fields = None
  48. ##@brief A tuple of fieldname (or a uniq fieldname) representing uid
  49. _uid = None
  50. ##@brief Read only datasource ( see @ref lodel2_datasources )
  51. _ro_datasource = None
  52. ##@brief Read & write datasource ( see @ref lodel2_datasources )
  53. _rw_datasource = None
  54. ##@brief Store the list of child classes
  55. _child_classes = None
  56. def __new__(cls, **kwargs):
  57. self = object.__new__(cls)
  58. ##@brief A dict that stores fieldvalues indexed by fieldname
  59. self.__datas = { fname:None for fname in self._fields }
  60. ##@brief Store a list of initianilized fields when instanciation not complete else store True
  61. self.__initialized = list()
  62. ##@brief Datas accessor. Instance of @ref LeObjectValues
  63. self.d = LeObjectValues(self.fieldnames, self.set_data, self.data)
  64. for fieldname, fieldval in kwargs.items():
  65. self.__datas[fieldname] = fieldval
  66. self.__initialized.append(fieldname)
  67. self.__is_initialized = False
  68. self.__set_initialized()
  69. return self
  70. ##@brief Construct an object representing an Editorial component
  71. # @note Can be considered as EmClass instance
  72. def __init__(self, **kwargs):
  73. if self._abstract:
  74. raise NotImplementedError("%s is abstract, you cannot instanciate it." % self.__class__.__name__ )
  75. # Checks that uid is given
  76. for uid_name in self._uid:
  77. if uid_name not in kwargs:
  78. raise LeApiError("Cannot instanciate a LeObject without it's identifier")
  79. self.__datas[uid_name] = kwargs[uid_name]
  80. del(kwargs[uid_name])
  81. self.__initialized.append(uid_name)
  82. # Processing given fields
  83. allowed_fieldnames = self.fieldnames(include_ro = False)
  84. err_list = dict()
  85. for fieldname, fieldval in kwargs.items():
  86. if fieldname not in allowed_fieldnames:
  87. if fieldname in self._fields:
  88. err_list[fieldname] = LeApiError(
  89. "Value given but the field is internal")
  90. else:
  91. err_list[fieldname] = LeApiError(
  92. "Unknown fieldname : '%s'" % fieldname)
  93. else:
  94. self.__datas[fieldname] = fieldval
  95. self.__initialized.append(fieldname)
  96. if len(err_list) > 0:
  97. raise LeApiErrors(msg = "Unable to __init__ %s" % self.__class__,
  98. exceptions = err_list)
  99. self.__set_initialized()
  100. #-----------------------------------#
  101. # Fields datas handling methods #
  102. #-----------------------------------#
  103. ##@brief Property method True if LeObject is initialized else False
  104. @property
  105. def initialized(self):
  106. return self.__is_initialized
  107. ##@return The uid field name
  108. @classmethod
  109. def uid_fieldname(cls):
  110. return cls._uid
  111. ##@brief Return a list of fieldnames
  112. # @param include_ro bool : if True include read only field names
  113. # @return a list of str
  114. @classmethod
  115. def fieldnames(cls, include_ro = False):
  116. if not include_ro:
  117. return [ fname for fname in cls._fields if not cls._fields[fname].is_internal() ]
  118. else:
  119. return list(cls._fields.keys())
  120. @classmethod
  121. def name2objname(cls, name):
  122. return name.title()
  123. ##@brief Return the datahandler asssociated with a LeObject field
  124. # @param fieldname str : The fieldname
  125. # @return A data handler instance
  126. @classmethod
  127. def data_handler(cls, fieldname):
  128. if not fieldname in cls._fields:
  129. raise NameError("No field named '%s' in %s" % (fieldname, cls.__name__))
  130. return cls._fields[fieldname]
  131. ##@brief Getter for references datahandlers
  132. #@param with_backref bool : if true return only references with back_references
  133. #@return <code>{'fieldname': datahandler, ...}</code>
  134. @classmethod
  135. def reference_handlers(cls, with_backref = True):
  136. return { fname: fdh
  137. for fname, fdh in cls.fields(True).items()
  138. if issubclass(fdh.__class__, Reference) and \
  139. (not with_backref or fdh.back_reference is not None)}
  140. ##@brief Return a LeObject child class from a name
  141. # @warning This method has to be called from dynamically generated LeObjects
  142. # @param leobject_name str : LeObject name
  143. # @return A LeObject child class
  144. # @throw NameError if invalid name given
  145. @classmethod
  146. def name2class(cls, leobject_name):
  147. if cls.__module__ == 'lodel.leapi.leobject':
  148. raise NotImplementedError("Abstract method")
  149. mod = importlib.import_module(cls.__module__)
  150. try:
  151. return getattr(mod, leobject_name)
  152. except (AttributeError, TypeError) :
  153. raise LeApiError("No LeObject named '%s'" % leobject_name)
  154. @classmethod
  155. def is_abstract(cls):
  156. return cls._abstract
  157. ##@brief Field data handler getter
  158. #@param fieldname str : The field name
  159. #@return A datahandler instance
  160. #@throw NameError if the field doesn't exist
  161. @classmethod
  162. def field(cls, fieldname):
  163. try:
  164. return cls._fields[fieldname]
  165. except KeyError:
  166. raise NameError("No field named '%s' in %s" % ( fieldname,
  167. cls.__name__))
  168. ##@return A dict with fieldname as key and datahandler as instance
  169. @classmethod
  170. def fields(cls, include_ro = False):
  171. if include_ro:
  172. return copy.copy(cls._fields)
  173. else:
  174. return {fname:cls._fields[fname] for fname in cls._fields if not cls._fields[fname].is_internal()}
  175. ##@brief Return the list of parents classes
  176. #
  177. #@note the first item of the list is the current class, the second is it's
  178. #parent etc...
  179. #@param cls
  180. #@warning multiple inheritance broken by this method
  181. #@return a list of LeObject child classes
  182. #@todo multiple parent capabilities implementation
  183. @classmethod
  184. def hierarch(cls):
  185. res = [cls]
  186. cur = cls
  187. while True:
  188. cur = cur.__bases__[0] # Multiple inheritance broken HERE
  189. if cur in (LeObject, object):
  190. break
  191. else:
  192. res.append(cur)
  193. return res
  194. ##@brief Return a tuple a child classes
  195. #@return a tuple of child classes
  196. @classmethod
  197. def child_classes(cls):
  198. return copy.copy(cls._child_classes)
  199. ##@brief Return the parent class that is the "source" of uid
  200. #
  201. #The method goal is to return the parent class that defines UID.
  202. #@return a LeObject child class or false if no UID defined
  203. @classmethod
  204. def uid_source(cls):
  205. if cls._uid is None or len(cls._uid) == 0:
  206. return False
  207. hierarch = cls.hierarch()
  208. prev = hierarch[0]
  209. uid_handlers = set( cls._fields[name] for name in cls._uid )
  210. for pcls in cls.hierarch()[1:]:
  211. puid_handlers = set(cls._fields[name] for name in pcls._uid)
  212. if set(pcls._uid) != set(prev._uid) \
  213. or puid_handlers != uid_handlers:
  214. break
  215. prev = pcls
  216. return prev
  217. ##@brief Initialise both datasources (ro and rw)
  218. #
  219. #This method is used once at dyncode load to replace the datasource string
  220. #by a datasource instance to avoid doing this operation for each query
  221. #@see LeObject::_init_datasource()
  222. @classmethod
  223. def _init_datasources(cls):
  224. if isinstance(cls._datasource_name, str):
  225. rw_ds = ro_ds = cls._datasource_name
  226. else:
  227. ro_ds, rw_ds = cls._datasource_name
  228. #Read only datasource initialisation
  229. cls._ro_datasource = DatasourcePlugin.init_datasource(ro_ds, True)
  230. if cls._ro_datasource is None:
  231. log_msg = "No read only datasource set for LeObject %s"
  232. log_msg %= cls.__name__
  233. logger.debug(log_msg)
  234. else:
  235. log_msg = "Read only datasource '%s' initialized for LeObject %s"
  236. log_msg %= (ro_ds, cls.__name__)
  237. logger.debug(log_msg)
  238. #Read write datasource initialisation
  239. cls._rw_datasource = DatasourcePlugin.init_datasource(rw_ds, False)
  240. if cls._ro_datasource is None:
  241. log_msg = "No read/write datasource set for LeObject %s"
  242. log_msg %= cls.__name__
  243. logger.debug(log_msg)
  244. else:
  245. log_msg = "Read/write datasource '%s' initialized for LeObject %s"
  246. log_msg %= (ro_ds, cls.__name__)
  247. logger.debug(log_msg)
  248. ##@brief Return the uid of the current LeObject instance
  249. #@return the uid value
  250. #@warning Broke multiple uid capabilities
  251. def uid(self):
  252. return self.data(self._uid[0])
  253. ##@brief Read only access to all datas
  254. # @note for fancy data accessor use @ref LeObject.g attribute @ref LeObjectValues instance
  255. # @param name str : field name
  256. # @return the Value
  257. # @throw RuntimeError if the field is not initialized yet
  258. # @throw NameError if name is not an existing field name
  259. def data(self, field_name):
  260. if field_name not in self._fields.keys():
  261. raise NameError("No such field in %s : %s" % (self.__class__.__name__, field_name))
  262. if not self.initialized and field_name not in self.__initialized:
  263. raise RuntimeError("The field %s is not initialized yet (and have no value)" % field_name)
  264. return self.__datas[field_name]
  265. ##@brief Read only access to all datas
  266. #@return a dict representing datas of current instance
  267. def datas(self, internal = False):
  268. return {fname:self.data(fname) for fname in self.fieldnames(internal)}
  269. ##@brief Datas setter
  270. # @note for fancy data accessor use @ref LeObject.g attribute @ref LeObjectValues instance
  271. # @param fname str : field name
  272. # @param fval * : field value
  273. # @return the value that is really set
  274. # @throw NameError if fname is not valid
  275. # @throw AttributeError if the field is not writtable
  276. def set_data(self, fname, fval):
  277. if fname not in self.fieldnames(include_ro = False):
  278. if fname not in self._fields.keys():
  279. raise NameError("No such field in %s : %s" % (self.__class__.__name__, fname))
  280. else:
  281. raise AttributeError("The field %s is read only" % fname)
  282. self.__datas[fname] = fval
  283. if not self.initialized and fname not in self.__initialized:
  284. # Add field to initialized fields list
  285. self.__initialized.append(fname)
  286. self.__set_initialized()
  287. if self.initialized:
  288. # Running full value check
  289. ret = self.__check_modified_values()
  290. if ret is None:
  291. return self.__datas[fname]
  292. else:
  293. raise LeApiErrors("Data check error", ret)
  294. else:
  295. # Doing value check on modified field
  296. # We skip full validation here because the LeObject is not fully initialized yet
  297. val, err = self._fields[fname].check_data_value(fval)
  298. if isinstance(err, Exception):
  299. #Revert change to be in valid state
  300. del(self.__datas[fname])
  301. del(self.__initialized[-1])
  302. raise LeApiErrors("Data check error", {fname:err})
  303. else:
  304. self.__datas[fname] = val
  305. ##@brief Update the __initialized attribute according to LeObject internal state
  306. #
  307. # Check the list of initialized fields and set __initialized to True if all fields initialized
  308. def __set_initialized(self):
  309. if isinstance(self.__initialized, list):
  310. expected_fields = self.fieldnames(include_ro = False) + self._uid
  311. if set(expected_fields) == set(self.__initialized):
  312. self.__is_initialized = True
  313. ##@brief Designed to be called when datas are modified
  314. #
  315. # Make different checks on the LeObject given it's state (fully initialized or not)
  316. # @return None if checks succeded else return an exception list
  317. def __check_modified_values(self):
  318. err_list = dict()
  319. if self.__initialized is True:
  320. # Data value check
  321. for fname in self.fieldnames(include_ro = False):
  322. val, err = self._fields[fname].check_data_value(self.__datas[fname])
  323. if err is not None:
  324. err_list[fname] = err
  325. else:
  326. self.__datas[fname] = val
  327. # Data construction
  328. if len(err_list) == 0:
  329. for fname in self.fieldnames(include_ro = True):
  330. try:
  331. field = self._fields[fname]
  332. self.__datas[fname] = fields.construct_data( self,
  333. fname,
  334. self.__datas,
  335. self.__datas[fname]
  336. )
  337. except Exception as e:
  338. err_list[fname] = e
  339. # Datas consistency check
  340. if len(err_list) == 0:
  341. for fname in self.fieldnames(include_ro = True):
  342. field = self._fields[fname]
  343. ret = field.check_data_consistency(self, fname, self.__datas)
  344. if isinstance(ret, Exception):
  345. err_list[fname] = ret
  346. else:
  347. # Data value check for initialized datas
  348. for fname in self.__initialized:
  349. val, err = self._fields[fname].check_data_value(self.__datas[fname])
  350. if err is not None:
  351. err_list[fname] = err
  352. else:
  353. self.__datas[fname] = val
  354. return err_list if len(err_list) > 0 else None
  355. #--------------------#
  356. # Other methods #
  357. #--------------------#
  358. ##@brief Temporary method to set private fields attribute at dynamic code generation
  359. #
  360. # This method is used in the generated dynamic code to set the _fields attribute
  361. # at the end of the dyncode parse
  362. # @warning This method is deleted once the dynamic code loaded
  363. # @param field_list list : list of EmField instance
  364. # @param cls
  365. @classmethod
  366. def _set__fields(cls, field_list):
  367. cls._fields = field_list
  368. ## @brief Check that datas are valid for this type
  369. # @param datas dict : key == field name value are field values
  370. # @param complete bool : if True expect that datas provide values for all non internal fields
  371. # @param allow_internal bool : if True don't raise an error if a field is internal
  372. # @param cls
  373. # @return Checked datas
  374. # @throw LeApiDataCheckError if errors reported during check
  375. @classmethod
  376. def check_datas_value(cls, datas, complete = False, allow_internal = True):
  377. err_l = dict() #Error storing
  378. correct = set() #valid fields name
  379. mandatory = set() #mandatory fields name
  380. for fname, datahandler in cls._fields.items():
  381. if allow_internal or not datahandler.is_internal():
  382. correct.add(fname)
  383. if complete and not hasattr(datahandler, 'default'):
  384. mandatory.add(fname)
  385. provided = set(datas.keys())
  386. # searching for unknow fields
  387. for u_f in provided - correct:
  388. #Here we can check if the field is invalid or rejected because
  389. # it is internel
  390. err_l[u_f] = AttributeError("Unknown or unauthorized field '%s'" % u_f)
  391. # searching for missing mandatory fieldsa
  392. for missing in mandatory - provided:
  393. err_l[missing] = AttributeError("The data for field '%s' is missing" % missing)
  394. #Checks datas
  395. checked_datas = dict()
  396. for name, value in [ (name, value) for name, value in datas.items() if name in correct ]:
  397. dh = cls._fields[name]
  398. res = dh.check_data_value(value)
  399. checked_datas[name], err = res
  400. if err:
  401. err_l[name] = err
  402. if len(err_l) > 0:
  403. raise LeApiDataCheckErrors("Error while checking datas", err_l)
  404. return checked_datas
  405. ##@brief Check and prepare datas
  406. #
  407. # @warning when complete = False we are not able to make construct_datas() and _check_data_consistency()
  408. #
  409. # @param datas dict : {fieldname : fieldvalue, ...}
  410. # @param complete bool : If True you MUST give all the datas
  411. # @param allow_internal : Wether or not interal fields are expected in datas
  412. # @param cls
  413. # @return Datas ready for use
  414. # @todo: complete is very unsafe, find a way to get rid of it
  415. @classmethod
  416. def prepare_datas(cls, datas, complete=False, allow_internal=True):
  417. if not complete:
  418. warnings.warn("\nActual implementation can make broken datas \
  419. construction and consitency when datas are not complete\n")
  420. ret_datas = cls.check_datas_value(datas, complete, allow_internal)
  421. if isinstance(ret_datas, Exception):
  422. raise ret_datas
  423. if complete:
  424. ret_datas = cls._construct_datas(ret_datas)
  425. cls._check_datas_consistency(ret_datas)
  426. return ret_datas
  427. ## @brief Construct datas values
  428. #
  429. # @param cls
  430. # @param datas dict : Datas that have been returned by LeCrud.check_datas_value() methods
  431. # @return A new dict of datas
  432. # @todo IMPLEMENTATION
  433. @classmethod
  434. def _construct_datas(cls, datas):
  435. constructor = DatasConstructor(cls, datas, cls._fields)
  436. ret = {
  437. fname:constructor[fname]
  438. for fname, ftype in cls._fields.items()
  439. if not ftype.is_internal() or ftype.internal != 'autosql'
  440. }
  441. return ret
  442. ## @brief Check datas consistency
  443. # @warning assert that datas is complete
  444. # @param cls
  445. # @param datas dict : Datas that have been returned by LeCrud._construct_datas() method
  446. # @throw LeApiDataCheckError if fails
  447. @classmethod
  448. def _check_datas_consistency(cls, datas):
  449. err_l = []
  450. err_l = dict()
  451. for fname, dh in cls._fields.items():
  452. ret = dh.check_data_consistency(cls, fname, datas)
  453. if isinstance(ret, Exception):
  454. err_l[fname] = ret
  455. if len(err_l) > 0:
  456. raise LeApiDataCheckError("Datas consistency checks fails", err_l)
  457. ## @brief Check datas consistency
  458. # @warning assert that datas is complete
  459. # @param cls
  460. # @param datas dict : Datas that have been returned by LeCrud.prepare_datas() method
  461. @classmethod
  462. def make_consistency(cls, datas, type_query = 'insert'):
  463. for fname, dh in cls._fields.items():
  464. ret = dh.make_consistency(fname, datas, type_query)
  465. ## @brief Add a new instance of LeObject
  466. # @return a new uid en case of success, False otherwise
  467. @classmethod
  468. def insert(cls, datas):
  469. query = LeInsertQuery(cls)
  470. return query.execute(datas)
  471. ## @brief Update an instance of LeObject
  472. #
  473. #@param datas : list of new datas
  474. def update(self, datas = None):
  475. datas = self.datas(internal=False) if datas is None else datas
  476. uids = self._uid
  477. query_filter = list()
  478. for uid in uids:
  479. query_filter.append((uid, '=', self.data(uid)))
  480. try:
  481. query = LeUpdateQuery(self.__class__, query_filter)
  482. except Exception as err:
  483. raise err
  484. try:
  485. result = query.execute(datas)
  486. except Exception as err:
  487. raise err
  488. return result
  489. ## @brief Delete an instance of LeObject
  490. #
  491. #@return 1 if the objet has been deleted
  492. def delete(self):
  493. uids = self._uid
  494. query_filter = list()
  495. for uid in uids:
  496. query_filter.append((uid, '=', self.data(uid)))
  497. query = LeDeleteQuery(self.__class__, query_filter)
  498. result = query.execute()
  499. return result
  500. ## @brief Delete instances of LeObject
  501. #@param uids a list: lists of (fieldname, fieldvalue), with fieldname in cls._uids
  502. #@returns the
  503. @classmethod
  504. def delete_bundle(cls, query_filters):
  505. deleted = 0
  506. try:
  507. query = LeDeleteQuery(cls, query_filters)
  508. except Exception as err:
  509. raise err
  510. try:
  511. result = query.execute()
  512. except Exception as err:
  513. raise err
  514. if not result is None:
  515. deleted += result
  516. return deleted
  517. ## @brief Get instances of LeObject
  518. #
  519. #@param target_class LeObject : class of object the query is about
  520. #@param query_filters dict : (filters, relational filters), with filters is a list of tuples : (FIELD, OPERATOR, VALUE) )
  521. #@param field_list list|None : list of string representing fields see
  522. #@ref leobject_filters
  523. #@param order list : A list of field names or tuple (FIELDNAME,[ASC | DESC])
  524. #@param group list : A list of field names or tuple (FIELDNAME,[ASC | DESC])
  525. #@param limit int : The maximum number of returned results
  526. #@param offset int : offset
  527. #@param Inst
  528. #@return a list of items (lists of (fieldname, fieldvalue))
  529. @classmethod
  530. def get(cls, query_filters, field_list=None, order=None, group=None, limit=None, offset=0):
  531. if field_list is not None:
  532. for uid in [ uidname
  533. for uidname in cls.uid_fieldname()
  534. if uidname not in field_list ]:
  535. field_list.append(uid)
  536. if CLASS_ID_FIELDNAME not in field_list:
  537. field_list.append(CLASS_ID_FIELDNAME)
  538. try:
  539. query = LeGetQuery(
  540. cls, query_filters = query_filters, field_list = field_list,
  541. order = order, group = group, limit = limit, offset = offset)
  542. except ValueError as err:
  543. raise err
  544. try:
  545. result = query.execute()
  546. except Exception as err:
  547. raise err
  548. objects = list()
  549. for res in result:
  550. res_cls = cls.name2class(res[CLASS_ID_FIELDNAME])
  551. inst = res_cls.__new__(res_cls,**res)
  552. objects.append(inst)
  553. return objects
  554. ##@brief Retrieve an object given an UID
  555. #@todo broken multiple UID
  556. @classmethod
  557. def get_from_uid(cls, uid):
  558. uidname = cls.uid_fieldname()[0] #Brokes composed UID
  559. res = cls.get([(uidname,'=', uid)])
  560. if len(res) > 1:
  561. raise LodelFatalError("Get from uid returned more than one \
  562. object ! For class %s with uid value = %s" % (cls, uid))
  563. return res