|
@@ -16,7 +16,8 @@ REL_SUB = 1
|
16
|
16
|
|
17
|
17
|
class LeApiErrors(Exception):
|
18
|
18
|
## @brief Instanciate a new exceptions handling multiple exceptions
|
19
|
|
- # @param exptexptions dict : A list of data check Exception with concerned field (or stuff) as key
|
|
19
|
+ # @param msg str : Exception message
|
|
20
|
+ # @param exceptions dict : A list of data check Exception with concerned field (or stuff) as key
|
20
|
21
|
def __init__(self, msg = "Unknow error", exceptions = None):
|
21
|
22
|
self._msg = msg
|
22
|
23
|
self._exceptions = dict() if exceptions is None else exceptions
|
|
@@ -62,7 +63,7 @@ class _LeCrud(object):
|
62
|
63
|
## @brief Asbtract constructor for every child classes
|
63
|
64
|
# @param uid int : lodel_id if LeObject, id_relation if its a LeRelation
|
64
|
65
|
# @param **kwargs : datas !
|
65
|
|
- # @raise NotImplementedError if trying to instanciate a class that cannot be instanciated
|
|
66
|
+ # @throw NotImplementedError if trying to instanciate a class that cannot be instanciated
|
66
|
67
|
def __init__(self, uid, **kwargs):
|
67
|
68
|
if len(kwargs) > 0:
|
68
|
69
|
if not self.implements_leobject() and not self.implements_lerelation():
|
|
@@ -109,7 +110,9 @@ class _LeCrud(object):
|
109
|
110
|
return name.title()
|
110
|
111
|
|
111
|
112
|
## @brief Convert an EmCalss and EmType name in a rel2type class name
|
112
|
|
- # @param name str : The name
|
|
113
|
+ # @param class_name str : The name of concerned class
|
|
114
|
+ # @param type_name str : The name of the concerned type
|
|
115
|
+ # @param relation_name str : The name of the relation (the name of the rel2type field in the LeClass)
|
113
|
116
|
# @return name.title()
|
114
|
117
|
@staticmethod
|
115
|
118
|
def name2rel2type(class_name, type_name, relation_name):
|
|
@@ -118,6 +121,7 @@ class _LeCrud(object):
|
118
|
121
|
|
119
|
122
|
## @brief Given a dynamically generated class name return the corresponding python Class
|
120
|
123
|
# @param name str : a concrete class name
|
|
124
|
+ # @param cls
|
121
|
125
|
# @return False if no such component
|
122
|
126
|
@classmethod
|
123
|
127
|
def name2class(cls, name):
|
|
@@ -299,6 +303,7 @@ class _LeCrud(object):
|
299
|
303
|
# @param datas dict : key == field name value are field values
|
300
|
304
|
# @param complete bool : if True expect that datas provide values for all non internal fields
|
301
|
305
|
# @param allow_internal bool : if True don't raise an error if a field is internal
|
|
306
|
+ # @param cls
|
302
|
307
|
# @return Checked datas
|
303
|
308
|
# @throw LeApiDataCheckError if errors reported during check
|
304
|
309
|
@classmethod
|
|
@@ -344,9 +349,11 @@ class _LeCrud(object):
|
344
|
349
|
# @param query_filters list : list of string of query filters (or tuple (FIELD, OPERATOR, VALUE) ) see @ref leobject_filters
|
345
|
350
|
# @param field_list list|None : list of string representing fields see @ref leobject_filters
|
346
|
351
|
# @param order list : A list of field names or tuple (FIELDNAME, [ASC | DESC])
|
347
|
|
- # @param groups list : A list of field names or tuple (FIELDNAME, [ASC | DESC])
|
|
352
|
+ # @param group list : A list of field names or tuple (FIELDNAME, [ASC | DESC])
|
348
|
353
|
# @param limit int : The maximum number of returned results
|
349
|
354
|
# @param offset int : offset
|
|
355
|
+ # @param instanciate bool : If True return an instance, else return a dict
|
|
356
|
+ # @param cls
|
350
|
357
|
# @return A list of lodel editorial components instance
|
351
|
358
|
# @todo think about LeObject and LeClass instanciation (partial instanciation, etc)
|
352
|
359
|
@classmethod
|
|
@@ -397,6 +404,8 @@ class _LeCrud(object):
|
397
|
404
|
|
398
|
405
|
## @brief Insert a new component
|
399
|
406
|
# @param datas dict : The value of object we want to insert
|
|
407
|
+ # @param classname str : The class name
|
|
408
|
+ # @param cls
|
400
|
409
|
# @return A new id if success else False
|
401
|
410
|
@classmethod
|
402
|
411
|
def insert(cls, datas, classname=None):
|
|
@@ -415,6 +424,7 @@ class _LeCrud(object):
|
415
|
424
|
# @param datas dict : {fieldname : fieldvalue, ...}
|
416
|
425
|
# @param complete bool : If True you MUST give all the datas
|
417
|
426
|
# @param allow_internal : Wether or not interal fields are expected in datas
|
|
427
|
+ # @param cls
|
418
|
428
|
# @return Datas ready for use
|
419
|
429
|
# @todo: complete is very unsafe, find a way to get rid of it
|
420
|
430
|
@classmethod
|
|
@@ -444,6 +454,7 @@ class _LeCrud(object):
|
444
|
454
|
|
445
|
455
|
## @brief Construct datas values
|
446
|
456
|
#
|
|
457
|
+ # @param cls
|
447
|
458
|
# @param datas dict : Datas that have been returned by LeCrud.check_datas_value() methods
|
448
|
459
|
# @return A new dict of datas
|
449
|
460
|
@classmethod
|
|
@@ -459,7 +470,7 @@ class _LeCrud(object):
|
459
|
470
|
## @brief Check datas consistency
|
460
|
471
|
#
|
461
|
472
|
# @warning assert that datas is complete
|
462
|
|
- #
|
|
473
|
+ # @param cls
|
463
|
474
|
# @param datas dict : Datas that have been returned by LeCrud._construct_datas() method
|
464
|
475
|
# @throw LeApiDataCheckError if fails
|
465
|
476
|
@classmethod
|
|
@@ -476,6 +487,7 @@ class _LeCrud(object):
|
476
|
487
|
|
477
|
488
|
|
478
|
489
|
## @brief Prepare a field_list
|
|
490
|
+ # @param cls
|
479
|
491
|
# @param field_list list : List of string representing fields
|
480
|
492
|
# @return A well formated field list
|
481
|
493
|
# @throw LeApiDataCheckError if invalid field given
|
|
@@ -499,6 +511,7 @@ class _LeCrud(object):
|
499
|
511
|
return ret_field_list
|
500
|
512
|
|
501
|
513
|
## @brief Check that a relational field is valid
|
|
514
|
+ # @param cls
|
502
|
515
|
# @param field str : a relational field
|
503
|
516
|
# @return a nature
|
504
|
517
|
@classmethod
|
|
@@ -506,6 +519,8 @@ class _LeCrud(object):
|
506
|
519
|
raise NotImplementedError("Abstract method")
|
507
|
520
|
|
508
|
521
|
## @brief Check that the field list only contains fields that are in the current class
|
|
522
|
+ # @param cls
|
|
523
|
+ # @param field : a field
|
509
|
524
|
# @return None if no problem, else returns a list of exceptions that occurs during the check
|
510
|
525
|
@classmethod
|
511
|
526
|
def _check_field(cls, field):
|
|
@@ -515,7 +530,8 @@ class _LeCrud(object):
|
515
|
530
|
|
516
|
531
|
## @brief Prepare the order parameter for the get method
|
517
|
532
|
# @note if an item in order_list is just a str it is considered as ASC by default
|
518
|
|
- # @param order_list list : A list of field name or tuple (FIELDNAME, [ASC|DESC])
|
|
533
|
+ # @param cls
|
|
534
|
+ # @param order_field_list list : A list of field name or tuple (FIELDNAME, [ASC|DESC])
|
519
|
535
|
# @return a list of tuple (FIELDNAME, [ASC|DESC] )
|
520
|
536
|
@classmethod
|
521
|
537
|
def _prepare_order_fields(cls, order_field_list):
|
|
@@ -544,6 +560,7 @@ class _LeCrud(object):
|
544
|
560
|
#
|
545
|
561
|
# Both categories of filters are represented in the same way, a tuple with 3 elements (NAME|NAT , OP, VALUE )
|
546
|
562
|
#
|
|
563
|
+ # @param cls
|
547
|
564
|
# @param filters_l list : This list can contain str "FIELDNAME OP VALUE" and tuples (FIELDNAME, OP, VALUE)
|
548
|
565
|
# @return a tuple(FILTERS, RELATIONNAL_FILTERS
|
549
|
566
|
#
|